WRITE IN JAVA PropertyTest program will declare an array of Owners[2]. You will
ID: 3722800 • Letter: W
Question
WRITE IN JAVA
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.
Then, walk through the Owners array and calculate the property taxes and print to a dialog box.
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
Explanation / Answer
import java.util.*;
// Class Owner definition
class Owner
{
// Instance variable to store data
String name[];
String address[];
double propertyCost;
static double grandTotalCost = 0;
double cost[];
int counter = 0;
// Default constructor to allocate memory to the arrays
Owner()
{
address = new String[2];
name = new String[2];
cost = new double[2];
}// End of constructor
// Method to add data
void addOwner(String na, String add, double value)
{
// Assigns data at counter position
name[counter] = na;
address[counter] = add;
cost[counter] = value;
// Calculates total property cost for each owner
propertyCost += cost[counter];
// Calculates all owners property cost
grandTotalCost += cost[counter];
// Increase the counter by one
counter++;
}// End of method
// Method to display data
void display()
{
System.out.print(" Name: " + name[0] + " Property address 1: " + address[0] +
" Property address 2: " + address[1]);
System.out.print(" Property 1 value: " + cost[0] + " Property 2 value: " + cost[1]);
System.out.print(" Total property cost: " + propertyCost);
}// End of method
// Method to return grand total of property
static double getGrandTotalCost()
{
return grandTotalCost;
}// End of method
}// End of class
// Driver class PropertyTest definition
public class PropertyTest
{
// Main method definition
public static void main(String ss[])
{
// 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 address
String add[] = {"2500 West Seventh St Fort Worth, Texas 76015", "1225 Green Rd. Euless, Texas 76000",
"123 Mitchell Arlington, Texas 76019", "61 Bose Lane Dallas, Texas 75002"};
// Creates double array to store property cost
double value[] = {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], add[x], value[x]);
// Otherwise adds data to one index position
else
ow[1].addOwner(names[1], add[x], value[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: " + Owner.getGrandTotalCost());
// 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
Property address 1: 2500 West Seventh St Fort Worth, Texas 76015
Property address 2: 123 Mitchell Arlington, Texas 76019
Property 1 value: 575000.0 Property 2 value: 120000.0
Total property cost: 695000.0
Name: Smith
Property address 1: 1225 Green Rd. Euless, Texas 76000
Property address 2: 61 Bose Lane Dallas, Texas 75002
Property 1 value: 215500.0 Property 2 value: 310000.0
Total 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.