当前位置: 代码迷 >> Java相关 >> (求助)请各位帮我看一下这道题
  详细解决方案

(求助)请各位帮我看一下这道题

热度:310   发布时间:2009-10-06 22:36:19.0
(求助)请各位帮我看一下这道题
我作业上最难的一题,我花了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  

----------------解决方案--------------------------------------------------------
看不懂,但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));
    }
}


----------------解决方案--------------------------------------------------------

非常感谢gameohyes, 我试一下看行不行
----------------解决方案--------------------------------------------------------
希望 会JAVAD的朋友加我qq
452323960,一起研究一下编程
----------------解决方案--------------------------------------------------------
回复 4楼 lyf3368
哎,已经弃java投奔c/c++了
----------------解决方案--------------------------------------------------------
还是支持java。感觉以后都是java的世界
----------------解决方案--------------------------------------------------------
唉,这道题其实很简单,关键是看清题意,看清题意就很简单,由于这道题要求编写好几个类的代码,所以这里就不提供了
----------------解决方案--------------------------------------------------------
还有这个System.out.println(ball.clearance);
其中的clearance是什么意思,要实现一个什么样的功能

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

发来看下咯。

----------------解决方案--------------------------------------------------------
你的代码有点小毛病,我自己写好了一个,clearance 是清仓大减价德尔意思
----------------解决方案--------------------------------------------------------
那是肯定的。我挤在一起写的。
给你提供个思路而已,没办法,英语看不懂。
----------------解决方案--------------------------------------------------------
  相关解决方案