JavaHelp (Discount Calculator)

• 02-24-2010, 06:04 AM
dcoi
JavaHelp (Discount Calculator)
I'm trying to create a class that stores the number of units sold and has a method that returns the total cost of the purchase.

It displays a small chart with the quantity and percent discount.

I cant figure this out, can anyone help?

below is the the code I have so far. :( :confused: :eek:

import java.util.Scanner;

public class salescommision
{
public static void main(String[] args)
{
double
total = 99, //The total price before the offered discount was supposed to be 99\$
quantity,
discount = 0,
cost = (total-discount);

Scanner keyboard = new Scanner(System.in);

System.out.println("This program calculates the discounts "
+ "3 test scores.");

System.out.print("Enter quantity: ");
quantity = keyboard.nextDouble();

total = (total * discount);
System.out.println("The total is " + total);

// The goal is if between these number of quantities you will get a certain percent discount
if (total < 19)
System.out.println("20%");
else if (total < 49)
System.out.println("30%");
else if (total < 99)
System.out.println("40%");
else if (total < 100)
System.out.println("50%");
}
}
• 02-24-2010, 09:11 AM
r035198x
1.) Please use code tags when posting code.
2.) What happens when you attempt to compile/run your code and what did you expect instead?
• 02-24-2010, 11:32 PM
dcoi
:confused:The exact assignment is:

A company sells a package for 99\$. Quantity discounts are given according to the current table.

Quantity Discount
10-19 20%
20-49 30%
50-99 40%
100 or More 50%

Design a class that stores the number of units sold and has a method that returns the total cost of the purchase.

My outcome is: (with 23 entered, but any # can be).

Enter quantity: 23
The total is 99.0
20%

I have to somehow make an if/else statement that calculates percentages and displays in the println? But I keep trying and failing, If you could help at all or lead me to a better direction I would really appreciate it.