Type your solution in the window below (no uploads). Write a…
Type your solution in the window below (no uploads). Write a class to represent an object called Toy. Every Toy has a price that can contain 2 decimal points, a name with arbitrary letters/numbers in it and a time that has no decimal places. Your instance variables should not be accessible to any class outside of the Toy class. The class should have a constructor that uses three parameters. Users can create a Toy using: Toy t = new Toy(“Riding car”, 50.99, 0); // order of arguments: name, price, time Allowed behaviors/methods that can be used include the following: System.out.print(t); // results in the following being printed: Name: Riding car, price: 50.99, time: 0 t.increaseTime(); // increases time by 1. If time is multiple of 3 after the increase happens, then it decrease the price by 5.00. However, the price should never drop below 5.00. System.out.print(t); //prints out: Name: Riding car, price: 50.99, time: 1 t.increaseTime(); t.increaseTime(); System.out.print(t); //prints out: Name: Riding car, price: 45.99, time: 3 The class shouldn’t have any mutator methods, however, it must have accessor methods for all instance variables. Note: Do not skip minor details like semi-colons, parenthesis, etc. Even though you are not allowed to use a compiler for this exam, your code should be as close to compiling as possible. It doesn’t need to be perfect, but it should be close.
Read Details