给一个Java编写的机票预定系统的示例代码
时间: 2023-03-13 11:07:00 浏览: 85
一个Java编写的机票预定系统的示例代码如下:public class TicketBookingSystem {
public static void main(String[] args) {
// Declare variables
double ticketPrice;
int noOfTickets;
double totalPrice; // Ask user to enter ticket price
System.out.println("Please enter the ticket price: ");
Scanner scanner = new Scanner(System.in);
ticketPrice = scanner.nextDouble(); // Ask user to enter number of tickets
System.out.println("Please enter number of tickets: ");
noOfTickets = scanner.nextInt(); // Calculate total price
totalPrice = ticketPrice * noOfTickets; // Print total price
System.out.println("Total Price: " + totalPrice);
}
}
阅读全文