| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1218 人关注过本帖
标题:(求助)请各位帮我看一下这道题
取消只看楼主 加入收藏
lyf3368
Rank: 1
等 级:新手上路
帖 子:26
专家分:0
注 册:2009-10-6
结帖率:25%
收藏
已结贴  问题点数:20 回复次数:3 
(求助)请各位帮我看一下这道题
我作业上最难的一题,我花了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
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
lyf3368
Rank: 1
等 级:新手上路
帖 子:26
专家分:0
注 册:2009-10-6
收藏
得分:0 
你的代码有点小毛病,我自己写好了一个,clearance 是清仓大减价德尔意思
2009-10-09 05:41
快速回复:(求助)请各位帮我看一下这道题
数据加载中...
 
   



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

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