I still am a student and still learning java and I just recently learned how if...else...
works but I don't know how to properly use it. How do I compute and display the amount of the total price using the if...else....
The problem:
A rice store nearby is on sale. All rice is sold at 10% (.1) off per kilo if the customer buys at least 11 kilos. For anything less than that, the regular price applies.
Here is the list of prices:
Lion - Php48/kilo
Ganador - Php50/kilo
Conchita - Php47/kilo
Other types of rice - Php45/kilo
Let the user input the rice purchased and the kilos and then compute and display the total amount the customer needs to pay.
Example: If a customer buys 3 kilos of Lion rice, your program is expected to only compute 3 kilos with the regular price.
Note: Customers may buy rice in any quantity, even half a kilo.
My code:
import java.util.Scanner;
public class Main
{
public static void main (String[] args)
{
System.out.println("List of prices: ");
System.out.println("Lion - Php48/kilo");
System.out.println("Ganador - Php50/kilo");
System.out.println("Conchita - Php47/kilo");
System.out.println("Other types of rice - Php45/kilo");
System.out.println(" ");
Scanner input = new Scanner(System.in);
System.out.println("Type of rice: ");
String rice = input.nextLine();
System.out.println(" ");
System.out.println("Kilos of rice: ");
int kilo = input.nextInt();
System.out.println(" ");
System.out.println("Type of rice: " +rice);
System.out.println("Kilos of rice: " +kilo);
if(kilo>11)
{
System.out.println("You have a discount of 10%.");
}
else if(kilo<11)
{
System.out.println("You have no discount of 10%.");
}
}
}