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
Why does the position of drawCircle(x, y, r) in the answer choices matter?
Andrei [34K]

Answer:

B and C

Explanation:

xPos and yPos determine the center of the circle, and rad determines the radius of the circle drawn.

It cannot be A because it starts drawing a circle with the center of (4, 1). None of the circles ahve a center at (4, 1). It is B because while it does start at (4, 1), the repeat function adds one to the y and radius. While ti repeats 3 times it ends up drawing all 3 circles. C also works because it starts by drawing the biggest circle and then subtracting the values to make the other two. It cannot be D because in the repeat function it subtracts from the y value and radius too early, it doesn't draw the biggest circle.

6 0
1 year ago
Brainstorm what you want your LED board to do. What would need to happen first? What happens next?
lbvjy [14]
First it will glow then change what color you want
5 0
3 years ago
Read 2 more answers
Circular errors are caused by adding the cell name of a/an _______ cell to a formula.
Alex777 [14]
The word you are looking for is active.
4 0
3 years ago
Why is it important to understand the basic ways in which pictures and video are stored in the computer?
nalin [4]

Answer:

This is important to understand the basic ways to store pictures and video in a computer because both of them consume a relatively large storage spaces in a the computer compared with normal text files.

Explanation:

Nowadays, many computers shipped with a SSD drive (Solid State Drive) with only around 256 - 512 Gb. With this capacity, the storage spaces left to store the pictures and video are very limited after installation of the essential software.

One common way to store pictures and video is to save them at an external hard drive. Another option is the cloud storage service such as Google Drive, Google Photo etc. These storage mediums obviate the need to store those media files into the local computer machine.

6 0
3 years ago
During which process does the computer load its operating system?
cupoosta [38]
A bootstrapping process, also known as booting
5 0
3 years ago
Other questions:
  • The first character of the VIN designates which of the following? 
    15·2 answers
  • Ad designers use movement in order to
    9·2 answers
  • A cloud file system (CFS) allows users or applications to directly manipulate files that reside on the cloud.
    6·1 answer
  • Write a couple of paragraph on 'limited government and its important'?​
    7·1 answer
  • The
    6·2 answers
  • Class members are accessed via the ____(1)_____ operator in conjunction with the name of an object of the class, or via the ___(
    6·1 answer
  • Marie has never used a word processor. In 3 to 4 sentences, describe how she could benefit from using a word processor to comple
    7·2 answers
  • What would happen without satellites???
    12·2 answers
  • O Why was the Internet originally constructed? Oto enable researchers to communicate
    6·2 answers
  • If you select one slice of pie in a pie chart, you have selected a ____
    13·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!