In this assignment, you will implement Address and Residence classes.
Create a new java project.
Part A
Add and implement a class named Address according to specifications in the UML class diagram.
To demonstrates the Address class, in main method write a program that:
Example of data:
PART B
Add and implement a class named Residence according the instruction in the UML diagram
In main method, you already created an instance of Address class called testAddress and prompted the user to enter the address details.
// Address.java
public class Address
{
private String street;
private String city;
private String province;
private String zipCode;
// default constructor
public Address()
{
street = "";
city = "";
province = "";
zipCode = "";
}
// parameterized constructor
public Address(String street, String city, String
province, String zipCode)
{
this.street = street;
this.city = city;
this.province = province;
this.zipCode = zipCode;
}
// setters
public void setStreet(String street)
{
this.street = street;
}
public void setCity(String city)
{
this.city = city;
}
public void setProvince(String province)
{
this.province = province;
}
public void setZipCode(String zipCode)
{
this.zipCode = zipCode;
}
// getters
public String getStreet()
{
return street;
}
public String getProvince()
{
return province;
}
public String getCity()
{
return city;
}
public String getZipCode()
{
return zipCode;
}
// return String representation
public String toString()
{
return street+", "+city+",
"+province+" - "+zipCode;
}
}
//end of Address.java
// Residence.java
public class Residence {
private int bedrooms;
private int bathrooms;
private double price;
private int squareFeet;
private int yearBuilt ;
private Address address;
// default constructor
public Residence()
{
bedrooms = 0;
bathrooms = 0;
price = 0;
squareFeet = 0;
yearBuilt = 0;
address = new Address();
}
// parameterized constructor
public Residence(int bedrooms, int bathrooms, double
price, int squareFeet, int yearBuilt, Address address)
{
this.bedrooms = bedrooms;
this.bathrooms = bathrooms;
this.squareFeet = squareFeet;
this.yearBuilt = yearBuilt;
this.price = price;
this.address = address;
}
// setters
public void setBedrooms(int bedrooms)
{
this.bedrooms = bedrooms;
}
public void setBathrooms(int bathrooms)
{
this.bathrooms = bathrooms;
}
public void setSquareFeet(int squareFeet)
{
this.squareFeet = squareFeet;
}
public void setYearBuilt(int yearBuilt)
{
this.yearBuilt = yearBuilt;
}
public void setAddress(Address address)
{
this.address = address;
}
// getters
public int getBedrooms()
{
return bedrooms;
}
public int getBathrooms()
{
return bathrooms;
}
public double getPrice()
{
return price;
}
public int getSquareFeet()
{
return squareFeet;
}
public int getYearBuilt()
{
return yearBuilt;
}
public Address getAddress()
{
return address;
}
// method to calculate and return commission
public double calculateCommission()
{
return price*0.02;
}
// toString method
public String toString()
{
return "Address:
"+address.toString()+"\nSquare feet: "+squareFeet+"\nYear built:
"+yearBuilt+"\nBedrooms: "+bedrooms+
"\nBathrooms: "+bathrooms+"\nPrice:
"+price+"\nCommission: "+calculateCommission();
}
}
//end of Residence.java
// ResidenceTester.java : Java program to test Address and Residence class
import java.util.Scanner;
public class ResidenceTester {
public static void main(String[] args) {
String street, city, province,
zipCode;
int bathrooms, bedrooms, yearBuilt,
squareFeet;
double price;
Address testAddress;
Scanner scan = new
Scanner(System.in);
// input details of Address
System.out.print("Enter the street:
");
street = scan.nextLine();
System.out.print("Enter city:
");
city = scan.nextLine();
System.out.print("Enter province:
");
province = scan.nextLine();
System.out.print("Enter zip code:
");
zipCode = scan.nextLine();
// create an object of Address
class
testAddress = new Address(street,
city, province, zipCode);
System.out.println(testAddress); //
display Address using toString method of Address class
Residence residence;
// input details of Residence
System.out.print("Enter number of
bedrooms: ");
bedrooms = scan.nextInt();
System.out.print("Enter number of
bathrooms: ");
bathrooms = scan.nextInt();
System.out.print("Enter square
feet: ");
squareFeet = scan.nextInt();
System.out.print("Enter year built:
");
yearBuilt = scan.nextInt();
System.out.print("Enter price:
");
price = scan.nextDouble();
// create object of Residence
class
residence = new Residence(bedrooms,
bathrooms, price, squareFeet, yearBuilt, testAddress);
System.out.println("Residence:\n"+residence); //display Residence
details using toString method of Residence class
}
}
//end of ResidenceTester.java
Output:
In this assignment, you will implement Address and Residence classes. Create a new java project. Part...
JAVA :The following are descriptions of classes that you will create. Think of these as service providers. They provide a service to who ever want to use them. You will also write a TestClass with a main() method that fully exercises the classes that you create. To exercise a class, make some instances of the class, and call the methods of the class using these objects. Paste in the output from the test program that demonstrates your classes’ functionality. Testing...
Need help to create general class Classes Data Element - Ticket Create an abstract class called Ticket with: two abstract methods called calculateTicketPrice which returns a double and getld0 which returns an int instance variables (one of them is an object of the enumerated type Format) which are common to all the subclasses of Ticket toString method, getters and setters and at least 2 constructors, one of the constructors must be the default (no-arg) constructor. . Data Element - subclasses...
I need the following written in Java please, thank you ' We want you to implement a java class that will show details on users and throw exceptions where needed. The following requirements specify what fields you are expected to implement in your User class: - A private String firstName that specifies the first name of the user - A private String lastName that specifies the last name of the user - A private int age that specifies user's age...
Part 1. (60 pts) 1. Define an Address class in the file Address.h and implement the Address class in Address.cpp. a. This class should have two private data members, m_city and m_state, that are strings for storing the city name and state abbreviation for some Address b. Define and implement public getter and setter member functions for each of the two data members above. Important: since these member functions deal with objects in this case strings), ensure that your setters...
Deliverable A zipped NetBeans project with 2 classes app ZipCode Address Classes Suggestion: Use Netbeans to copy your last lab (Lab 03) to a new project called Lab04. Close Lab03. Work on the new Lab04 project then. The Address Class Attributes int number String name String type ZipCode zip String state Constructors one constructor with no input parameters since it doesn't receive any input values, you need to use the default values below: number - 0 name - "N/A" type...
java with Part 1 Write the Java classes given with their fields. Implement their constructors, toString methods, getters and setters. Then create three Ticket instances. • Airport: String name, String city, String country • Route: Airport departure , Airport destination • Date: int day, int month, int year (Day must be between 0-31, month must be between 0-12, year must be between 2020-2025; please consider this when you're implementing setters and constructors). • ClockTime: int hour, int minute (Hour must...
Implement a new Generic class called a ShapeBox. This class will have two instance data, a Shape object (as in the graphics Shape like Circle, Rectangle, Ellipse), and a double to store the Shape's area. The specific type of Shape will be specified via Generics so that your class will need a placeholder for the type of Shape. This placeholder must extend Shape. Additionally, ShapeBox will implement the Comparable interface requiring that you implement a compareTo method to compare this...
signature 1. Create a new NetBeans Java project. The name of the project has to be the first part of the name you write on the test sheet. The name of the package has to be testo You can chose a name for the Main class. (2p) 2. Create a new class named Address in the test Two package. This class has the following attributes: city: String-the name of the city zip: int - the ZIP code of the city...
********************Java Assigment******************************* 1. The following interface and classes have to do with the storage of information that may appear on a mailing label. Design and implement each of the described classes below. public interface AddrLabelInterface { String getAttnName(); String getTitle(); // Mr., Mrs., etc. String getName(); String getNameSuffix(); // e.g., Jr., III String getProfessionalSuffix(); // O.D. (doctor of optometry) String getStreet(); String getSuiteNum(); String getCity(); String getState(); String getZipCode(); } Step 1 Create an abstract AddrLabel class that implements the...
Please help me with this code. Thank you Implement the following Java class: Vehicle Class should contain next instance variables: Integer numberOfWheels; Double engineCapacity; Boolean isElectric, String manufacturer; Array of integers productionYears; Supply your class with: Default constructor (which sets all variables to their respective default values) Constructor which accepts all the variables All the appropriate getters and setters (you may skip comments for this methods. Also, make sure that for engineCapacity setter method you check first if the vehicle...