Question: Hi could you solve these using Java? 2. Create a storage class named Card. A Card class has fields that store a value (1-10), a

 Hi could you solve these using Java? 2. Create a storage

Hi could you solve these using Java?

2. Create a storage class named Card. A Card class has fields that store a value (1-10), a string for the full card name (e.g Ace of Spades), and a string to hold an image file name (e.g. spades_ace.png). Create methods to get and set each of the fields. Create a method named setCard that accepts a number between 1 and 52 and sets the 3 internal attributes with the proper value, card name, and file name (use a switch). Overload the setCard method to take a String as a second parameter. If the second parameter is "H" or "h", the value of the ace should be 11 instead of 1. Create a display function to show the class's current state. Create an application named TestCard and test all methods you created for your Card class. 3a. Create a storage class named Candy. A Candy class has fields that store values for color, length, and price. Create methods to get and set ONLY color and length (in cm). When the length is added, the price of the candy will be calculated based on a rate of $0.75/cm. Create a default constructor to default the color to "black", the length to 2, and the price to 1.50. Create a secondary constructor to initialize the object with a color and length set when instantiated (price is to be calculated). Create a display function to show the class's current state. Create a subclass named BonBons that has extra attributes for type (like chocolate or gumdrop) and calories (e.g. 250). Create accessors and mutators for your new fields. Override your display method to show all 5 attributes. Override your mutator for the length attribute to calculate the price based on a rate of $2.50/cm. Create a default constructor and a constructor where all 5 values are set when the class is instantiated (using the super method(s) as appropriate). Create an application named TestBonCandy to test your Candy and BonBon classes (test all methods)

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!