Question

In: Computer Science

Modify the attached files to do the following in java: 1) Add all necessary Getters and...

Modify the attached files to do the following in java:

1) Add all necessary Getters and Setters to the Class file.

2) Add code to compare two instances of the class to see which one comes before the other one based on the zipcode.

//Address1.java

public class Address

{

   // attributes

   private String street, aptNum, city, state;

   private int zip;

   // constructors

   public Address(String street, String aptNum, String city, String state, int zip)

   {

this.street = street;

this.aptNum = aptNum;

this.city = city;

this.state = state;

this.zip = zip;

   }

   public Address(String street, String city, String state, int zip)

   {

this(street, "", city, state, zip);

   }

   // write the getters and setters for this on your own! :)

  

   /**

Determines if given Address object comes before calling Address

object, based on the zip code

@param other Address object to compare to

@return whether the given object comes before the calling object

   */

   public boolean comesBefore(Address other)

   {

/*if(other.zip < this.zip)

{

   return true;

}

else{

   return false;

}*/

return(other.zip < this.zip);

   }//End comesBefore

   // define and return the string representation of an address

   public String toString()

   {

String str = street + " "+ aptNum + "\n"+ city + ", "+ state + " "+ zip;

return str;

// alternatively:

// return street + " " + aptNum + "\n" + city + ", " + state + " " + zip;

   }//EndOf toString

   public boolean equals(Address other)

   {

// check if the street, aptNum, city, state, and zip are the same

if(this.street.equals(other.street) && this.aptNum.equals(other.aptNum) &&

   this.city.equals(other.city) && this.state.equals(other.state) &&

   this.zip == other.zip)

   {

return true;

   }

   else{

return false;

   }

   /*return (this.street.equals(other.street) && this.aptNum.equals(other.aptNum) &&

   this.city.equals(other.city) && this.state.equals(other.state) &&

   this.zip == other.zip);*/

   }//Endof equals

}//EndOf Class Address

//AddressDriver1

public class AddressDriver

{

   public static void main(String[] args)

   {

Address a = new Address("2000 Clayton State Blvd", "Morrow", "GA", 30303);

Address b = new Address("2000 Clayton State Blvd", "227", "Morrow", "GA", 30260);

// toString method stuff

System.out.println(a);

System.out.println(b);

String words = "The address is: \n"+ a;

System.out.println(words);

// equals method stuff

Address c = new Address("2000 Clayton State Blvd", "Morrow", "GA", 30303);

if(a.equals(c))

{

   System.out.println("Those addresses are the same.");

}

else{

   System.out.println("Those addresses are NOT the same.");

}

   }

}

Solutions

Expert Solution

CODE

public class Address {

// attributes

private String street, aptNum, city, state;

private int zip;

// constructors

public Address(String street, String aptNum, String city, String state, int zip)

{

this.street = street;

this.aptNum = aptNum;

this.city = city;

this.state = state;

this.zip = zip;

}

public Address(String street, String city, String state, int zip)

{

this(street, "", city, state, zip);

}

public String getStreet() {

return street;

}

public void setStreet(String street) {

this.street = street;

}

public String getAptNum() {

return aptNum;

}

public void setAptNum(String aptNum) {

this.aptNum = aptNum;

}

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 int getZip() {

return zip;

}

public void setZip(int zip) {

this.zip = zip;

}

// write the getters and setters for this on your own! :)

/**

Determines if given Address object comes before calling Address

object, based on the zip code

@param other Address object to compare to

@return whether the given object comes before the calling object

*/

public boolean comesBefore(Address other) {

return(other.zip < this.zip);

}//End comesBefore

// define and return the string representation of an address

public String toString()

{

String str = street + " "+ aptNum + "\n"+ city + ", "+ state + " "+ zip;

return str;

// alternatively:

// return street + " " + aptNum + "\n" + city + ", " + state + " " + zip;

}//EndOf toString

public boolean equals(Address other)

{

// check if the street, aptNum, city, state, and zip are the same

if(this.street.equals(other.street) && this.aptNum.equals(other.aptNum) &&

this.city.equals(other.city) && this.state.equals(other.state) &&

this.zip == other.zip)

{

return true;

}

else{

return false;

}

/*return (this.street.equals(other.street) && this.aptNum.equals(other.aptNum) &&

   this.city.equals(other.city) && this.state.equals(other.state) &&

   this.zip == other.zip);*/

}//Endof equals

}//EndOf Class Address

//AddressDriver1


Related Solutions

Complete the java program. /* Note: Do not add any additional methods, attributes. Do not modify...
Complete the java program. /* Note: Do not add any additional methods, attributes. Do not modify the given part of the program. Run your program against the provided Homework2Driver.java for requirements. */ /* Hint: This Queue implementation will always dequeue from the first element of the array i.e, elements[0]. Therefore, remember to shift all elements toward front of the queue after each dequeue. */ public class QueueArray<T> { public static int CAPACITY = 100; private final T[] elements; private int...
Complete the attached program by adding the following: a) add the Java codes to complete the...
Complete the attached program by adding the following: a) add the Java codes to complete the constructors for Student class b) add the Java code to complete the findClassification() method c) create an object of Student and print out its info in main() method of StudentInfo class. * * @author * @CS206 HM#2 * @Description: * */ public class StudentInfo { /** * @param args the command line arguments */ public static void main(String[] args) { // TODO code application...
For java code: Create a library to do it all. The attached file has all the...
For java code: Create a library to do it all. The attached file has all the directions and methods that need to be included in your library (.jar). You will create a .jar file, and a tester app that will include your .jar file (Add External JAR). The attached file below: Create a java project called MyLibrary, a package called net.dtcc.lib, and a class called AllInOne. The class should have the following methods, each method should return the answer: Area:...
Given the following program(Java); we are asked to do the following 1. Add a loop in...
Given the following program(Java); we are asked to do the following 1. Add a loop in the main to enqueue 12 items of your choice. 2. Be sure to implement some form of error checking that lets you know if the loop tries to add too many items to the queue. Error message: "Unexpected overflow" 3. Add a loop to dequeue items and print them on their own line with their location. Location = ? item = ? package Khatrijavaarrayqueue;...
JAVA programming language Please add or modify base on the given code Adding functionality Add functionality...
JAVA programming language Please add or modify base on the given code Adding functionality Add functionality for multiplication (*) Adding JUnit tests Add one appropriately-named method to test some valid values for tryParseInt You will use an assertEquals You'll check that tryParseInt returns the expected value The values to test: "-2" "-1" "0" "1" "2" Hint: You will need to cast the return value from tryParseInt to an int e.g., (int) ValidationHelper.tryParseInt("1") Add one appropriately-named method to test some invalid...
In Java. Modify the attached GameDriver2 to read characters in from a text file rather than...
In Java. Modify the attached GameDriver2 to read characters in from a text file rather than the user. You should use appropriate exception handling when reading from the file. The text file that you will read is provided. -------------------- Modify GaveDriver2.java -------------------- -----GameDriver2.java ----- import java.io.File; import java.util.ArrayList; import java.util.Scanner; /** * Class: GameDriver * * This class provides the main method for Homework 2 which reads in a * series of Wizards, Soldier and Civilian information from the user...
complete all methods in java! /* Note:   Do not add any additional methods, attributes.         Do...
complete all methods in java! /* Note:   Do not add any additional methods, attributes.         Do not modify the given part of the program.         Run your program against the provided Homework2Driver.java for requirements. */ /* Hint:   This Queue implementation will always dequeue from the first element of         the array i.e, elements[0]. Therefore, remember to shift all elements         toward front of the queue after each dequeue. */ public class QueueArray<T> {     public static int CAPACITY = 100;...
Modify the following program. Add using Exception handing and polymorphism. try-catch block, Finally block in java...
Modify the following program. Add using Exception handing and polymorphism. try-catch block, Finally block in java * description of class Driver here. *these is the main class where it acts like parent class. Compiler will execute firstly static method. import java.util.Scanner; public class Driver {     public static void main (String[] args){         Scanner stdIn = new Scanner(System.in);         String user;         String computer;         char a = 'y';         do {             System.out.println("What kind of Computer would you like?");...
Java Modify subclass HourlyEmployee11 and class HourlyExc (created to hold the exception) to add a "try...
Java Modify subclass HourlyEmployee11 and class HourlyExc (created to hold the exception) to add a "try and catch" statement to catch an exception if "empStatus == 1" hourly wage is not between $15.00/hr. and $25.00/hr. The keywords “throw” and “throws” MUST be used correctly and both keywords can be used either in a constructor or in a method. If an exception is thrown, the program code should prompt the user for the valid input and read it in. *NOTE*- I...
repare a single compressed file in .zip format containing all the source files (.java files, NOT...
repare a single compressed file in .zip format containing all the source files (.java files, NOT .class files) and the output file generated by running your code (i.e., testsOutput.txt) and submit it through Moodle. To be more precise, your submitted .zip file should contain the following files: PhoneCard.java, SuperNA10Card, Global10Card, Global25Card, SuperPhoneCardInc.java, CardTable.java, CallZone.java, and testsOutput.txt. Note: (1) Your assignment will be given a zero mark if only the compiled files (.class files) are submitted. No exceptions. Please make sure...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT