Confusion with variable types
the program should do the following
http://img402.imageshack.us/img402/5747/capture1okj.png
this is my code (The code if part of a while loop, this is only one part of it) and it's supposed to do what's on the picture. I have problems with the variables and finding ways to make it work.
Code:
while (option1 ==3) //if users picks option 3 the following codes will be executed
{
String empty; System.out.print(" "); //Program did not run so I created an empty variable
empty = keyboard.nextLine(); // for reasons I don't know it worked this way
String name2;
//creating scanner for input
System.out.println("Enter customer's name ");
name2 = keyboard.nextLine(); //name2 contains the name you want to match with the
// one on the text file.
//The file was created earlier in the program
//obtaining the desired product from customer
System.out.println("what product are you buying? \n1.Shoes \n2.T-Shirts \n3.Shorts \n4.Caps \n5.Jackets");
product = keyboard.nextInt(); //obtaining the customer's selection
int price = 1;
switch (product) {
case 1:
price = 50; break; //options depending of the customer's selection
case 2:
price = 30; break;
case 3:
price = 75; break;
case 4:
price = 15; break;
case 5:
price = 100; break;
default:
System.out.println("Wrong choice");
}
System.out.println("How many do you want?");
quantity = keyboard.nextInt(); //quantity purchased
tax = .0825; //8% of tax
total = (product*quantity*tax);
TOTAL = Totalt + product;
System.out.println(total);
System.out.println(TOTAL);
String cinfo = ("customerInfo.txt"); //assigning the name of the file to the variable cinfo
File file = new File(cinfo); //file is ready to display
Scanner inputFile = new Scanner(file);
String name3 = inputFile.nextLine(); // name3 contains the name in the fil
inputFile.close();
//compare name2 & name3
//if names are the same display the content of the file, otherwise error message
//use if-statements for this step
if (name2.equals(name3))
{
File file2 = new File(cinfo); //opening file
Scanner inputFile2 = new Scanner(file2);
while (inputFile.hasNext()) //loop to display all the lines in the text file
{
String alltext = inputFile.nextLine();
// displaying the content of the file
System.out.println(alltext);
}
}
else
{ System.out.println("Could not find name in the system ");
}
}
Help is appreciated. I know it's long. I'm sorry for that.