有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

java票价计算

使用以下私有变量创建一个类票证

int ticketid;
int price;
static int `availableTickets`;

在Ticket类中包括getter和setter方法。 可用门票应仅具有正值。不允许使用零值和负值。(应在相应的setter方法中检查此逻辑) 在Ticket类中编写以下方法:

public int calculateTicketCost(int no_of_tickets) 

-此方法应检查票据可用性,如果票据可用,则将no_of_ticketsavailable_Tickets减少,并将总金额计算为nooftickets*price,然后返回总金额。如果票证不可用,此方法应返回-1。 在main类中编写一个main方法来测试应用程序

样本输入和输出

Enter no of bookings:
2
Enter the available tickets:
25
Enter the ticket id:
123
Enter the price:
100
Enter the no of tickets:
5
Available tickets: 25
Total amount:500
Available ticket after booking:20
Enter the ticket id:
124
Enter the price:
100
Enter the no of tickets:
2
Available tickets: 20
Total amount:200
Available ticket after booking:18

共 (0) 个答案