私はクラス割り当てのための映画チケットプログラムを作成しています。JAVA:クラスの映画チケットプログラムを修正するのに役立つ必要があります
私は夜のチケット対マチネのための別の計算式を使用するようにプログラムに指示する方法がわからないので、ユーザが望んでいるのチケットの総コストを計算するつもりだ方法を見つけ出すことはできませんか?
映画の評価がRの場合、ユーザーが子供用のチケットを購入できないようにする方法も見つけ出す必要がありますか?私のコードは以下の通りです
...
/**
* @param args
*/
public static void main(String[] args)
{
//initializes variables for the various costs of each ticket
double adultMatCost = 7.50;
double adultEveCost = 9.50;
double childMatCost = 7.00;
double childEveCost = 7.00;
double seniorMatCost = 5.00;
double seniorEveCost = 7.00;
//introduces the user to the program, creates scanner for program,
//and asks user to enter their name
Scanner scan = new Scanner(System.in);
System.out.println("Welcome to the J-Town Theater.");
System.out.print("Please enter a name for our transaction records:");
String name = scan.next();
//thanks user and asks user which movie they would like to choose
//assigns a String movie is assigned text based on what the user chose
//if user enters a value other than 1 or 2 the program terminates gracefully
System.out.println("Thank you, " + name);
System.out.println("Which movie would you like to see?");
System.out.println("[1] My Little Pony (PG)");
System.out.println("[2] Blade Runner 2049 (R)");
System.out.print("Enter movie choice: ");
int movieChoice = scan.nextInt();
String movie = "";
if (movieChoice == 1){
movie = ("My Little Pony");
}
else if (movieChoice == 2){
movie = ("Blade Runner 2049");
}
else{
System.out.println("I'm sorry, " + name + ", but that is an invalid choice");
System.out.println("Goodbye.");
return;
}
//asks user what time they want to see the movie
//user enters M/m for Matinee and E/e for evening
//if user enters something besides M/m/E/e the program terminates gracefully
System.out.println("What time of day would you like?");
System.out.println("[M] Matinee");
System.out.println("[E] Evening");
System.out.print("Enter movie time:");
String timeDay = scan.next();
double totalCost = 0;
String timeDayResult = "";
double timeDayME = 0;
if (timeDay.equals("m")){
timeDayResult = ("Matinee showing");
}
else if (timeDay.equals("M")){
timeDayResult = ("Matinee showing");
}
else if (timeDay.equals("e")){
timeDayResult = ("Evening showing");
}
else if (timeDay.equals("E")){
timeDayResult = ("Evening showing");
}
else{
System.out.println("I'm sorry, " + name + ", but that is an invalid choice.");
System.out.println("Goodbye.");
return;
}
//asks how many tickets they would like and shows the price for each ticket
//user enters number between 0 and 10 if they enter something besides that
//the program will terminate gracefully
//if the movie chosen was rated R no tickets can be sold to children
System.out.println("How many tickets would you like?");
System.out.println("Child : $7.00");
System.out.println("Adult : $7.50");
System.out.println("Senior: $5.00");
System.out.print("Enter number of children (0-10):");
int ticketsChild = scan.nextInt();
if (ticketsChild >= 0){
int ticketsChildTotal = ticketsChild;
}
if (ticketsChild <= 10){
int ticketsChildTotal = ticketsChild;
}
else{
System.out.println("I'm sorry, " + name + ", but that is an invalid choice.");
System.out.println("Goodbye.");
return;
}
System.out.print("Enter number of adults (0-10):");
int ticketsAdult = scan.nextInt();
if (ticketsAdult >= 0){
int ticketsAdultTotal = ticketsAdult;
}
if (ticketsAdult <= 10){
int ticketsAdultTotal = ticketsAdult;
}
else{
System.out.println("I'm sorry, " + name + ", but that is an invalid choice.");
System.out.println("Goodbye.");
return;
}
System.out.print("Enter number of seniors (0-10):");
int ticketsSenior = scan.nextInt();
if (ticketsSenior >= 0){
int ticketsSeniorTotal = ticketsSenior;
}
if (ticketsSenior <= 10){
int ticketsSeniorTotal = ticketsSenior;
}
else{
System.out.println("I'm sorry, " + name + ", but that is an invalid choice.");
System.out.println("Goodbye.");
return;
}
//gives a transaction summary for the user showing what movie they want,
//what time they want, and how many tickets they want total,
//then the program calculates the total ticket price
System.out.println("Thank you, Penolope, here is a record of your purchase.");
int totalTickets = ticketsSenior + ticketsAdult + ticketsChild;
System.out.println(movie + " (" + timeDayResult + "): " + totalTickets + " tickets total");
System.out.println("Children: " + ticketsChild);
System.out.println("Adults: " + ticketsAdult);
System.out.println("Seniors: " + ticketsSenior);
double totalMatineeCost = (childMatCost * ticketsChild) + (adultMatCost * ticketsAdult) + (seniorMatCost + ticketsSenior);
double totalEveningCost = (childMatCost * ticketsChild) + (adultMatCost * ticketsAdult) + (seniorMatCost + ticketsSenior);
System.out.println("Total cost: $" + totalCost);
}
}
私はこのコードで実行されたデバッグの証拠がないので、この質問をdownvotedしました。あなたの質問を編集して、あなたのデバッグが明らかにしたことと、実際のコード行についての特定の質問を表示してください。参照:[最小限で完全で検証可能な例の作成方法](http://stackoverflow.com/help/mcve)と[小規模プログラムのデバッグ方法](https://ericlippert.com/2014/03/05)/how-to-debug-small-programs /)を実行します。 –