Assignment is to define a class named Address. The Address class will have three private instance variables: an int named street_number a String named street_name and a String named state. Write three constructors for the Address class: an empty constructor (no input parameters) that initializes the three instance variables with default values of your choice, a constructor that takes the street values as input but defaults the state to "Arizona", and a constructor that takes all three pieces of information as input Next create a driver class named Main.java. Put public static void main here and test out your class by creating three instances of Address, one using each of the constructors. You can choose the particular address values that are used. I recommend you make them up and do not use actual addresses. Run your code to make sure it works. Next add the following public methods to the Address class and test them from main as you go: Write getters and setters for all the instance variables The setter for street number should make sure the street number is greater than zero otherwise it sets the street number to one. Override the default equals method with an equals method that returns true if the input Address has the same values as this. Your method header will look like: public boolean equals(Object other) Be aware that you will need to cast other to a variable of type Address. Refer to this example: https://www.geeksforgeeks.org/overriding-equals-method-in-java/ Override the default toString method: public String toString() Write a method named isNeighbor which returns true if street name and state are equal and street number is off by one. Use the following method header: public boolean isNeighbor(Address other) This needs to be about to upload in completed Address.java and Main.java files separately or zipped together.
Instructions-Java
Assignment is to define a class named Address.
The Address class will have three private instance variables:
- an int named street_number
- a String named street_name
- and a String named state.
Write three constructors for the Address class:
- an empty constructor (no input parameters) that initializes the three instance variables with default values of your choice,
- a constructor that takes the street values as input but defaults the state to "Arizona",
- and a constructor that takes all three pieces of information as input
Next create a driver class named Main.java. Put public static void main here and test out your class by creating three instances of Address, one using each of the constructors. You can choose the particular address values that are used. I recommend you make them up and do not use actual addresses.
Run your code to make sure it works.
Next add the following public methods to the Address class and test them from main as you go:
- Write getters and setters for all the instance variables
- The setter for street number should make sure the street number is greater than zero otherwise it sets the street number to one.
- Override the default equals method with an equals method that returns true if the input Address has the same values as this. Your method header will look like: public boolean equals(Object other) Be aware that you will need to cast other to a variable of type Address. Refer to this example: https://www.geeksforgeeks.org/overriding-equals-method-in-java/
- Override the default toString method: public String toString()
- Write a method named isNeighbor which returns true if street name and state are equal and street number is off by one. Use the following method header: public boolean isNeighbor(Address other)
This needs to be about to upload in completed Address.java and Main.java files separately or zipped together.
Trending now
This is a popular solution!
Step by step
Solved in 4 steps with 5 images