I hava a Java homework assignment where I need to use two classes. One is Order
ID: 3535276 • Letter: I
Question
I hava a Java homework assignment where I need to use two classes. One is Order which is the supplier class and Landscaper which is the client class. My problem is I cant figure out how to share information between the two classes and get the correct results. Here is what I have so far. I attempted to get the information from class Order to Lanscaper class in the Lanscaper costOfRock (); but it only sends information from the first standard order. I also need a way to figure out the maximumorder and heaviest order. any help would be greatly appreciated.
public class Order
{
//instance variables
private int tonsSand;
private int tonsRock;
private int tonsTopSoil;
private int tonsBark;
private int weightTons;
int rockCount = 0;
int sandCount = 0;
int soilCount = 0;
int barkCount = 0;
public Order(int tonsRockCount, int tonsSandCount, int tonsTopSoilCount, int tonsBarkCount) {
tonsSand = tonsSandCount;
tonsRock = tonsRockCount;
tonsTopSoil = tonsTopSoilCount;
tonsBark = tonsBarkCount;
}
public Order(){
tonsRock = 10;
tonsTopSoil = 5;
tonsBark = 3;
}
public Order(int underlayCount, int coverCount) {
tonsSand = underlayCount * 6;
tonsRock = underlayCount * 10;
tonsTopSoil = coverCount * 5;
tonsBark = coverCount * 4;
}
public int getSandCount(){
return tonsSand;
}
public int getRockCount(){
return tonsRock;
}
public int getTopSoilCount(){
return tonsTopSoil;
}
public int getBarkCount(){
return tonsBark;
}
public int weightOfOrder(){
weightTons = tonsBark + tonsRock + tonsSand + tonsTopSoil;
return weightTons;
}
}
public class Landscaper
{
// add class constants
public int totalRock;
public int totalSand;
public int totalBark;
public int totalSoil;
public int mostExpensiveOrde;
public int heaviestOrde;
public static final double costOfRock = 21.00;
public static final double costOfSand = 3.99;
public static final double costOfTopSoil = 15.50;
public static final double costOfBark = 24.50;
public double cost;
public double priceOfSale;
public double totalSales = 0;
// add instance variables
// add constructors
public Landscaper(){
double rock = 1000;
double sand = 1000;
double topsoil = 500;
double bark = 500;
double totalSales = 0;
double rockCount;
}
// add QUERY methods
public double costOfOrder(Order order){
Order Rock = new Order();
totalRock = Rock.getRockCount();
Order Sand = new Order();
totalSand = Sand.getSandCount();
Order Soil = new Order();
totalSoil = Soil.getTopSoilCount();
Order Bark = new Order();
totalBark = Bark.getBarkCount();
cost = (costOfRock * totalRock) + (costOfSand * totalSand) + (costOfTopSoil * totalSoil) + (costOfBark * totalBark);
totalSales += cost;
return cost;
}
public double getTotalSales(){
return totalSales;
}
// add UPDATE method
public double processOrder(Order request ){
if (request == null) {
throw new NullPointerException();
}
else{
totalSales += cost;
return totalSales;
}
}
public void printInventory(){
System.out.print("hello");
}
public void test()
{
final String dashes = "---------------------------";
Order order1 = new Order();
Order order2 = new Order( 2, 3 );
Order order3 = new Order(2, 60, 2, 2 );
processOrder( order3 );
processOrder( order2 );
double price = processOrder( order1 ); // use return value
System.out.println( dashes );
System.out.println( "Price for one Combo Package = " + price );
System.out.println( dashes );
System.out.println( "Contents of order #3:" );
System.out.println( order3.getRockCount() + " tons of rock" );
System.out.println( order3.getSandCount() + " tons of sand" );
System.out.println( order3.getTopSoilCount() + " tons of topsoil" );
System.out.println( order3.getBarkCount() + " tons of bark" );
System.out.println( dashes );
printInventory();
double balance = getTotalSales();
}
}
Explanation / Answer
add method on class Order
string MaximumAndHeaviestOrder(){
double heavy[]={tonsBark , tonsRock , tonsSand , tonsTopSoil};
double he = heavy[0];
for(int i=1;i<4;i++)
if(he < heavy[i])
he=heavy[i];
for( i=0;i<4;i++)
if(he=heavy[i])
break;
switch(i){
case 0:
return "Bark";
case 1:
return "Rock";
case 2:
return "Sand";
case 3:
return "Soil";
}
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.