| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 602 人关注过本帖
标题:(求助)可以帮我看看这个吗
只看楼主 加入收藏
lyf3368
Rank: 1
等 级:新手上路
帖 子:26
专家分:0
注 册:2009-10-6
结帖率:25%
收藏
已结贴  问题点数:20 回复次数:3 
(求助)可以帮我看看这个吗
The TicketBooth Class

Define a class called TicketBooth that defines the following attributes:

• moneyMade - a float indicating the amount of money received by
this booth so far

• availablePasses - an int indicating the number of passes that are
available at this booth

• availableTickets - an int indicating the number of tickets that are
available at this booth

Make the following two class constants:

• TICKET_PRICE - the price for each individual ticket ... set it to be $0.50.
• PASS_PRICE - the price for a ride pass ... set it to be $16.50.

Write a zero-parameter constructor as well as one that takes an initial # of passes that the booth has available. Also, write a constructor that takes an initial number of passes that the booth has available as well as the number of tickets that it has available. So … you will write 3 constructors altogether.
Lastly, write a toString() method that returns a string with the following format:

Ticket booth with 5 passes and 28 tickets

Making use of the two class constants above whenever possible, write these 2 methods:

 • a sellPass()
() method that simulates the selling of a ride pass at this booth (Hint: Think of what happens in real life and then determine how the TicketBooth object changes as a result of this method. Make sure to handle the situation where there are no passes available).



• a sellTickets(int num) method that simulates the selling of the specified number of tickets at this booth. If there are not enough tickets to accommodate the requested amount then nothing happens, no selling takes place. (Hint: Think the same way as you did above).

Write a test program called TicketBoothTestProgram.java that creates two ticket booths ... the 1st one with 5 passes and 50 tickets available and the 2nd one with 1 pass and 10 tickets available. Your code should use the toString() method to display both of the booths to the console. Your program should then sell 2 passes from one of the booths and then simulate the situation in which that booth sells 5 tickets to someone, then "attempts to" sell 12 tickets to someone else and finally attempts to sell 3 more tickets one last time. For the other booth, repeat the process of attempting to sell 2 passes, followed by 5 tickets, 12 tickets and 3 tickets. Display the amount of money made from each of the booths at the end of your program and confirm that the values are correct. Also, re-display (using toString() the two booths to ensure that the number of tickets and passes remaining is correct).
Adjust your code so that it produces the following output exactly:

Here are the booths at the start:
Ticket booth with 5 passes and 50 tickets
Ticket booth with 1 passes and 10 tickets
Booth 1 has made $43.0
Booth 2 has made $20.5
Here are the booths at the end:
Ticket booth with 3 passes and 30 tickets
Ticket booth with 0 passes and 2 tickets
搜索更多相关主题的帖子: following received number amount called 
2009-10-21 09:00
lampeter123
Rank: 16Rank: 16Rank: 16Rank: 16
等 级:版主
威 望:54
帖 子:2508
专家分:6424
注 册:2009-1-30
收藏
得分:10 
class TicketBooth
{
  float moneyMade;  
  int availablePasses;
  int availableTickets;

  final float TICKET_PRICE = 0.50;   //常量
  final float PASS_PRICE = 16.50;    //常量

  public TicketBooth()  //无参构造函数
  {

  }

  public void sellPass()
  {
     //具体方法留给你自己写
  }

  public void sellTickets(int num)  
  {
    //具体方法留给你自己写
  }

  public void toString()  //重写toString()方法
  {
 
  }
}

[ 本帖最后由 lampeter123 于 2009-10-21 09:29 编辑 ]

你的优秀和我的人生无关!!!!
    
    我要过的,是属于我自己的生活~~~
2009-10-21 09:17
lyf3368
Rank: 1
等 级:新手上路
帖 子:26
专家分:0
注 册:2009-10-6
收藏
得分:0 
为什么你们写方法前面都加public我们都不用的除了 toString 方法外
2009-10-22 00:38
dadongzicool
Rank: 6Rank: 6
等 级:贵宾
威 望:11
帖 子:209
专家分:474
注 册:2009-3-20
收藏
得分:10 
习惯问题吧  不加public默认是public

本人出售软件专业毕业设计(包括论文,代码)题目众多,价格从优联系方式:QQ
1635008514(寻找高校代理)
2009-10-22 15:44
快速回复:(求助)可以帮我看看这个吗
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.051344 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved