Java Reference
In-Depth Information
{
static Scanner console = new Scanner(System.in);
public static void main(String[] args)
{
double cost;
double area;
double bagSize;
System.out.print("Enter the amount of fertilizer, "
+ "in pounds, in one bag: ");
bagSize = console.nextDouble();
System.out.println();
System.out.print("Enter the cost of the " + bagSize
+ " pound fertilizer bag: ");
cost = console.nextDouble();
System.out.println();
System.out.print("Enter the area, in square feet, that "
+ "can be fertilized by one bag: ");
area = console.nextDouble();
System.out.println();
System.out.printf("The cost of the fertilizer per pound is: "
+ "$%.2f%n", bagSize / cost);
System.out.printf("The cost of fertilizing per square "
+ "foot is: $%.4f%n", area / cost);
}
}
5. The manager of a football stadium wants you to write a program that
calculates the total ticket sales after each game. There are four types of
tickets—box, sideline, premium, and general admission. After each game,
data is stored in a file in the following form:
ticketPrice
numberOfTicketsSold
.
.
.
Sample data are shown below:
250 5750
100 28000
50 35750
25 18750
The first line indicates that the box ticket price is $250 and that 5750 tickets
were sold at that price. Output the number of tickets sold and the total sale
amount. Format your output with two decimal places.
Search WWH ::




Custom Search