Hello just arrived today so hello everyone
I'm trying to get my head around if statments
I have 6 items that i can buy (in my little shop) But I am only allowed to buy 3 of the 6
I have the code worked out price, quantity ect
but cant manage the ifs
here is what i have so far without any ifs any help would be super it is causing me to dream in if's
I am only starting out so I can only use if, if else and else
import java.util.Scanner;
class ApplesBanannas
{
public static void main(String args[]) throws Exception
{
double aPrice, appleCost;
int aQuantity;
aPrice = 0.30;
Scanner in = new Scanner(System.in); // standard input is keyboard for console application,
System.out.print("Enter quantity of apples required ");
aQuantity = in.nextInt();
appleCost = aPrice * aQuantity; //calculate final cost by adding tax
String fs1 = String.format(" your apples will cost you: %.2f", appleCost);
System.out.println(fs1);
double oPrice, orangesCost;
int oQuantity;
oPrice = 0.45;
System.out.print("Enter quantity of oranges required ");
oQuantity = in.nextInt();
orangesCost = oPrice * oQuantity; //calculate final cost by adding tax
String fs2 = String.format(" your oranges will cost you: %.2f", orangesCost);
System.out.println(fs2);
double stPrice, straberriesCost;
int stQuantity;
stPrice = 2.30;
System.out.print("Enter quantity of straberries required ");
stQuantity = in.nextInt();
straberriesCost = stPrice * stQuantity; //calculate final cost
String fs3 = String.format(" your straberries will cost you: %.2f", straberriesCost);
System.out.println(fs3);
double pPrice, patatoCost;
int pQuantity;
pPrice = 3.25;
System.out.print("Enter quantity of patatoes required ");
pQuantity = in.nextInt();
patatoCost = pPrice * pQuantity; //calculate final cost
String fs4 = String.format(" your patatoes will cost you: %.2f", patatoCost);
System.out.println(fs4);
double tPrice, turnipCost;
int tQuantity;
tPrice = 0.70;
System.out.print("Enter quantity of turnips required ");
tQuantity = in.nextInt();
turnipCost = tPrice * tQuantity; //calculate final cost
String fs5 = String.format(" your turnips will cost you: %.2f", turnipCost);
System.out.println(fs5);
double cPrice, carrotCost;
int cQuantity;
cPrice = 1.25;
System.out.print("Enter quantity of carrots required ");
cQuantity = in.nextInt();
carrotCost = cPrice * cQuantity; //calculate final cost
String fs6 = String.format(" your carrots will cost you: %.2f", carrotCost);
System.out.println(fs6);
System.out.println (" \t\t your basket total comes to");
System.out.println(+appleCost + carrotCost+ " Please have your money Ready to check out");
}
}