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.

C++ Programming: From Problem Analysis to Program Design
8th Edition
ISBN:9781337102087
Author:D. S. Malik
Publisher:D. S. Malik
Chapter12: Points, Classes, Virtual Functions And Abstract Classes
Section: Chapter Questions
Problem 33SA
icon
Related questions
Question

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.

Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 4 steps with 5 images

Blurred answer
Knowledge Booster
Concept of pointer parameter
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
C++ Programming: From Problem Analysis to Program…
C++ Programming: From Problem Analysis to Program…
Computer Science
ISBN:
9781337102087
Author:
D. S. Malik
Publisher:
Cengage Learning