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...
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...
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...
Modify Account Class(Java programming) used in the exercises such that ‘add’ and ‘deduct’ method could only...
Modify Account Class(Java programming) used in the exercises such that ‘add’ and ‘deduct’ method could only run if the account status is active. You can do this adding a Boolean data member ‘active’ which describes account status (active or inactive). A private method isActive should also be added to check ‘active’ data member. This data member is set to be true in the constructor, i.e. the account is active the first time class Account is created. Add another private method...
Recursion java: 1. Write a recursive algorithm to add all the elements of an array of...
Recursion java: 1. Write a recursive algorithm to add all the elements of an array of n elements 2. Write a recursive algorithm to get the minimum element of an array of n elements 3. Write a recursive algorithm to add the corresponding elements of two arrays (A and B) of n elements. Store the results in a third array C .4. Write a recursive algorithm to get the maximum element of a binary tree 5. Write a recursive algorithm...
You inherited the following SAS program. Add all the necessary statements to: a) Create two new...
You inherited the following SAS program. Add all the necessary statements to: a) Create two new variables. Call one OVERALL, computed as the average of the IQ score, the MATH score, and the SCIENCE score divided by 500. Call the other GROUP, defined as 1 for IQ scores between 0 and 100 (inclusive), 2 for IQ cores between 101 and 140 (inclusive), and 3 for IQ greater than 140. b) Provide a listing of this data set in IQ order....
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT