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
The ______________ steps through the source code, converting each source code instruction into appropriate machine language foll
grandymaker [24]

Answer:

Compiler

Explanation:

A compiler takes the source code thereby converting them to a machine language object file in which the linker combines this object file with other previously compiled object files in order to create file that are executable.

A compiler is also change or transform code that are typically written in a high-level programming language into the machine code.

Therefore The COMPILER steps through the source code, converting each source code instruction into appropriate machine language following the strict rules of the language and writing the machine code to a separate file.

4 0
3 years ago
Consider the binary search tree constructed for the words oenology, phrenology, campanology, ornithology, ichthyology, limnology
Sveta_85 [38]

Explanation:

Binary Search Tree is also called ordered tree or sorted binary tree. In the tree each node contains smaller values in the left side of the subtree and larger values in the right side of  the subtree.

7 0
3 years ago
The index used by the OS to manage computer files is called _____.
tester [92]

Answer:

GUI

Explanation:

4 0
3 years ago
Read 2 more answers
What is the hack of the cookie clicker
zlopas [31]

Answer:

<h3><u>Open </u><u>Sesame</u></h3>

  • <u>New Pokemon Games - The Loop. Open Sesame is the control panel for Cookie Clicker. It can be opened with a console command, or by changing the name of your bakery.</u>

Explanation:

<h2>Hope this helps you !! </h2>
7 0
3 years ago
im in honors comupter science and one of my questions is evaluate 18% 7 does anyone know how to answer that
yanalaym [24]

Answer:

18% of 7 is 1.26

Explanation:

your question was somewhat unclear

4 0
4 years ago
Other questions:
  • Beside homework, what products can you use for personal use? Identify three uses and briefly describe.
    15·1 answer
  • How many bits are in 1 tb? [hint: depending on the tool used to calculate this, you may need to use a trick to get the exact res
    6·1 answer
  • Attempting to determine a password that is not known to the attacker is often called ____.
    13·1 answer
  • A Unit of information containing the objects position, rotation, and scale values is called:
    13·1 answer
  • A global project called One Laptop per Child is attempting to distribute low-cost laptop computers to children in developing cou
    10·1 answer
  • A ____ error occurs when an instruction does not follow the grammar of the programming language
    6·1 answer
  • Define and discuss statistical significance as it pertains to web analytics, formulate your own opinions of what this means. in
    8·1 answer
  • Which entity might hire a Computer Systems Analyst to help it catch criminals?
    12·2 answers
  • Make and run a Python program which:
    13·1 answer
  • Which of the following includes premium content you must pay to use?<br> On word
    6·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!