Question

Deliverable

A zipped NetBeans project with 2 classes

  • app
  • ZipCode
  • Address

Classes

App ZipCode Address Creates an Address object ad1 using the no-parameter constructor. - Creates an Address object ad2 using t

Suggestion:

  • Use Netbeans to copy your last lab (Lab 03) to a new project called Lab04.
  • Close Lab03.
  • Work on the new Lab04 project then.

The Address Class

  1. Attributes
    • int number
    • String name
    • String type
    • ZipCode zip
    • String state
  1. Constructors
    • one constructor with no input parameters
      • since it doesn't receive any input values, you need to use the default values below:
        • number - 0
        • name - "N/A"
        • type - "Unknown"
        • zip - use the default constructor of ZipCode
        • state - " " (two spaces)
    • one constructor with all (five) parameters
      • one input parameter for each attribute
  2. Methods
    • public String toString()
      • returns this object as a String, i.e., make each attribute a String, concatenate all strings and return as one String.
      • toString() is a special method, you will learn more about it in the next lessons
        • it needs to be public
        • it needs to have @override notation (on the line above the method itself). Netbeans will suggest you do it.

The ZipCode Class (same as before)

  1. Attributes
    • String fiveDigit
    • String plus4
  2. Constructors
    • one constructor with no input parameters
      • since it doesn't receive any input values, you need to use the default values below:
        • fiveDigit - "00000"
        • plus4 - "0000"
    • one constructor with one parameter
      • one input parameter for fiveDigit
      • use the default value from the no-parameter constructor to initialize plus4
    • one constructor with all (two) parameters
      • one input parameter for each attribute
  3. Methods (same as last lab)
    • public String toString()
      • returns this object as a String, i.e., make each attribute a String, concatenate all strings and return as one String.
      • toString() is a special method, you will learn more about it in the next lessons
        • it needs to be public
        • it needs to have @override notation (on the line above the method itself). Netbeans will suggest you do it.
    • display()
      • this method gets the "toString()" value (whatever is returned by toString() ) and uses "System.out.println" to display it.
      • you need to decide what is the type of this method
    • displayPrefix(int p)
      • this method receives an input parameter, an int number p
      • based on p's value
        • if p's value is 1
          • uses "System.out.println" to display the zipcode's prefix, i.e., its 3 first digits.
          • if the fiveDigit is "10022", displays "100"
        • if p's value is2
          • uses "System.out.println" to display the zipcode's area, i.e., its fourth and fifth digits.
          • if the fiveDigit is "10022", displays "22"
        • for any other value of p, it should not display anything

The App class

  1. create an Address object called ad1 using the no-parameter constructor
  2. create an Address object called ad2 using the all-parameter constructor with the value
    • number 100
    • name Rodeo
    • type Drive
    • zip 90210
    • state CA
  3. create an Address object called ad3 using the all-parameter constructor with the values
    • number 210
    • name West College
    • type Avenue
    • zip 16801-2141
    • state PA
  4. display all the data from each object using System.out.println and the method toString()

Output

The output should be similar to

Address{number=0, name=N/A, type=Unknown, zip=00000, state=  }
Address{number=100, name=Rodeo, type=Drive, zip=90210, state=CA}
Address{number=210, name=West College, type=Avenue, zip=16801-2141, state=PA}
0 0
Add a comment Improve this question Transcribed image text
Answer #1

As per your given question the code has been written and pasted here for your reference.

Proper inline comments have been written for your understanding.

I have also attached the screenshots of code and the output i got here.

Kindly go through the screenshots in case you get any difficulty in understanding the answer.

------------------------ code -----------------------

// class ZipCode

class ZipCode{

    String fiveDigit;

    String plus4;

    public ZipCode() {          // constructor with no parameter

        this.fiveDigit = "00000";

        this.plus4 = "0000";

    }

    public ZipCode(String fiveDigit) {  // constructor with one parameter

        this.fiveDigit = fiveDigit;

    }

    public ZipCode(String fiveDigit, String plus4) { // constructor with two parameter

        this.fiveDigit = fiveDigit;

        this.plus4 = plus4;

    }

    public void display(){   // display method

        System.out.println(this.fiveDigit+this.plus4);

    }

    

    public void displayPrefix(int p){     // display prefixmethod

        if(p == 1){

            // Returns a string that is a substring of this string. The substring begins at

            // the specified beginIndex and extends to the character at index endIndex - 1.

            // Thus the length of the substring is endIndex-beginIndex

            System.out.println(fiveDigit.substring(0,3));

        }else if(p == 2){

            // if we pass only one index the it is considered as beginIndex

            // and it creates substring upto last character

            System.out.println(fiveDigit.substring(3));

        }

    }

    @Override

    public String toString() {    // toString method to print the values

        // checking if plus4 value exist and it is not default value , then return both

        if(this.plus4 != null && this.plus4.equals("0000") == false){    

            return fiveDigit + "-" + plus4;                           

        }

        return this.fiveDigit;  // otherwise return only fiveDigit

    }

}

// Address class definition

class Address{

    int number;

    String name;

    String type;

    ZipCode zip;

    String state;

    public Address() {         // constructor with no parameter

        this.number = 0;

        this.name = "N/A";

        this.type = "Unknown";

        // creating new ZipCode object by calling constructor with no parameter to

        // assign defalut values

        this.zip = new ZipCode();

        this.state = " ";

    }

    // constructor with all parameter

    public Address(int number, String name, String type, String zip, String state) {

        this.number = number;

        this.name = name;

        this.type = type;

        // checking if zip string contains both fiveDigit and plus4 or not

        if(zip.contains("-")){  // contains returns true or false

            // if zip string contains both the string  the extracting each of them

            String fiveDigit = zip.substring(0, 5);

            String plus4 = zip.substring(6);

            // creating new ZipCode object by calling constructor with two parameter to

            // assign the respective values

            this.zip = new ZipCode(fiveDigit,plus4);

        }else{

            // otherwise calling constructor with only one parameter

            this.zip = new ZipCode(zip);

        }

        this.state = state;

    }

    // Overriding toString method to print the object in given format

    @Override

    public String toString() {

        return "Address { number=" + number

                + ",name=" + name + ", type=" + type + ", zip=" + zip

                + ", state=" + state + "}";

    }

}

/**

* App class

*/

public class App {

    public static void main(String[] args) {   // main method

        // creating Address objects as requird

        Address ad1 = new Address();

        Address ad2 = new Address(100, "Rodeo", "Drive", "90210", "CA");

        Address ad3 = new Address(210,"West College","Avenue","16801-2141","PA");

        

        // printing all the three objects

        System.out.println(ad1);

        System.out.println(ad2);

        System.out.println(ad3);

    }

}

-------------------------------------------Screenshots ----------------------------------------

o-------------------------------------output -------------------------------------------

Add a comment
Know the answer?
Add Answer to:
Deliverable A zipped NetBeans project with 2 classes app ZipCode Address Classes Suggestion: Use Netbeans to...
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
  • In this assignment, you will implement Address and Residence classes. Create a new java project. Part...

    In this assignment, you will implement Address and Residence classes. Create a new java project. Part A Implementation details of Address class: Add and implement a class named Address according to specifications in the UML class diagram. Data fields: street, city, province and zipCode. Constructors: A no-arg constructor that creates a default Address. A constructor that creates an address with the specified street, city, state, and zipCode Getters and setters for all the class fields. toString() to print out all...

  • signature 1. Create a new NetBeans Java project. The name of the project has to be...

    signature 1. Create a new NetBeans Java project. The name of the project has to be the first part of the name you write on the test sheet. The name of the package has to be testo You can chose a name for the Main class. (2p) 2. Create a new class named Address in the test Two package. This class has the following attributes: city: String-the name of the city zip: int - the ZIP code of the city...

  • using java write a code with notepad++ Create the following classes using inheritance and polymorphism Ship...

    using java write a code with notepad++ Create the following classes using inheritance and polymorphism Ship (all attributes private) String attribute for the name of ship float attribute for the maximum speed the of ship int attribute for the year the ship was built Add the following behaviors constructor(default and parameterized) , finalizer, and appropriate accessor and mutator methods Override the toString() method to output in the following format if the attributes were name="Sailboat Sally", speed=35.0f and year built of...

  • Please help with a source code for C++ and also need screenshot of output: Step 1:...

    Please help with a source code for C++ and also need screenshot of output: Step 1: Create a Glasses class using a separate header file and implementation file. Add the following attributes. Color (string data type) Prescription (float data type) Create a default constructor that sets default attributes. Color should be set to unknown because it is not given. Prescription should be set to 0.0 because it is not given. Create a parameterized constructor that sets the attributes to the...

  • Start a new project in NetBeans that defines a class Person with the following: Instance variables...

    Start a new project in NetBeans that defines a class Person with the following: Instance variables firstName (type String), middleInitial (type char) and lastName (type String) (1) A no-parameter constructor with a call to the this constructor; and (2) a constructor with String, char, String parameters (assign the parameters directly to the instance variables in this constructor--see info regarding the elimination of set methods below) Accessor (get) methods for all three instance variables (no set methods are required which makes...

  • GUI programming

    Please use netBeans Exercise 4:A librarian needs to keep track of the books he has in his Library.1. Create a class Book that has the following attributes: ISBN, Title, Author, Subject, and Price. Choose anappropriate type for each attribute.2. Add a static member BookCount to the class Book and initialize it to zero.3. Add a default constructor for the class Book. Increment the BookCount static member variable and an initialization constructor for the class Book. Increment the BookCount in all constructors.4....

  • Use inheritance to create a new class AudioRecording based on Recording class that: it will retain...

    Use inheritance to create a new class AudioRecording based on Recording class that: it will retain all the members of the Recording class, it will have an additional field bitrate (non-integer numerical; it cannot be modified once set), its constructors (non-parametrized and parametrized) will set all the attributes / fields of this class (reuse code by utilizing superclass / parent class constructors): Non-parametrized constructor should set bitrate to zero, If arguments for the parametrized constructor are illegal or null, it...

  • Additional info is this will use a total of four classes Book, BookApp, TextBook, and TextBookApp....

    Additional info is this will use a total of four classes Book, BookApp, TextBook, and TextBookApp. Also uses Super in the TextBook Class section. Problem 1 (10 points) Вook The left side diagram is a UML diagram for Book class. - title: String The class has two attributes, title and price, and get/set methods for the two attributes. - price: double Вook) Book(String, double) getTitle(): String setTitle(String): void + getPrice() double setPrice(double): void toString() String + The first constructor doesn't...

  • Create a NetBeans project called "Question 1". Then create a public class inside question1 package called Author according to the following information (Make sure to check the UML diagram)

    Create a NetBeans project called "Question 1". Then create a public class inside question1 package called Author according to the following information (Make sure to check the UML diagram) Author -name:String -email:String -gender:char +Author(name:String, email:String, gender:char) +getName():String +getEmail):String +setEmail (email:String):void +getGender():char +tostring ):String . Three private instance variables: name (String), email (String), and gender (char of either 'm' or 'f'): One constructor to initialize the name, email and gender with the given values . Getters and setters: get Name (), getEmail() and getGender (). There are no setters for name and...

  • Hey I really need some help asap!!!! I have to take the node class that is...

    Hey I really need some help asap!!!! I have to take the node class that is in my ziplist file class and give it it's own file. My project has to have 4 file classes but have 3. The Node class is currently in the ziplist file. I need it to be in it's own file, but I am stuck on how to do this. I also need a uml diagram lab report explaining how I tested my code input...

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
ADVERTISEMENT