Create a constructor that initializes only first data member


Assignment: Java code

A) Create a class called Toy

1) Define at three private data members that makes sense for a class called Toy.

a) A string that is the name of the toy

b) You decide what this data member represents and what is the appropriate data type

c) A double representing the price of the toy

2) Create a Constructor that initializes only the first and second data members using arguments

a) Take the argument passed in for the name of the toy, make it uppercase using a String method, and assign it to the appropriate data member.

b) Initialize the second data member with the second argument

c) Create a random double in the range of [10.75, 20.5) and assign it the third data member representing the price of the toy. (Note, after formatting for output you can get 20.50.)

3) Write the one get method to retrieve the values of the third data member as type double.

4) Write one set method to set the value of the third data member, the price.

5) Write the toString method as described in class using example below. The price must be output in Currency using the FormatNumber class.

B) In main method

1) Create an instance of the Toy class passing two arguments as described above

2) Call the get method for the price to retrieve the current price.

3) Output the current price formatted for currency.

4) Increase the current price by 25%

5) Call the set method to update the price with the new value you calculated.

6) Call the toString method and output the String it returns for the instance variable

C) Example Output. follow the format for toString() as explained in chapter 3.

Price before increase: $8.7
Toy name: JUMP ROPE
Color: green sparkles
Price: $10.91

Format your assignment according to the following formatting requirements:

(1) The answer should be typed, double spaced, using Times New Roman font (size 12), with one-inch margins on all sides.

(2) The response also includes a cover page containing the title of the assignment, the student's name, the course title, and the date. The cover page is not included in the required page length.

(3) Also include a reference page. The Citations and references should follow APA format. The reference page is not included in the required page length.

Solution Preview :

Prepared by a verified Expert
JAVA Programming: Create a constructor that initializes only first data member
Reference No:- TGS03138333

Now Priced at $45 (50% Discount)

Recommended (91%)

Rated (4.3/5)