Question

In: Computer Science

Inheritance – Address, PersonAddress, BusinessAddress Classes Assignment Download the Lab6.zip starter file. Use 7zip to unzip...

Inheritance – Address, PersonAddress, BusinessAddress Classes

Assignment

Download the Lab6.zip starter file. Use 7zip to unzip the file using ‘Extract Here’. Open the project folder in IntelliJ.

Examine the Main and Address classes. You are going to add two classes derived from Address: BusinessAddress and PersonAddress.

Create BusinessAddress class

  1. Select package edu.cscc and create a new Java class called BusinessAddress  
  2. Make the class extend the Address class
  3. Add two private String fields businessName and address2
  4. Generate constructor and all getters and setters
  5. Add a printLabel() method

The printLabel method should print (using System.out.println()) // Here is the 1st place I'm getting stuck ?? All I did was create the BusinessAddress class. I appreciate your assistance

First line – the businessName field

Second line – the address2 field if it is not null or empty

Third line – the StreetAddress field if it is not null or empty

Fourth line – city field followed by a comma and space, the state field followed by two spaces, and the zip field

Create PersonAddress class

  1. Select package edu.cscc and create a new Java class called PersonAddress
  2. Make the class extend the Address class
  3. Add a private String field personName
  4. Generate constructor and all getters and setters
  5. Add a printLabel() method

The printLabel method should print (using System.out.println())

First line – the personName field

Second line – the StreetAddress field

Third line – city field followed by a comma and space, the state field followed by two spaces, and the zip field

Modify Main class

Add the following three BusinessAddress objects to the list.

BusinessName

Address2

StreetAddress

City

State

Zip

Columbus State

Eibling 302B

550 East Spring St.

Columbus

OH

43215

AEP

P.O. Box 2075

null

Columbus

OH

43201

Bill’s Coffee

null

2079 N. Main St.

Columbus

OH

43227

Add the following three PersonAddress objects to the list.

PersonName

StreetAddress

City

State

Zip

Saul Goodman

1200 N. Fourth St.

Worthington

OH

43217

Mike Ehrmentraut

207 Main St.

Reynoldsburg

OH

43211

Gustavo Fring

2091 Elm St.

Pickerington

OH

43191

Example Output

Columbus State

Eibling 302B

550 East Spring St.

Columbus, OH 43215

====================

AEP

P.O. Box 2075

Columbus, OH 43201

====================

Bill's Coffee

2079 N. Main St.

Columbus, OH 43227

====================

Saul Goodman

1200 N. Fourth St.

Worthington, OH 43217

====================

Mike Ehrmentraut

207 Main St.

Reynoldsburg, OH 43211

====================

Gustavo Fring

2091 Elm St.

Pickerington, OH 43191

====================

public class Main {

    public static void main(String[] args) {
       Address[] addressList = new Address[6];

       // TODO Add 3 person addresses to list

        // TODO Add 3 business address to list

       for (Address address : addressList) {
           address.printLabel();
            System.out.println("====================");
        }
    }
}
public abstract class Address {
    private String streetAddress;
    private String city;
    private String state;
    private String zip;

    public Address(String streetAddress, String city, String state, String zip) {
        this.streetAddress = streetAddress;
        this.city = city;
        this.state = state;
        this.zip = zip;
    }

    public String getStreetAddress() {
        return streetAddress;
    }

    public void setStreetAddress(String streetAddress) {
        this.streetAddress = streetAddress;
    }

    public String getCity() {
        return city;
    }

    public void setCity(String city) {
        this.city = city;
    }

    public String getState() {
        return state;
    }

    public void setState(String state) {
        this.state = state;
    }

    public String getZip() {
        return zip;
    }

    public void setZip(String zip) {
        this.zip = zip;
    }

    public String toString() {
        return streetAddress + "\n" +
                city + ", " + state + "  " + zip + "\n";
    }

    public abstract void printLabel();
}

public class BusinessAddress extends Address {

    private String businessName;
    private String address2;

    public BusinessAddress(String streetAddress, String city, String state, String zip, String businessName, String address2) {
        super(streetAddress, city, state, zip);
        this.businessName = businessName;
        this.address2 = address2;
    }

    public String getBusinessName() {
        return businessName;
    }

    public void setBusinessName(String businessName) {
        this.businessName = businessName;
    }

    public String getAddress2() {
        return address2;
    }

    public void setAddress2(String address2) {
        this.address2 = address2;
    }

    public void printLabel() {

    }
}

Solutions

Expert Solution

public class Main {

public static void main(String[] args) {
Address[] addressList = new Address[6];
// TODO Add 3 business address to list
Address add1=new BusinessAddress("550 East Spring St.","Columbus","OH","43215","Columbus State","Eibling 302B");
Address add2=new BusinessAddress(null,"Columbus","OH","43201","AEP","P.O. Box 2075");
Address add3=new BusinessAddress("2079 N. Main St.","Columbus","OH","43227","Bill’s Coffee",null);
// TODO Add 3 person addresses to list
Address add4=new PersonAddress("1200 N. Fourth St.","Worthington","OH", "43217", "Saul Goodman");
Address add5=new PersonAddress("207 Main St.","Reynoldsburg","OH", "43211", "Mike Ehrmentraut");
Address add6=new PersonAddress("2091 Elm St.","Pickerington","OH", "43191", "Gustavo Fring");
addressList[0]=add1;
addressList[1]=add2;
addressList[2]=add3;
addressList[3]=add4;
addressList[4]=add5;
addressList[5]=add6;

for (Address address : addressList) {
address.printLabel();
System.out.println("====================");
}
}
}

public class BusinessAddress extends Address{

private String businessName;
private String address2;

public BusinessAddress(String streetAddress, String city, String state, String zip, String businessName, String address2) {
super(streetAddress, city, state, zip);
this.businessName = businessName;
this.address2 = address2;
}

public String getBusinessName() {
return businessName;
}

public void setBusinessName(String businessName) {
this.businessName = businessName;
}

public String getAddress2() {
return address2;
}

public void setAddress2(String address2) {
this.address2 = address2;
}

public void printLabel() {
   String toprint=this.getBusinessName();
   if(this.getAddress2()!=null && this.getAddress2()!=""){
       toprint+="\n"+this.getAddress2();
   }
   if(this.getStreetAddress()!=null && this.getStreetAddress()!=""){
       toprint+="\n"+this.getStreetAddress();
   }
   toprint+="\n"+this.getCity()+", "+this.getState()+" "+this.getZip();
   System.out.println(toprint);
}
}

public class PersonAddress extends Address{
  
   private String personName;
   public PersonAddress(String streetAddress, String city, String state, String zip,String name) {
       super(streetAddress, city, state, zip);
       this.personName=name;
   }
   public String getPersonName() {
       return personName;
   }
   public void setPersonName(String personName) {
       this.personName = personName;
   }
   @Override
   public void printLabel() {
       // TODO Auto-generated method stub
       String toprint=this.getPersonName();
       toprint+="\n"+this.getStreetAddress();
       toprint+="\n"+this.getCity()+", "+this.getState()+" "+this.getZip();
       System.out.println(toprint);
   }
}

public abstract class Address {
private String streetAddress;
private String city;
private String state;
private String zip;

public Address(String streetAddress, String city, String state, String zip) {
this.streetAddress = streetAddress;
this.city = city;
this.state = state;
this.zip = zip;
}

public String getStreetAddress() {
return streetAddress;
}

public void setStreetAddress(String streetAddress) {
this.streetAddress = streetAddress;
}

public String getCity() {
return city;
}

public void setCity(String city) {
this.city = city;
}

public String getState() {
return state;
}

public void setState(String state) {
this.state = state;
}

public String getZip() {
return zip;
}

public void setZip(String zip) {
this.zip = zip;
}

public String toString() {
return streetAddress + "\n" +
city + ", " + state + " " + zip + "\n";
}

public abstract void printLabel();
}

Expected output:


Related Solutions

Download the following zip file Bag and complete the program. You will need to complete files...
Download the following zip file Bag and complete the program. You will need to complete files MyBag and . MyBag uses the java API class ArrayList as the underline data structure. Using the class variables given, complete the methods of the MyBag class. In your BagHand class you should set appropriate default values for select class variables in the constructor in the add method, use the MyBag object to add a PlayingCard type to the bag and find and set...
Assignment 3 Qu #2 W19 You must download the file “Assn3_Qu#2_W19” to use the required data....
Assignment 3 Qu #2 W19 You must download the file “Assn3_Qu#2_W19” to use the required data. It gives the number of city-bus users (Ridership) on a public transportation system of a large city in 3 given working days chosen at random in units of hundreds. It gives this data separately for the 4 busy bus routes and for 5 time slots. Here, TSlot1: from start of day to 9:30 am, TSlot2: 9:30 – 12:30, TSlot3: 12:30 – 15:30, TSlot4: 15:30...
This assignment uses a combination of classes and arrays. Instructions: 1) download the 3 program files...
This assignment uses a combination of classes and arrays. Instructions: 1) download the 3 program files into a new C++ project.    NOTE: if your IDE does not allow you to create projects - or you are not sure how to do it - then you may combine the two cpp files into a single file. 2) Complete the program by adding code the the class methods. You may want to study the existing code first to get a feel...
Download this file to your hard drive and follow the instructions in the Module 9 Assignment...
Download this file to your hard drive and follow the instructions in the Module 9 Assignment (Word) document. Prepare two files for your post. The first file should be a text file containing your Python solution. The second file should contain your output file(txt). Complete the following using Python on a single text file and submit your code and your output as separate documents. For each problem create the necessary list objects and write code to perform the following examples:...
Use inheritance to implement the following classes: A: A Car that is a Vehicle and has...
Use inheritance to implement the following classes: A: A Car that is a Vehicle and has a name, a max_speed value and an instance variable called the number_of_cylinders in its engine. Add public methods to set and get the values of these variables. When a car is printed (using the toString method), its name, max_speed and number_of_cylinders are shown. B: An Airplane that is also a vehicle and has a name, a max_speed value and an instance variable called the...
Assignment Examine the Main and Address classes. You are going to add two classes derived from...
Assignment Examine the Main and Address classes. You are going to add two classes derived from Address: BusinessAddress and PersonAddress. Create BusinessAddress class Select package home and create a new Java class called BusinessAddress Make the class extend the Address class Add two private String fields businessName and address2 Generate constructor and all getters and setters Add a printLabel() method The printLabel method should print (using System.out.println()) First line – the businessName field Second line – the address2 field if...
How algorithms address object-oriented classes and objects. What is the File object? How are File objects...
How algorithms address object-oriented classes and objects. What is the File object? How are File objects used in algorithms? 175 words minumum please :)
Java assignment, abstract class, inheritance, and polymorphism. these are the following following classes: Animal (abstract) Has...
Java assignment, abstract class, inheritance, and polymorphism. these are the following following classes: Animal (abstract) Has a name property (string) Has a speech property (string) Has a constructor that takes two arguments, the name and the speech It has getSpeech() and setSpeech(speech) It has getName and setName(name) It has a method speak() that prints the name of the animal and the speech. o Example output: Tom says meow. Mouse Inherits the Animal class Has a constructor takes a name and...
This assignment tests your understanding of abstract classes, inheritance, and requirements modeling using class-based methods. The...
This assignment tests your understanding of abstract classes, inheritance, and requirements modeling using class-based methods. The assignment scenario involves an abstract vehicle class and concrete subclasses Jeep and Ford. The vehicle class has the following variables (manufacturer, language), and methods (getManufacturer( ), and getLanguage( )). The manufacturer builds a specific vehicle (a Jeep and a Ford). The manufacturer will notify the consumer class that a Jeep and a Ford are available for purchase. The consumer class purchases the Jeep. Your...
c++ programing. Objectives Further practice with classes Use of inheritance Use compositions Define a class called...
c++ programing. Objectives Further practice with classes Use of inheritance Use compositions Define a class called Person with private members name of type string, and money of integer type. The class has the public member functions set(), getMoney(), print(), and a parameterized constructor with default values. Define a class called Patient with private data members name of type string, durationOfTreatment, and TreatmentCost of type integer. The class has the public member functions set(), getCost(), getDuration(), print(), and a parameterized constructor...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT