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
To hide gridline when you display or print a worksheet
Bingel [31]
Hide it under the copier
7 0
4 years ago
Your boss bought a new printer with a USB 3.0 port, and it came with a USB 3.0 cable. Your boss asks you:
postnew [5]

Answer:

Will the printer work when I connect the printer's USB cable into a USB 2.0 port on my computer:

b. Yes, but at the USB 2.0 speed.

Explanation:

  • The option a is not correct as we can use 2.0 port also for this purpose but not only 3.0.
  • The option b is correct as we can use 2.0 USB Port for 3.0 USB but the speed will remain that of 2.0 USB.
  • The option c is incorrect as  because the speed is dependent on the speed of port.
  • The option d is incorrect as because USB can have speed of 2.0 or 3.0 depending upon the port and USB but can't have 1.1 speed.
8 0
3 years ago
Read 2 more answers
Write python code that does the following.
Mariulka [41]

Answer:

the answers are in front of you it is correct to follow the steps

¯\_(ツ)_/¯:

5 0
3 years ago
A computerized spreadsheet program is useful for
Vaselesa [24]
Its c storing and charting data from surveys
6 0
4 years ago
Read 2 more answers
1. ___________ ensures the integrity and security of data that are passing over a network.
allochka39001 [22]

Answer:

The correct answer to the following question will be Option D (Network-security protocols).

Explanation:

  • Methods and procedures for protecting network data from unwanted information retrieval are managed by network security protocols.
  • They are a network-style protocol that guarantees the protection and privacy of data in transit through a wireless connection. It describes procedures and techniques for protecting network data from every unauthorized effort to access or remove data material.

Therefore, Option D is the right answer.

5 0
4 years ago
Other questions:
  • I just wanted to know what are some of the challenges that could arise from setting up a file management system on a computer
    11·2 answers
  • What technical elements can a film director manipulate to achieve the final product, conveying his ideology and vision?
    11·1 answer
  • Based on the Pizza database you imported, complete the SQL statement below to add the column VIP to the customers table. The cus
    8·1 answer
  • Which files have not been processed by your camera or computer?
    13·1 answer
  • Technician A says that almost every part of a vehicle is somehow powered by or controlled by an electrical or electronic system.
    9·2 answers
  • Why can it be helpful to perform mathematical calculations using programming? Choose the best answer.
    11·1 answer
  • This road sign means
    14·2 answers
  • Which symbol should you use for entering a formula in a cell?
    7·2 answers
  • *please be serious and also answer everything * <br> I will also mark you brainliest :)
    6·1 answer
  • Apart from mATX and ATX what are the other form factors of power supply
    7·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!