| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1218 人关注过本帖
标题:(求助)请各位帮我看一下这道题
只看楼主 加入收藏
lyf3368
Rank: 1
等 级:新手上路
帖 子:26
专家分:0
注 册:2009-10-6
结帖率:25%
收藏
已结贴  问题点数:20 回复次数:9 
(求助)请各位帮我看一下这道题
我作业上最难的一题,我花了2个小时还是做不出来,请大家谁会的帮我一下,

(3) The Toy Class

A toy store company wants you to write a program to keep track of its
inventory. Define an object called Toy which maintains attributes
representing a toy's name (a string), manufacturer (a string),
minSuggestedAge (an integer), price (a float) and whether or not the
toy is on clearance (a boolean). Create a zero-argument constructor
and one that takes 5 parameters. Save and compile the file.

The program on the next page is called ToyTestProgram and it should
test your Toy class methods. However, the testing code is incomplete.
Please complete the testing code according to the directions given. Make
sure that your test code compiles, runs and produces the correct output.
Hand this test code in with your assignment.

class ToyTestProgram {
public static void main(String args[]) {
// Create three Toy objects. One should be a ball from the Little
// Tikes company which is rated for ages 1 and up. It should cost 99
// cents and not be on clearance. Another toy should be a Lego Mindstorms
// toy from the Lego company which is for ages 12 and up and is on clearance.
// The last toy should be a Barbie doll from Mattel and set for ages 5 and up
// and not on clearance.
Toy ball = ......
Toy lego = ......
Toy barbie = ......

System.out.println("Here is the Ball information:");
System.out.println(ball.name);
System.out.println(ball.manufacturer);
System.out.println(ball.minSuggestedAge);
System.out.println(ball.price);
System.out.println(ball.clearance);

System.out.println("\nHere is the Lego information:");
System.out.println(lego.name);
System.out.println(lego.manufacturer);
System.out.println(lego.minSuggestedAge);
System.out.println(lego.price);
System.out.println(lego.clearance);

System.out.println("\nHere is the Barbie information:");
System.out.println(barbie.name);
System.out.println(barbie.manufacturer);
System.out.println(barbie.minSuggestedAge);
System.out.println(barbie.price);
System.out.println(barbie.clearance);

// Write code to change the ball's name to "SuperBall" and its price
// to $1.99 and it should now be on clearance
...

System.out.println("\nHere is the Ball's new information:");
System.out.println(ball.name);
System.out.println(ball.manufacturer);
System.out.println(ball.minSuggestedAge);
System.out.println(ball.price);
System.out.println(ball.clearance);

// Complete the line below so that it shows the combined total
// of all toy prices
System.out.println("The total cost of all toys is $" + ....);

// Complete the code below so that it determines which toy has the largest
// minSuggestedAge and displays the result using a nice readable sentence such
// as "The ball has the largest minimum suggested age.". You will need to make
// use of the IF statement to compare the age limits.
...


// Complete the code below so that it displays "All Clearance" if all 3 toys
// are on clearance, "Mixed" if 1 or 2 toys are on clearance and "All Regular
// Price" if all three toys are not on clearance
...

}
}


(4) The FUN Stuff

You will now add code to use an additional object within the Toy class.
Follow the steps below.

1. Create a class called Company which maintains name (i.e., a String)
and history (i.e., a History object ... see next step) attributes.

2. Create a class called History which maintains founder (i.e., a String) and
yearFounded (i.e., an int) attributes.

3. Create a constructor in the History class that takes initial founder name and yearFounded
values, and sets them properly. Compile.

4. Create a constructor in the Company class that takes initial name, founder and yearFounded
values. This constructor should create a new History object, passing in the appropriate initial
values. Compile.

5. Copy your Toy.java file to a new file called Toy2.java.

6. Modify the Toy2 class so that the manufacturer is now a Company object instead of a String
object.

7. Copy your ToyTestProgram.java file to a new file called Toy2TestProgram.java.

8. Modify the Toy2TestProgram so that it makes use of the Company object constructor by making
any appropriate changes. The Little Tikes company was founded by Thomas G. Murdough Jr. in
1969, Lego was founded by Ole Kirk Christiansen in 1932 and Mattel was founded by Harold
Matson & Elliot Handler in 1945.

9. Make sure to modify the code so that instead of displaying the manufacturer, you are displaying
the name of the manufacturer.

10. Add code to the end of the test program that determines and displays the oldest of the three toy
manufacturers. Your code should work for any year founded value, not just the ones shown.
The output should be: Lego is the oldest toy manufacturer




[ 本帖最后由 lyf3368 于 2009-10-6 22:43 编辑 ]
搜索更多相关主题的帖子: company whether Create called store 
2009-10-06 22:36
gameohyes
Rank: 16Rank: 16Rank: 16Rank: 16
来 自:湖南
等 级:版主
威 望:53
帖 子:1275
专家分:3629
注 册:2009-3-5
收藏
得分:6 
看不懂,但google翻译了下.做了下,做的不好,别见怪.public class ToyTestProgram {
    class ball {
        String name;
 
        String manufacturer;
 
        int minSuggestedAge;
 
        double price;
 
        public ball() {
            name = "ball";  
            manufacturer = "Tikes";
            minSuggestedAge = 1;
            price = 99.0;
        }
    }
 
    class lego {
        String name;
 
        String manufacturer;
 
        int minSuggestedAge;
 
        double price;
 
        public lego() {
            name = "lego";
            manufacturer = "lego";
            minSuggestedAge = 12;
            price = 99.0;
        }
    }
 
    class barbie {
        String name;
 
        String manufacturer;
 
        int minSuggestedAge;
 
        double price;
 
        public barbie() {
            name = "barbie";
            manufacturer = "Mattel";
            minSuggestedAge = 5;
            price = 99.0;
        }
    }
    public static void main(String [] args){
        ToyTestProgram ttp=new ToyTestProgram();
        ToyTestProgram.ball ba= ttp.new ball();
        ToyTestProgram.lego lg= ttp.new lego();
        ToyTestProgram.barbie bb= ttp.new barbie();
        ba.name="spuerball";
        ba.price=1.99;
        System.out.println("The total cost of all toys is $" +(ba.price+lg.price+bb.price));
    }
}


C#超级群 74862681,欢迎大家的到来!
2009-10-08 21:45
lyf3368
Rank: 1
等 级:新手上路
帖 子:26
专家分:0
注 册:2009-10-6
收藏
得分:0 

非常感谢gameohyes, 我试一下看行不行
2009-10-08 22:19
lyf3368
Rank: 1
等 级:新手上路
帖 子:26
专家分:0
注 册:2009-10-6
收藏
得分:0 
希望 会JAVAD的朋友加我qq
452323960,一起研究一下编程
2009-10-08 22:21
flyingcloude
Rank: 10Rank: 10Rank: 10
等 级:青峰侠
威 望:6
帖 子:598
专家分:1512
注 册:2008-1-13
收藏
得分:6 
回复 4楼 lyf3368
哎,已经弃java投奔c/c++了

你能学会你想学会的任何东西,这不是你能不能学会的问题,而是你想不想学的问题
2009-10-08 22:23
gameohyes
Rank: 16Rank: 16Rank: 16Rank: 16
来 自:湖南
等 级:版主
威 望:53
帖 子:1275
专家分:3629
注 册:2009-3-5
收藏
得分:0 
还是支持java。感觉以后都是java的世界

C#超级群 74862681,欢迎大家的到来!
2009-10-08 23:01
ygp_sfec
Rank: 3Rank: 3
等 级:论坛游侠
威 望:2
帖 子:87
专家分:115
注 册:2009-9-8
收藏
得分:6 
唉,这道题其实很简单,关键是看清题意,看清题意就很简单,由于这道题要求编写好几个类的代码,所以这里就不提供了
2009-10-08 23:07
gameohyes
Rank: 16Rank: 16Rank: 16Rank: 16
来 自:湖南
等 级:版主
威 望:53
帖 子:1275
专家分:3629
注 册:2009-3-5
收藏
得分:0 
还有这个System.out.println(ball.clearance);
其中的clearance是什么意思,要实现一个什么样的功能

4) The FUN Stuff
这下面的代码你写了吗?

发来看下咯。

C#超级群 74862681,欢迎大家的到来!
2009-10-08 23:12
lyf3368
Rank: 1
等 级:新手上路
帖 子:26
专家分:0
注 册:2009-10-6
收藏
得分:0 
你的代码有点小毛病,我自己写好了一个,clearance 是清仓大减价德尔意思
2009-10-09 05:41
gameohyes
Rank: 16Rank: 16Rank: 16Rank: 16
来 自:湖南
等 级:版主
威 望:53
帖 子:1275
专家分:3629
注 册:2009-3-5
收藏
得分:0 
那是肯定的。我挤在一起写的。
给你提供个思路而已,没办法,英语看不懂。

C#超级群 74862681,欢迎大家的到来!
2009-10-09 17:49
快速回复:(求助)请各位帮我看一下这道题
数据加载中...
 
   



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

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