Jump to content

Recommended Posts

Posted

I'm in CS1 at my high school. In 10th grade right now and we just learned how to make multiple classes in a class. Please help me! We use Eclipse.

 

 


Your fruit stand has been amazingly successful! With the increased customer base, you have
decided to branch out and sell as many different varieties of apples, oranges, and bananas as
you can. Follow each of the following parts in turn...


Part 1

* You should have an Apple class; You will now extend this with 2 more classes: one for
oranges, and one for bananas. Each class will have the following...


* Data members for sweetness and size

* Both a default and non­default constructor

* 2 extra methods (of your design ­ have fun with it, but be appropriate)


Part 2

* To keep track of your new inventory, add 3 arrays to your FruitStand class...


i) apple_array, ii) orange_array, iii) banana_array


* These arrays should store Apples, Oranges, and Bananas, respectively
* Be sure to initialize the arrays in the FruitStand constructor.


Part 3

* Add a new method to the FruitStand class to display your entire stock of fruit.

* public void show_stock()

* The method should iterate through each array of fruit, displaying the contents of all 3
arrays.


* Be sure to call this new method in your Tester class


This what I have so far:

 

- My Apple Class -

 

 

public class Apple {



private double weight;


private String color;


private String flavor;


private String sweetness;


private String size;



public Apple()


{


weight = 0.2;


color = "red";


flavor = "delicious";


}



public Apple(double w, String c, String f)


{


weight = w;


color = c;


flavor = f;


}



public void eat()


{


weight = 0.001;


color = "brown";


flavor = "";


}



public double applesauce()


{


return weight / 3;


}



public double smash (int lbs)


{


return weight * lbs * 1000;


}

 

- My Banana Class -

 

 

public class Bananas {



private double weight;


private String color;


private String flavor;


private String sweetness;


private String size;



public Bananas ()


{


weight = 1.1;


color = "yellow";


flavor = "sweet";


}



public Bananas (int x, String y, String z)


{


weight = x;


color = y;


flavor = z;


}



public void eat()


{


weight = .03;


color = "white";


flavor = "Sweet";


}



public void Smoothie()


{


weight = 2;


color = "whitesh - yellow";


flavor = "delicious";


}

- My Orange Class -

ublic class Oranges {



private double weight;


private String color;


private String flavor;


private String sweetness;


private String size;



public Oranges()


{


weight = 0.8;


color = "orange";


flavor = "sour";


}



public Oranges (int a, String b, String c)


{


weight = a;


color = b;


flavor = c;


}



public double peel()


{


return weight - 0.2;



}



public double juice()


{


return weight / 3;


}



}

 

 

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.