need help for a project

• 02-07-2009, 11:57 AM
megironi
need help for a project
I'm doing a project for school, and am just starting out. Really I don't know what I'm doing, I pretty much have to teach myself. Here's what I got so far, please help me if you can. To me it's like attempting to read a foreign language.

import java.util.Scanner;
import java.text.DecimalFormat;
public class assignment2.java
{
final static double BOX_OF_APPLES = 14.00;
final static double BOX_OF_PEACHES = 16.00;
final static double BOX_OF_ORANGES = 18.00;
final static double TAX = 0.10;
public static void main(String[] args)
{
DecimalFormat money = new DecimalFormat("\$0.00");
Scanner in = new Scanner(System.in);
System.out.print("How many boxes of apples do you want? ");
System.out.print("How many boxes of peaches do you want? ");
System.out.print("How many boxes of oranges do you want? ");
double subTotal = in.nextInt() * BOX_OF_APPLES;
double subTotal = in.nextInt() * BOX_OF_PEACHES;
double subTotal = in.nextInt() * BOX_OF_ORANGES;
double taxCost = subTotal * TAX;
double total = subTotal + taxCost;
System.out.println("Cost of food:148.00 " + money.format(subTotal));
System.out.println("Tax:14.80 " + money.format(taxCost));
System.out.println("Total:162.80 " + money.format(total));
}
}

here was my assignment.
The Lone Oak High School Marching Band is raising funds by selling fruit. In order to simplify processing of orders, only three types of packages of fruit are being sold. They are

Box of Apples at a cost of \$14.00
Box of Peaches at a cost of \$16.00
Box of Oranges at a cost of \$18.00

There is a 10.00% tax on the total order amount. Write a Java program that reads the number of each type package on an order and computes the cost for the packages of each type ordered. Total the order, calculate the tax on the order, and the total including the tax. Print all items read and all items calculated with appropriate labels.

Example:

Boxes of Apples: 2
Boxes of Peaches: 3
Boxes of Oranges: 4

Total cost of the fruit: 148.00
Tax: 14.80
Total Amount Due: 162.80
Note: the red is user inputted information (2, 3, 4)
• 02-07-2009, 02:50 PM
Fubarable
You need to ask a specific question to get specific help since this is really what we're best at here. If the question is "I have no clue" then often the best answer is: have a talk with your teacher. Best of luck.
• 02-07-2009, 08:07 PM
It isn't going to compile, because you declared 'subTotal' 3 times in the same scope. What you want is something like...

Code:

```double subTotal = 0; subTotal +=  in.nextInt() * BOX_OF_APPLES; subTotal += ...```
• 02-07-2009, 09:22 PM
megironi
Can anyone tell me whats wrong with the line,

public static void main(String[] args)

Every time I build file, it has errors on that line that say,
; expected, .class' expected, and illegal start of operation. however, when I looked at an example and I can't figure out whats different.
• 02-07-2009, 09:28 PM
CJSLMAN
Don't need the extention...
`public class assignment2[B][COLOR="Red"].java[/COLOR][/B]`