TheProgrammerDude - 1 year ago 58

Java Question

This is a homework question that been working on for awhile, but i cant seem to figure out the rest.

Your program is going to calculate the price of some bags of coffee.

You will first ask the user; how many bags of coffee do they want.

The price per bag is $5.50 each. Your price must also include the

shipping of how many boxes this shipment will require. There are

three size shipping boxes available. A large box can hold 20 bags, a

medium box holds 10 bags, and a small box can hold up to 5 bags. You

cannot ship large or medium boxes that are not full. (but small ones

can have 1-5 bags in them) The price of shipping per box is large =

$1.80, medium = $1.00, and small = $0.60 . One final price change is

a possible discount. Use the following chart to calculate the

discount off of the coffee price (NOT off the shipping).

`0-24 bags - no discount`

25-49 bags – 5% discount

50-99 bags – 10% discount

100-149 bags – 15% discount

150-199 bags - 20% discount

200-299 bags - 25% discount

300 and up - 30% discount

Discount is not to be used on the boxes. Use if statements or a

switch statement to get this done.

`import java.util.Scanner;`

public class discount {

public static void main(String[] args) {

Scanner key = new Scanner(System.in);

System.out.println("Hello how are you? How many numberbags of coffee would you like?");

double numberbag;

double bag = 5.50;

numberbag = key.nextDouble();

System.out.println("Number of numberbags ordered: " + numberbag);

double price = (numberbag * bag);

System.out.println("- $" + price);

if (numberbag < 24 && numberbag > 0) {

System.out.println("no discount: $" + price);

}

else if (numberbag < 49 && numberbag > 25) {

System.out.println("5% discount: $" + price * .05);

}

else if (numberbag < 99 && numberbag > 50) {

System.out.println("10% discount: $" + price * .10);

}

else if (numberbag < 149 && numberbag > 100) {

System.out.println("15% discount: $" + price * .15);

}

else if (numberbag < 199 && numberbag > 150) {

System.out.println("20% discount: $" + price * .20);

}

else if (numberbag < 299 && numberbag > 200) {

System.out.println("25% discount: $" + price * .25);

}

else {

System.out.println("30% discount: $" + price * .30);

}

double small = ;

double medium = 10;

double large = 20;

double sp = 0.60;

double mp = 1.00;

double lp = 1.80;

double Rl = numberbag%large;

double Rm = Rl%medium;

double Rs = Rm%small;

Answer Source

Change it to this

```
if (numberbag < 24 && numberbag > 0) {
System.out.println("no discount: $" + price);
}
else if (numberbag < 49 && numberbag > 25) {
System.out.println("5% discount: $" + (price - (price * .05)));
}
else if (numberbag < 99 && numberbag > 50) {
System.out.println("10% discount: $" + (price - (price * .10)));
}
else if (numberbag < 149 && numberbag > 100) {
System.out.println("15% discount: $" + (price - (price * .15)));
}
else if (numberbag < 199 && numberbag > 150) {
System.out.println("20% discount: $" + (price - (price * .20)));
}
else if (numberbag < 299 && numberbag > 200) {
System.out.println("25% discount: $" + (price - (price * .25)));
}
else {
System.out.println("30% discount: $" + (price - (price * .30)));
}
```