Question

write a parent class that describes a parcel (like a package, as shown below) and a...

write a parent class that describes a parcel (like a package, as shown below) and a child class that describes an overnight parcel. Use the provided Address class.

A parcel is described by:

  • id (which might contain numbers and letters)
  • weight (described as the number of pounds; a parcel could be less than 1 pound)
  • destination address (uses the provided class)

An overnight parcel is described by id, weight, destination address and also:

  • whether or not a signature is required upon delivery

public class Address {

private String name, street, city, state, zip;

public Address(String name, String street, String city, String state, String zip) {

this.name = name;

this.street = street;

this.city = city;

this.state = state;

this.zip = zip;

}

public String getName() {

return name;

}

public void setName(String name) {

this.name = name;

}

public String getStreet() {

return street;

}

public void setStreet(String street) {

this.street = street;

}

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;

}

@Override

public String toString() {

return name + "\n" + street + "\n" + city + ", " + state + " " + zip;

}

}

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Classes in JAVA

class Address {

    private String name, street, city, state, zip;

    public Address(String name, String street, String city, String state, String zip) {

        this.name = name;

        this.street = street;

        this.city = city;

        this.state = state;

        this.zip = zip;

    }

    public String getName() {

        return name;

    }

    public void setName(String name) {

        this.name = name;

    }

    public String getStreet() {

        return street;

    }

    public void setStreet(String street) {

        this.street = street;

    }

    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;

    }

    @Override

    public String toString() {

        return name + "\n" + street + "\n" + city + ", " + state + " " + zip;

    }

}

class Parcel{

    String id;

    double weight;

    Address address;

    Parcel(String id, double weight, Address address){

        this.address=address;

        this.id=id;

        this.weight=weight;

    }

    String getID(){

        return id;

    }

    String getAddress(){

        return address.toString();

    }

    double getWeight(){

        return weight;

    }

    void setWeight(double weight){

        this.weight=weight;

    }

    void setAddress(Address address){

        this.address=address;

    }

    void setID(String id){

        this.id=id;

    }

}

class OvernightParcel extends Parcel{

    boolean signature;

    OvernightParcel(String id, double weight, Address address, boolean signature){

        super(id, weight, address);

        this.signature=signature;

    }

    boolean getSignature(){

        return this.signature;

    }

    void setSignature(boolean s){

        signature=s;

    }

}

Add a comment
Know the answer?
Add Answer to:
write a parent class that describes a parcel (like a package, as shown below) and a...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • For this problem, we are going to revisit the Online Company exercise from lesson 3. In...

    For this problem, we are going to revisit the Online Company exercise from lesson 3. In lesson 3, we created 3 classes, a superclass Company, a subclass OnlineCompany and a runner class CompanyTester. You can take your solutions from lesson 3 for the Company and OnlineCompany, but we are going to redesign the CompanyTester in this exercise. Your task is to create a loop that will allow users to enter companies that will then get stored in an ArrayList. You...

  • write comments // on this program please //Inside package bloodDonation //BloodDonor.java class package bloodDonation; import java.text.ParseException;...

    write comments // on this program please //Inside package bloodDonation //BloodDonor.java class package bloodDonation; import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.Calendar; import java.util.Date; import java.util.Scanner; public class BloodDonor {     long idNumber, cardNumber;     String name, bloodGroup, homePhone, mobilePhone, address, lastDateOfDonation;     SimpleDateFormat myFormat = new SimpleDateFormat("dd MM yyyy");     public BloodDonor(){         this.idNumber = 0;         this.cardNumber = 0;         this.name = "";         this.bloodGroup = "";         this.homePhone = "";         this.mobilePhone = "";         this.address = "";        ...

  • Debugging exercise Programmer Began programming the following program, but made some mistakes. Please debug: class Student{...

    Debugging exercise Programmer Began programming the following program, but made some mistakes. Please debug: class Student{     private int id;     private String name;     private String city;       Student(String name, String city){         this.name = name;         this.city = city;     }        Student(int id, String place){         this.id = id;         this.place =name;     }        void Student(int id, String name, String city){         this.id = id;         this.name = name;         this.city =...

  • I need help converting the following two classes into one sql table package Practice.model; impor...

    I need help converting the following two classes into one sql table package Practice.model; import java.util.ArrayList; import java.util.List; import Practice.model.Comment; public class Students {          private Integer id;    private String name;    private String specialties;    private String presentation;    List<Comment> comment;       public Students() {}       public Students(Integer id,String name, String specialties, String presentation)    {        this.id= id;        this.name = name;        this.specialties = specialties;        this.presentation = presentation;        this.comment = new ArrayList<Commment>();                  }       public Students(Integer id,String name, String specialties, String presentation, List<Comment> comment)    {        this.id= id;        this.name...

  • I have a java class that i need to rewrite in python. this is what i...

    I have a java class that i need to rewrite in python. this is what i have so far: class Publisher: __publisherName='' __publisherAddress=''    def __init__(self,publisherName,publisherAddress): self.__publisherName=publisherName self.__publisherAddress=publisherAddress    def getName(self): return self.__publisherName    def setName(self,publisherName): self.__publisherName=publisherName    def getAddress(self): return self.__publisherAddress    def setAddress(self,publisherAddress): self.__publisherAddress=publisherAddress    def toString(self): and here is the Java class that i need in python: public class Publisher { //Todo: Publisher has a name and an address. private String name; private String address; public Publisher(String...

  • Java Do 72a, 72b, 72c, 72d. Code & output required. public class Employee { private int...

    Java Do 72a, 72b, 72c, 72d. Code & output required. public class Employee { private int id; private String name; private int sal; public Employee(int id, String name, int sal) { super(); this.id = id; this.name = name; this.sal = sal; } public int getid) { return id; } public void setId(int id) { this.id = id; } public String getName() { return name; public void setName(String name) { this.name = name; } public int get Sall) { return sal;...

  • I need help with adding comments to my code and I need a uml diagram for...

    I need help with adding comments to my code and I need a uml diagram for it. PLs help.... Zipcodeproject.java package zipcodesproject; import java.util.Scanner; import java.io.BufferedReader; import java.io.FileReader; import java.io.IOException; public class Zipcodesproject { /** * @param args the command line arguments */ public static void main(String[] args) { Scanner input=new Scanner(System.in); BufferedReader reader; int code; String state,town; ziplist listOFCodes=new ziplist(); try { reader = new BufferedReader(new FileReader("C:UsersJayDesktopzipcodes.txt")); String line = reader.readLine(); while (line != null) { code=Integer.parseInt(line); line =...

  • The ", delimiter" should now be changed to use the "^ delimiter". There needs to be...

    The ", delimiter" should now be changed to use the "^ delimiter". There needs to be an 2nd address field added to the original code, as well as, a "plus 4" on the zip code (example: 47408-6606). Then the additional prompts must be added. Thank you! Last Real-World problem (in module 04 - 05), you added functionality to allow the user to enter multiple patients until the user indicated done. You are to enhance this functionality. Add the following functionality...

  • How to create a constructor that uses parameters from different classes? I have to create a...

    How to create a constructor that uses parameters from different classes? I have to create a constructor for the PrefferedCustomer class that takes parameters(name, address,phone number, customer id, mailing list status, purchase amount) but these parameters are in superclasses Person and Customer. I have to create an object like the example below....... PreferredCustomer preferredcustomer1 = new PreferredCustomer("John Adams", "Los Angeles, CA", "3235331234", 933, true, 400); System.out.println(preferredcustomer1.toString() + "\n"); public class Person { private String name; private String address; private long...

  • Assignment (to be done in Java): Person Class: public class Person extends Passenger{ private int numOffspring;...

    Assignment (to be done in Java): Person Class: public class Person extends Passenger{ private int numOffspring; public Person() {    this.numOffspring = 0; } public Person (int numOffspring) {    this.numOffspring = numOffspring; } public Person(String name, int birthYear, double weight, double height, char gender, int numCarryOn, int numOffspring) {    super(name, birthYear, weight, height, gender, numCarryOn);       if(numOffspring < 0) {        this.numOffspring = 0;    }    this.numOffspring = numOffspring; } public int getNumOffspring() {   ...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT