import java.util.*;
public class Concert
{ private final double TAX_RATE = 0.21;
private final int PARTNERS = 3;
private Guards guards = new Guards();
private Stadium stadium = new Stadium();
private double BAND = 10000.00;
private Shirts shirts;
public Concert()
{ stadium.sell();
shirts = new Shirts();
showOutput(); }
void showOutput()
{ System.out.println("Total attendance was " + stadium.attendance());
System.out.println("My take is $" + twoDecimals(myTake()));
System.out.println(); }
private double myTake()
{ return nett() / PARTNERS; }
private double tax(double amount)
{ return amount * TAX_RATE; }
private double nett()
{ double profit = profit() + shirts.profit();
return profit - tax(profit); }
private double profit()
{ return income() - cost(); }
private double income()
{ return stadium.income(); }
private double cost()
{ double cost = BAND + stadium.cost() + guards.cost(stadium.attendance()) ;
return cost; }
private double twoDecimals(double amount)
{ int intResult = (int) (amount * 100);
return intResult / 100.0; }
}
-----------------------------------------------------------------------------
public class Stadium
{ private final double RENT = 20000.00;
private final double SECURITY_RATE = 0.32;
private Guards guards;
private SeatGroup cheap, great;
public Stadium()
{ cheap = new SeatGroup("cheap", 2000, 60.00);
great = new SeatGroup("great", 100, 500.00); }
public void sell()
{ cheap.sell();
great.sell(); }
public int attendance()
{ return cheap.sold() + great.sold(); }
public double income()
{ return cheap.income() + great.income(); }
public double cost()
{ return RENT; }
}
--------------------------------------------
import java.util.*;
import java.util.Random;
public class SeatGroup
{ private Scanner input = new Scanner(System.in);
private Random random = new Random(121);
private String name;
private int number;
private double price;
private int sold;
public SeatGroup(String name, int number, double price)
{
this.name = name;
this.number = number;
this.price = price;
}
public int sold()
{
return sold;
}
public void sell()
{
sold = generateSold(); //You would also need to change the prompt below to something meaningful.
}
private int generateSold()
{
double value = random.nextDouble();
return (int) (value * number);
}
public double income()
{
return price * sold;
}
}
-------------------------------------------------------
public class Guards
{
private final int PER_GUARD = 200;
private final double RATE = 56.00;
private final int HOURS = 6;
public double cost(int attendance)
{
// Refer tutorial notes and lecture notes to calculate cost
return RATE * HOURS * guards(attendance);
}
private int guards(int attendance)
{
return roundUp(attendance / PER_GUARD);
}
private int roundUp(double value)
{
return (int) Math.ceil(value);
}
}
--------------------------------------------
import java.util.*;
public class Shirts
{
private final double costs =2;
private final double print =1;
private final double price =40;
private final double number =600;
private int sold;
private Scanner input = new Scanner(System.in);
public Shirts()
{
System.out.print("Number of shirts sold :" );
sold = input.nextInt();
}
public double profit()
{
return price * sold - costs();
}
private double costs()
{
return costs * print * number ;
}
}
No comments:
Post a Comment