JAVA ASSIGNMENT : Address Owner -name:String -propertyList:Property[5] -count:in
ID: 3724818 • Letter: J
Question
JAVA ASSIGNMENT :
Address
Owner
-name:String
-propertyList:Property[5]
-count:int
+addProperty(Property p):void
+getPropertyList():Property[]
-street:String
-city:String
-state:String
-zip:int
Property
-address:Address
-marketValue:double
+calculateTax(double taxRate):double
taxRate is a whole number; and is 8
The Owner constructors do not set the propertyList.
There is no setPropertyList.
Write the classes according to our coding standards.
Complete the UML for each class.
PropertyTest program will declare an array of Owners[2]. You will use the following data
in a 2-D string array to create customers and add property to their propertyList.
The following data will be in a String array and used to create customers and property.
Jones
2500 West Seventh St
Fort Worth, Texas 76015
$575,000
Smith
1225 Green Rd.
Euless, Texas 76000
215,500
Jones
123 Mitchell
Arlington, Texas 76019
$120,000
Smith
61 Bose Lane
Dallas, Texas 75002
$310,000
Then, walk through the Owners array and calculate the property taxes and print to a dialog box.
Sample output:
Explanation / Answer
import java.util.*;
// Class Address definition
class Address
{
// Instance variables
String street;
String city;
String state;
int zip;
// Method to set street
void setStreet(String st)
{
street = st;
}// End of method
// Method to set city
void setCity(String ci)
{
city = ci;
}// End of method
// Method to set state
void setState(String st)
{
state = st;
}// End of method
// Method to set zip
void setZip(int zp)
{
zip = zp;
}// End of method
// Method to return street
String getStreet()
{
return street;
}// End of method
// Method to return city
String getCity()
{
return city;
}// End of method
// Method to return state
String getState()
{
return state;
}// End of method
// Method to return zip
int getZip()
{
return zip;
}// End of method
// Overrides toString() method
public String toString()
{
return " Street: " + getStreet() + " City: " + getCity() + " State: " + getState() + " Zip: " + getZip();
}// End of method
}// End of class
// Class Property definition
class Property
{
// Instance variable
double cost;
// Method to set cost
void setCost(double co)
{
cost = co;
}// End of method
// Method to return cost
double getCost()
{
return cost;
}// End of method
// Overrides to String method
public String toString()
{
return String.valueOf(getCost());
}// End of method
}// End of class
// Class Owner definition
class Owner
{
// Instance variable
String name;
double ownerPropertyCost;
int counter;
// Address object declared
Address ownerAddress[];
// Property object declared
Property propertyCost[];
// Default constructor to allocate memory to the arrays
Owner()
{
name = null;
ownerPropertyCost = 0;
counter = 0;
// Creates two objects of Address class
ownerAddress = new Address[2];
// Initializes the object
ownerAddress[0] = new Address();
ownerAddress[1] = new Address();
// Creates two objects of Property class
propertyCost = new Property[2];
// Initializes the object
propertyCost[0] = new Property();
propertyCost[1] = new Property();
}// End of constructor
// Method to add data
void addOwner(String na, String street, String city, String state, int zip, double value)
{
// Assigns data at counter position
name = na;
ownerAddress[counter].setStreet(street);
ownerAddress[counter].setCity(city);
ownerAddress[counter].setState(state);
ownerAddress[counter].setZip(zip);
propertyCost[counter].setCost(value);
ownerPropertyCost += propertyCost[counter].getCost();
// Increase the counter by one
counter++;
}// End of method
// Method to display data
void display()
{
System.out.print(" Name: " + name + " Address 1: " + ownerAddress[0] +
" Address 2: " + ownerAddress[1] +
" Property Cost 1: " + propertyCost[0] + " Property Cost 2: " + propertyCost[1] +
" Owner Property Cost: " + ownerPropertyCost);
}// End of method
}// End of class
// Driver class PropertyTest definition
public class PropertyTest
{
// Main method definition
public static void main(String ss[])
{
double grandTotalCost = 0;
// Creates two object of Owner class
Owner ow[] = new Owner[2];
// Allocates memory to each object
for(int x = 0; x < 2; x++)
ow[x] = new Owner();
// Creates String array to store name
String names[] = {"Jones", "Smith"};
// Creates String array to store street
String streets[] = {"2500", "1225", "123", "61"};
// Creates String array to store city
String cities[] = {"West Seventh St Fort Worth", "Green Rd. Euless", "Mitchell Arlington", "Bose Lane Dallas"};
// Creates integer array to store zip code
int zips[] = {76015, 76000, 76019, 75002};
// Creates double array to store property cost
double values[] = {575000, 215500, 120000, 310000};
// Scanner class object created
Scanner sc = new Scanner(System.in);
// Loops 4 times
for(int x = 0; x < 4; x++)
{
// Accepts name
System.out.print(" Enter Name: ");
String name = sc.next();
// Checks if name is "Jones" then adds data to zero index position
if(name.equalsIgnoreCase("Jones"))
ow[0].addOwner(names[0], streets[x], cities[x], "Texas", zips[x], values[x]);
// Otherwise adds data to one index position
else
ow[1].addOwner(names[1], streets[x], cities[x], "Texas", zips[x], values[x]);
grandTotalCost += values[x];
}// End of for loop
// Loops two times to display the data
for(int x = 0; x < 2; x++)
ow[x].display();
// Displays texas total property cost
System.out.println(" Texas total property cost: " + grandTotalCost);
// Close scanner
sc.close();
}// End of main method
}// End of class
Sample Output:
Enter Name: Jones
Enter Name: Smith
Enter Name: Jones
Enter Name: Smith
Name: Jones
Address 1:
Street: 2500
City: West Seventh St Fort Worth
State: Texas
Zip: 76015
Address 2:
Street: 123
City: Mitchell Arlington
State: Texas
Zip: 76019
Property Cost 1: 575000.0
Property Cost 2: 120000.0
Owner Property Cost: 695000.0
Name: Smith
Address 1:
Street: 1225
City: Green Rd. Euless
State: Texas
Zip: 76000
Address 2:
Street: 61
City: Bose Lane Dallas
State: Texas
Zip: 75002
Property Cost 1: 215500.0
Property Cost 2: 310000.0
Owner Property Cost: 525500.0
Texas total property cost: 1220500.0
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.