(求助)请各位帮我看一下这道题
我作业上最难的一题,我花了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 编辑 ]