Write class called Person that implements IPerson. Define a protected field named money of type int. Implement
Question:
Write class called Person that implements IPerson. Define a protected field named money of type int. Implement the payMoney method as follows. Given input integer toPay, your method should decrease money by toPay and return the new value of money. Add a default constructor that sets money to 10000 (10000 = $100.00). Write getter for money named getMoney.
Exercise 3
Write a class called Employee that extends Person. Define a private integer field called employeeID. Write constructor that accepts as input an integer called employeeID. Your constructor should call Person's constructor
so that money is still initialized (hint: super). Set the field employeeID to the parameter employeeID (hint: this). Override the payMoney method. Remember to use the @Override annotation. Employees only pay half. Before subtracting the amount to pay from money, divide toPay by 2, rounding down. For example, if I have 500 and am asked to pay 21, I will only pay 10 because I am an employee, making my new total 490). Hint: The Math class has a method that can help with rounding. Implement a static method addMoney(I Person person, int amount). This method should add amount to the money of the given person. Write a getter for employeeID named getEmployeeID
Java An Introduction To Problem Solving And Programming
ISBN: 9780134462035
8th Edition
Authors: Walter Savitch