I've a system in which the user can select a discount for a seating system. However, I've run into an issue wherein my "else if" isn't displaying correctly if the user doesn't want to add a discount.
import java.io.FileReader;
import java.util.Scanner;
import java.io.FileNotFoundException;
public class Coursework2 {
public static void main(String[] args)
throws FileNotFoundException { {
Scanner reader = new Scanner(new FileReader("seats.txt"));
Scanner scan = new Scanner (System.in);
double defaultdiscount = 17.5, discount = 16.97;
boolean random = true;
while (random) {
System.out.println("Please enter your Surname:");
String name = scan.nextLine();
System.out.println("Good morning, Manager " + name + " Would you like to apply a specific discount rate?");
String decision = scan.nextLine();
if (decision.equalsIgnoreCase("yes") || decision.equalsIgnoreCase("y")) {
System.out.println("That's great, Mananger " + name + ".");
System.out.println("How much discount would you like? (1-100)");
break;
} else if (decision.equalsIgnoreCase("no") || decision.equalsIgnoreCase("n")) {
System.out.println("Alright, " + name + " Here's all the seats without discounts:");
break;
}
System.out.println("Invalid Input, please try again. Restarting.");
}
discount = scan.nextDouble();
defaultdiscount = discount;
while (reader.hasNext()) {
String table = reader.next();
double price = reader.nextDouble();
int bookings = reader.nextInt();
double newdiscount = (((price/100.00*discount)*bookings));
double newincome = (price*bookings-(((price/100.00*discount)*bookings)));
System.out.printf("Seat type: %s, Price: £%.2f, Bookings: %d %n",table, price, bookings );
System.out.printf("Discount: £%.2f, Income: £%.2f %n", newdiscount, newincome);
do {
System.out.printf("Seat type: %s, Price: £%.2f, Bookings: %d %n",table, price, bookings );
}
while (decision == "No");
}
reader.close();
scan.close();
}
}
}
I understand that the code runs sequentially, but when it comes to trying to run the read files through the else if (No), it can't go above the while reader or inside the else if or it won't see the info from the text file, and when outside, it can't see the variables. I'm just a bit confused. It feels like something might be in the wrong place and I can't wrap my head around it.
Aucun commentaire:
Enregistrer un commentaire