1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
Nata [24]
3 years ago
5

An address has a house number, a street, an optional apartment number, a city, a state and a postal code. Define the constructor

such that an object can be created in one of two ways: with an apartment number or without. Supply a print method that prints the address with the street on one line and the city, state and postal code on the next line.
Computers and Technology
1 answer:
Sveta_85 [38]3 years ago
5 0

Answer:

public class Address {

   private int houseNumber;

   private String street;

   private int apartmentNumber;

   private String city;

   private String state;

   private String postalCode;

   //First Constructor with an Apartment Number

   public Address(int houseNumber, String street, int apartmentNumber, String city, String state, String postalCode) {

       this.houseNumber = houseNumber;

       this.street = street;

       this.apartmentNumber = apartmentNumber;

       this.city = city;

       this.state = state;

       this.postalCode = postalCode;

   }

   // Second Constructor Without Apartment Number

   public Address(int houseNumber, String street, String city, String state, String postalCode) {

       this.houseNumber = houseNumber;

       this.street = street;

       this.city = city;

       this.state = state;

       this.postalCode = postalCode;

   }

   // Creating Getter Methods

   public int getHouseNumber() {

       return houseNumber;

   }

   public String getStreet() {

       return street;

   }

   public int getApartmentNumber() {

       return apartmentNumber;

   }

   public String getCity() {

       return city;

   }

   public String getState() {

       return state;

   }

   public String getPostalCode() {

       return postalCode;

   }

   //A Print Method to print an Address

   public void printAddress(){

       System.out.println(getStreet()+" Street"); //First line of the address

       System.out.println(getCity()+", "+getState()+" State, "+getPostalCode());//Second line of the address

   }

}

Explanation:

In Java, A class is created called Address

The house number, street, apartment number, city, state and postal code are all created as the class member variables (fields)

Two constructors are created. The first initializes all the fields so an object of the class contains all the fields. The second does not initialize the optional apartment number. This technique is called constructor overloading

Getter methods are created for all the fields

A method printAddress() is created that prints as stipulated by the question. Do pay attention to the comments in the code

You might be interested in
I have been working on this python program for a hour now, and I am trying to figure out what I an doing wrong in the loop. I ha
Alona [7]

Answer:

The correct loop is as follows:

for year in range(starting_tuitionYear, ending_tuitionYear, increment):

   tuition = startingTuition + rate * startingTuition

   startingTuition = tuition

   print('Tuition for the year of ' + str(year)+ ' is ' + str(tuition));

Explanation:

Required

The correction to the attached program

Some variables are not needed; so, I've removed the redundant variables.

The main error in the program is in the loop;

After the tuition for each year has been calculated, the startTuition of the next year must be set to the current tuition

<em>See attachment for complete program</em>

7 0
3 years ago
HELP!!!<br> THIS HAPPENS EVERY TIME
Lelu [443]
Idek but hope u figure it out!
4 0
3 years ago
Read 2 more answers
Consider the following list. list = {24, 20, 10, 75, 70, 18, 60, 35} Suppose that list is sorted using the selection sort algori
Nadya [2.5K]

Answer:

list =  {10, 18, 24, 75, 70, 20, 60, 35}

Explanation:

Selection is a sorting algorithm that will set a cursor position and search for a minimum number from the list. When the minimum number is found, that minimum number will be swapped with the number in the cursor position. Only one number will be swapped and sorted in one iteration of outer loop. To sort the next number in the following outer loop iteration, the cursor will be moved to the next position and repeat the same search and swapping process as in the first iteration. When finishing all the iterations of outer loop, all numbers shall be sorted in ascending order.

4 0
3 years ago
How's your day :D I hope its goin well you amazing person :D
Rainbow [258]

Answer:

You are an awesome and amazing person!!

Explanation:

7 0
3 years ago
Read 2 more answers
How to write a survey on cat theory​
nalin [4]
Start with a bold statement then follow with facts solutions problems and theory’s
3 0
2 years ago
Other questions:
  • Write a function named initialMatch that takes a string parameter, text, that contains only lowercase letters and whitespace. Th
    6·1 answer
  • The left column values in a table array are called table ____
    13·1 answer
  • False when you tap or click the ‘decrease font size’ button, excel assigns the next lowest font size in the font size gallery to
    13·1 answer
  • The ________________ command tests connectivity by sending an echo request to a remote computer.
    14·1 answer
  • Reasons for the growth of decision-making systems include:
    13·1 answer
  • If Nancy receives an encrypted message from Matthew, which key does she use to read it? Nancy’s private key Nancy’s public key M
    8·1 answer
  • Assign a variable solveEquation with a function expression that has three parameters (x, y, and z) and returns the result of eva
    14·1 answer
  • On the classic gameshow The Price Is Right, contestants must guess the price of an object (guesses are distinct). The winner is
    5·1 answer
  • What is your favorite film and what makes it good?
    9·2 answers
  • What is used for risk response control?
    7·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!