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]
2 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]2 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
Select the best answer from the drop-down menu.
maw [93]

Answer:

1) performance assessments

2) measurable goals

3)can't be measured quantitatively

4) milestones

Explanation:

Methods of evaluating the performance and productivity of an individual or group in relation to predetermined criteria and measurable goals are <u>performance assessments.</u>

<u>measurable goals</u> are goals that have concrete criteria for measuring progress toward their attainment.

Why are statements like “great customer experience” or “more sales” not good assessment criteria? <u>can't be measured quantitatively</u>

Personal goal setting helps lagging performance by setting <u>milestones</u>

which are short-term achievable tasks.

<u>OAmalOHopeO</u>

8 0
2 years ago
Read 2 more answers
Design a program that asks the User to enter a series of 5 numbers. The program should store the numbers in a list then display
klasskru [66]

Answer:

The program in Python is as follows:

numbers = []

total = 0

for i in range(5):

   num = float(input(": "))

   numbers.append(num)

   total+=num

   

print("Lowest: ",min(numbers))

print("Highest: ",max(numbers))

print("Total: ",total)

print("Average: ",total/5)

Explanation:

The program uses list to answer the question

This initializes an empty list

numbers = []

This initializes total to 0

total = 0

The following loop is repeated 5 times

for i in range(5):

This gets each input

   num = float(input(": "))

This appends each input to the list

   numbers.append(num)

This adds up each input

   total+=num

   

This prints the lowest using min() function

print("Lowest: ",min(numbers))

This prints the highest using max() function

print("Highest: ",max(numbers))

This prints the total

print("Total: ",total)

This calculates and prints the average

print("Average: ",total/5)

6 0
2 years ago
What is earning potential?
Natalka [10]

Answer:

Earning potential often refers to the top salary for a particular field or profession. In the finance world, the meaning is not much different: earning potential is the biggest profit a company could potentially make.

Explanation:

Earning potential often refers to the top salary for a particular field or profession. In the finance world, the meaning is not much different: earning potential is the biggest profit a company could potentially make.

4 0
3 years ago
Which type of software-generated problems can indicate that a software bug is causing a memory error?
Katena32 [7]
The type of software-generated problems that can indicate that a software bug is causing a memory error are page fault, exception error and general-protection fault. Registry errors show that there are parts of the registry that were written to the faulty parts of the RAM. An erroneous memory count would happen when there is incompatibility in the installation.
3 0
3 years ago
In which of the following scenarios would you use the Redo function?
MakcuM [25]
D. <span>You have just used the Undo function to delete a paragraph, and you want that paragraph back.</span>
6 0
2 years ago
Other questions:
  • What might the purpose be for a sata-style power connector on a motherboard?
    15·1 answer
  • Given a int variable named yesCount and another int variable named noCount and a char variable named response, write the necessa
    9·1 answer
  • 4. What aspect of the initial database planning process would the formula (0 + Pt × 3 + p)/5 be used in?
    5·1 answer
  • How to get the home button on your screen?
    13·1 answer
  • In apersuasive message, opposing ideas should be:
    13·1 answer
  • What is displayed on the console when running the following program? class Test { public static void main(String[] args) { try {
    10·1 answer
  • Password is an example of an authentication mechanisms that is based on " what an entity has".
    6·2 answers
  • PLEASE HELP! One of the nice byproducts of joining a club, organization, community service project, or service learning project
    6·1 answer
  • Can anyone please help me to solve this question?
    10·1 answer
  • Would you consider upgrading Maxine’s wardrobe a need or a want?
    11·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!