
Hello everyone Hope all are well Just new here & already have a question.
I have a little veg shop it sells 6 apples oranges turnips patotes straberries carrots. And add the price together. oh each item has a price eg apples = .30 ect my problem is I can only buy 3 of the above items without using loops or switch or while Im beginner so only if and nested if and else if This has my head in bits for days I have the below done x6 for each product How i get it to 3 (without throwing the other 3 items away)
double oPrice, orangesCost; int oQuantity; oPrice = 0.45; System.out.println(" \t\t Product Price Calculation"); 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);

import java.util.*;
class Example1{
public static void main(String[]args){
Scanner input=new Scanner(System.in);
System.out.print ("please select one of the following by pressing tne number on your keypad");
System.out.println();
System.out.println("1. Apples");
System.out.println("2. Oranges");
System.out.println("3. Straberries");
System.out.println("4. Potato");
System.out.println("5. Turnips");
System.out.println("6. Carrots");
int fruit=0,quantity=0,totalcost=0;
fruit = input.nextInt();
if (fruit ==1){
System.out.println ("Super choice");
System.out.print("Enter quantity of apples required: ");
quantity = input.nextInt();
int price=100;
totalcost = price * quantity;
}
if (fruit ==2){
System.out.print("Enter quantity of oranges required: ");
quantity = input.nextInt();
int price=50;
totalcost = price * quantity;
}
if (fruit ==3){
System.out.print("Enter quantity of strawberries required: ");
quantity = input.nextInt();
int price=200;
totalcost = price * quantity;
}
if (fruit ==4){
System.out.print("Enter quantity of potatoes required: ");
quantity = input.nextInt();
int price=10;
totalcost = price * quantity;
}
if (fruit ==5){
System.out.print("Enter quantity of apples required: ");
quantity = input.nextInt();
int price=25;
totalcost = price * quantity;
}
if (fruit ==6){
System.out.print("Enter quantity of apples required: ");
quantity = input.nextInt();
int price=20;
totalcost = price * quantity;
}
System.out.println("Total Cost: "+totalcost);
}
}