Ive to write a software program that allows a user to order groceries?
Ive to ask for the users details names, address etc.
I have to ask the user to input their grocery item and then the quantity for 3 items only.
and then add up the total cost and output the total cost to the screen.
I have done the following but getting 3 errors I cant figure it out as Im only after starting to learn Java.
import java.util.Scanner;
class Grocery1
{
public static void main(String[]args)
{
Scanner in = new Scanner (System.in);
// User details input needed. String variables.
String name;
String address;
String creditCardNum;
String expiryDate;
String dob;
String email;
String email2;
System.out.println("Please enter your Full Name ");{
name = in.nextLine();}
System.out.println("Please enter your Address ");{
address = in.nextLine();}
System.out.println("Please enter your Credit Card Number ");{
creditCardNum = in.nextLine();}
System.out.println("Please enter your Credit Card Expiry Date in 00/00 format ");{
expiryDate = in.nextLine();}
System.out.println("Please enter your Date of Birth in 00/00/00 format ");{
dob = in.nextLine();}
System.out.println("Please enter your email address ");{
email = in.nextLine();}
System.out.println("Please re enter your email address ");{
email2 = in.nextLine();}
//confirm the email
if(email.equals(email2)){
System.out.println(" Thank your email confirmation successful");}
else
{System.out.println(" Sorry you have entered the wrong email");}
Scanner grocery1Item = new Scanner (System.in);
String grocery1;
int grocery1Amt;
double grocery1Cost;
System.out.print("Please enter the first grocery item " );
grocery1 = grocery1Item.nextLine();
System.out.print("Please enter the amount ");
grocery1Amt = grocery1Item.nextInt();
if(grocery1.equalsIgnoreCase("apples")){
grocery1Cost = 0.30 * grocery1Amt;
System.out.println("The total cost for Item 1 is €" + grocery1Cost);}
else if(grocery1.equalsIgnoreCase("oranges")){
grocery1Cost = 0.45 * grocery1Amt;
System.out.println("The total cost for Item 1 is €" + grocery1Cost);}
else if(grocery1.equalsIgnoreCase("strawberries")){
grocery1Cost = 2.30 * grocery1Amt;
System.out.println("The total cost for Item 1 is €" + grocery1Cost);}
else if(grocery1.equalsIgnoreCase("potatoes")){
grocery1Cost = 3.25 * grocery1Amt;
System.out.println("The total cost for Item 1 is €" + grocery1Cost);}
else if(grocery1.equalsIgnoreCase("turnips")){
grocery1Cost = 0.70 * grocery1Amt;
System.out.println("The total cost for Item 1 is €" + grocery1Cost);}
else if(grocery1.equalsIgnoreCase("carrots")){
grocery1Cost = 1.25 * grocery1Amt;
System.out.println("The total cost for Item 1 is €" + grocery1Cost);}
else{
System.out.print(" You have entered an Invalid Item ");}
Scanner grocery2Item = new Scanner (System.in);
String grocery2;
int grocery2Amt;
double grocery2Cost;
System.out.print("Please enter the second grocery item " );
grocery2 = grocery2Item.nextLine();
System.out.print("Please enter the amount ");
grocery2Amt = grocery2Item.nextInt();
if(grocery2.equalsIgnoreCase("apples")){
grocery2Cost = 0.30 * grocery2Amt;
System.out.println("The total cost for Item 2 is €" + grocery2Cost);}
else if(grocery2.equalsIgnoreCase("oranges")){
grocery2Cost = 0.45 * grocery2Amt;
System.out.println("The total cost for Item 2 is €" + grocery2Cost);}
else if(grocery2.equalsIgnoreCase("strawberries")){
grocery2Cost = 2.30 * grocery2Amt;
System.out.println("The total cost for Item 2 is €" + grocery2Cost);}
else if(grocery2.equalsIgnoreCase("potatoes")){
grocery2Cost = 3.25 * grocery2Amt;
System.out.println("The total cost for Item 2 is €" + grocery2Cost);}
else if(grocery2.equalsIgnoreCase("turnips")){
grocery2Cost = 0.70 * grocery2Amt;
System.out.println("The total cost for Item 2 is €" + grocery2Cost);}
else if(grocery2.equalsIgnoreCase("carrots")){
grocery2Cost = 2.25 * grocery2Amt;
System.out.println("The total cost for Item 2 is €" + grocery2Cost);}
else{
System.out.print(" You have entered an Invalid Item ");}
Scanner grocery3Item = new Scanner (System.in);
String grocery3;
int grocery3Amt;
double grocery3Cost;
System.out.print("Please enter the third grocery item ");
grocery3 = grocery3Item.nextLine();
System.out.print("Please enter the amount ");
grocery3Amt = grocery3Item.nextInt();
if(grocery3.equalsIgnoreCase("apples")){
grocery3Cost = 0.30 * grocery3Amt;
System.out.println("The total cost for Item 3 is €" + grocery3Cost);}
else if(grocery3.equalsIgnoreCase("oranges")){
grocery3Cost = 0.45 * grocery3Amt;
System.out.println("The total cost for Item 3 is €" + grocery3Cost);}
else if(grocery3.equalsIgnoreCase("strawberries")){
grocery3Cost = 3.30 * grocery3Amt;
System.out.println("The total cost for Item 3 is €" + grocery3Cost);}
else if(grocery3.equalsIgnoreCase("potatoes")){
grocery3Cost = 3.35 * grocery3Amt;
System.out.println("The total cost for Item 3 is €" + grocery3Cost);}
else if(grocery3.equalsIgnoreCase("turnips")){
grocery3Cost = 0.70 * grocery3Amt;
System.out.println("The total cost for Item 3 is €" + grocery3Cost);}
else if(grocery3.equalsIgnoreCase("carrots")){
grocery3Cost = 3.35 * grocery3Amt;
System.out.println("The total cost for Item 3 is €" + grocery3Cost);}
else{
System.out.print(" You have entered an Invalid Item ");}
{
System.out.println("The total order cost is €" + grocery1Cost + grocery2Cost + grocery3Cost);}
}
}
Error: variable grocery1Cost might not have been initialized
Error: variable grocery2Cost might not have been initialized
Error: variable grocery3Cost might not have been initialized
Please help!!