Classes :: Problem Set

  1. Write the class Account which will instantiate the object user. Account will accept a deposit and keep the user’s balance. Account will also accept a withdrawal request from the user.Both withdrawal and deposit will come in the form of parameters. The withdraw method will only issue money to the user only the balance is greater than the withdrawal. Otherwise, the user will get 0 (if statement). Write the Account class in a separate file from the DemoAccount class.
  2. Create the class Average which will instantiate the object “student”. The class will accept 4 inputs representing the average of a student’s four courses. The class will return the average of the four courses. Write the class DemoAverage (main() )to test.
  3. Write a class that simulates the roll of a die. The die/roll is your object. Therefore, your class should instantiate an object that rolls a random number. The “face” of the roll (a number between 1 and 6) is the value of each roll. The following are guidelines (indeed a help) of how to write the Die class:
    1. If the name of the class is Die, therefore, what is the name of the constructor?
    2. Your constructor should initialize the object with a “roll”.
    3. The method that makes the die roll should only have one expression. The expression is: variableName = (int) (Math.random () * 6) + 1;
    4. Whatever the roll value is, it is NOT returned from this method.
  4. Then write the class DemoRoll. In this class you will include the main() method. The main() method should instantiate a Die object called “roll”. This object should be made “rolled” at least once. If you had no trouble with this, then make this object roll 10 times. Have fun!!

For answers click here