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

Define a class called Person which has attributes called height , money , ticketCount and hasPass.

The money and height variables are floats representing the amount of money the person currently has and the person's height (in inches).

The ticketCount is an integer indicating the number of tickets the person
currently has and hasPass is a boolean indicating whether or not the
person has a pass to get on the rides (assume a person can have at most 1
pass).

Write a constructor & all necessary methods in the Person class so that the
following code produces the output as shown below:

class PersonTester {
    public static void main(String args[]) {
    Person mary;

    mary = new Person(4.9f, 20.00f);

    System.out.println(mary.height);
    System.out.println(mary.money);
    System.out.println(mary.ticketCount);
    System.out.println(mary.hasPass);
    System.out.println(mary); // Notice that the money is properly formatted

    mary.ticketCount = 3;
    System.out.println(mary);

    mary.useTickets(2); // You have to write this method
    System.out.println(mary);

    mary.hasPass = true;
    System.out.println(mary);
}
}

Here is the output that your program MUST produce:

4.9
20.0
0
false
4.9' person with $20.00 and 0 tickets
4.9' person with $20.00 and 3 tickets
4.9' person with $20.00 and 1 tickets
4.9' person with $20.00 and a pass


Make sure to test your class with the test code above BEFORE you continue.
搜索更多相关主题的帖子: Class Person The 
2009-10-21 09:04
lyf3368
Rank: 1
等 级:新手上路
帖 子:26
专家分:0
注 册:2009-10-6
收藏
得分:0 
以下是引用gameohyes在2009-10-21 10:36:03的发言:

package oop;
 
public class Person {
    float height;
 
    float money;
    int ticketCount;
 
    boolean hasPass;
 
    PersonTester mary;
 
    int count;
 
    public Person() {
        ...
谢谢啊,这个很好,但是我不明白那个count++起什么作用啊,我看不出来,可以解释一下吗
2009-10-21 13:52
快速回复:(求助)The Person Class
数据加载中...
 
   



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

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