An object of the class Timer is used to indicate when a certain amount of time (in seconds) has elapsed, after which it provides a “DING”. The required data field is remainingTime which is the number of seconds until the “DING”. When a Timer object is constructed, it is set with the desired number of seconds. When the timer “ticks”, it is one second closer to the “DING”. This is represented with the tick() method. The dingCheck() method indicates whether the timer should be “DINGING”.
Provide the code for the constructor method, and the methods getRemainingTime(), tick(), and dingCheck().
public class Timer
{ // Methods
// Data
private int remainingTime;
}
Trending nowThis is a popular solution!
Step by stepSolved in 2 steps
- Note: It`s python codingarrow_forwardAssume an Animal class defines a public eat method and a Dog class derived fromthe Animal class defines a different public eat method. And assume thedeclaration:Animal[] animals = {new Animal(), new Dog("Collie", "brown")};Indicate which eat method is invoked by each of the following statements, and explainwhy.animals[0].eat();animals[1].eat();arrow_forwardIt is a Java programarrow_forward
- Assume you have this strcut type struct My Struct{ public int x;} Assume a struct s1 is created from MyStrcut and s1.x is assgined to value 15. We call a method, that takes an arugment of type MyStruct and pass s1 as the argument. This method increments the variables x of its argumemt by the value of 4. After returning from the method, what will be the value of s1.x?arrow_forwardCreate a class Animal with a constructor that takes no parameters and has an instance variable: private int energy; When an animal is "born," it has one unit of energy. It has the methods: public void eat(int amountToEat) - which increases the amount of energy the animal has by amountToEat public void move(int amountToMove) - which decreases the energy the animal has by amountToMove. public int getEnergy() - which returns the amount of energy left Notice there is no setEnergy method. Energy is only changed by eating or moving. You should also create a subclass BetterAnimal which has a cap on the amount of energy an animal can have. The constructor takes a parameter that specifies a maximum for energy. You will need to save this in another instance variable. Override the eat and move methods In the eat method: If the amount the BetterAnimal eats would set its energy above the max, the energy level is only increased to the max. Also energy is only changed if the amount > 0 In…arrow_forwardcreate different java methods in making the code and have at least 2 or more classesarrow_forward
- An object of the class Timer is used to indicate when a certain amount of time (in seconds) has elapsed, after which it provides a “DING". The required data field is remainingTime which is the number of seconds until the “DING". When a Timer object is constructed, it is set with the desired number of seconds. When the timer "ticks", it is one second closer to the "DING". This is represented with the tick) method. The dingChecko method indicates whether the timer should be "DINGING". Provide the code for the constructor method, and the methods getRemainingTime), tick(), and dingCheck). public class Timer // Methods // Data private int KeuainingTinei }arrow_forwardWhat are the advantages of passing this data into a method as opposed to just passing it into the current class object?arrow_forwardThe goal of this coding exercise is to create two classes BookstoreBook and LibraryBook. Both classes have these attributes: author: Stringtiltle: Stringisbn : String- The BookstoreBook has an additional data member to store the price of the book, and whether the book is on sale or not. If a bookstore book is on sale, we need to add the reduction percentage (like 20% off...etc). For a LibraryBook, we add the call number (that tells you where the book is in the library) as a string. The call number is automatically generated by the following procedure:The call number is a string with the format xx.yyy.c, where xx is the floor number that is randomly assigned (our library has 99 floors), yyy are the first three letters of the author’s name (we assume that all names are at least three letters long), and c is the last character of the isbn.- In each of the classes, add the setters, the getters, at least three constructors (of your choosing) and override the toString method (see samplerun…arrow_forward
- Complete the Car class by creating an attribute purchase_price (type int) and the method print_info() that outputs the car's information. Ex: If the input is: 2011 18000 2018 where 2011 is the car's model year, 18000 is the purchase price, and 2018 is the current year, then print_info() outputs: Car's information: Model year: 2011 Purchase price: $18000 Current value: $5770 Note: print_info() should use two spaces for indentation.arrow_forwardWrite a class Die representing a single die. Your class should include: An instance variable for the number of sides on the die. A constructor that allows you to specify the number of sides on the die. This method shouldcheck that there are at least 2 sides; if not, it should default to having 6 sides. A toString method that returns a description of the die, including its number of sides. A roll method that randomly returns one of the numbers on the die. Each number should have an equal probabilityof being returned. Assume that the numbers on the die range from 1 to the number of sides. A testDie method that takes one parameter for the number of times to roll the die. This method should roll the diethat number of times, keeping track of the results. Once all rolls are complete, the method should display statisticson how many times each number appeared, and the corresponding percentage. Example: Die myD4 = new Die(4); myD4.testDie(100000);might result in something like: Results from…arrow_forward1- is invoked to create an object. A A constructor B. The main method C. A method with a return type D. A method with the void return type 2- Suppose you wish to provide a getter for a double member gpa, what signature of the methad should be used? A. public void getGPA() B. public double getGPA() C. public boolean 1SGPA() D public void isGPA() 3- Suppose you wish to provide an accessor method for a Boolean property finished, what signature of the method should be used? A public int getFimished() B. public boolean isFinished) C public void isFinished() D public void getFinished()arrow_forward
- Computer Networking: A Top-Down Approach (7th Edi...Computer EngineeringISBN:9780133594140Author:James Kurose, Keith RossPublisher:PEARSONComputer Organization and Design MIPS Edition, Fi...Computer EngineeringISBN:9780124077263Author:David A. Patterson, John L. HennessyPublisher:Elsevier ScienceNetwork+ Guide to Networks (MindTap Course List)Computer EngineeringISBN:9781337569330Author:Jill West, Tamara Dean, Jean AndrewsPublisher:Cengage Learning
- Concepts of Database ManagementComputer EngineeringISBN:9781337093422Author:Joy L. Starks, Philip J. Pratt, Mary Z. LastPublisher:Cengage LearningPrelude to ProgrammingComputer EngineeringISBN:9780133750423Author:VENIT, StewartPublisher:Pearson EducationSc Business Data Communications and Networking, T...Computer EngineeringISBN:9781119368830Author:FITZGERALDPublisher:WILEY