Deliverable
A zipped NetBeans project with 2 classes
Classes
Suggestion:
The Address Class
The ZipCode Class (same as before)
The App class
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}
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 -------------------------------------------
Deliverable A zipped NetBeans project with 2 classes app ZipCode Address Classes Suggestion: Use Netbeans to...
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 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 (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: 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 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...
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 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. 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) 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 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...