| CSCI A201/A597Problem Set Three Second Summer 2000 |
| 1. |
Write a program that asks for an initial balance amount. Create a
BankAccount object with that amount. Then ask for a deposit
amount and a withdrawal amount. Carry out the deposit and withdrawal, then
print the remaining balance.
|
| 2. |
Implement a class Employee. An employee has a name (a string) and
a salary (a double). Write a default constructor, a constructor with
two parameters (name and salary), and methods to return the name and salary. Write
a small program to test your class.
|
| 3. |
Implement a class Employee. An employee has a name (a string) and
a salary (a double). Write a default constructor, a constructor with
two parameters (name and salary), and methods to return the name and salary. Write
a small program to test your class.
Enhance the class by adding a method
that raises the employee's salary by a certain percentage. Sample usage:
|
| 4. |
Implement a class Car with the following properties. A car has a certain fuel
efficiency (measured in miles per gallon or liters per km -- pick one) and a certain amount
of fuel in the gas tank. The efficiency is specified in the constructor,and the initial fuel
level is 0. Supply a method drive that simulates driving the car for a certain
distance, reducing the fuel level in the gas tank, and methods getFuelLevel,
returning the current fuel level, and tank, to tank up. Sample usage:
Car myBeemer = new Car(29); // 29 miles per gallon myBeemer.tank(20); // tank 20 gallons myBeemer.drive(100); // drive 100 miles System.out.println(myBeemer.getFuelLevel()); // print fuel remaining |
| 5. |
Change the purse program Coins6 to ask the user to supply coins in a
different currency. For example, you can use the following collection of German coins:
What changes did you have to make? What changes would you have to make to thenew Coin(0.01, "Pfenig"); new Coin(0.1, "Groschen"); new Coin(1.0, "Mark"); Coins4
program to change the currency? Which is easier?
|
| 6. |
Add a method
to the Purse class that asks the user how many coins of that type
to add to the purse and that updates the coin count.
|
| 7. |
Implement a class Student. For the purpose of this
exercise, a student has a name and a total quiz score. Supply an
appropriate constructor and methods
To compute the latter, you also need to store the number of quizzes that the student took. |
| 8. |
Implement a class Product. A product has a name and a price, for example
Supply methods printProduct(), getPrice(), and
setPrice(). Write in a program that makes two products, prints
them, reduces their prices by $5.00, and then prints them again.
|
| 9. |
Implement a class Circle that has methods getArea() and
getCircumference(). In the constructor, supply the radius of the circle.
|
| 10. |
Implement a class BeerCan with methods
getSurfaceArea() and getVolume().
In the constructor, supply the height and radius of the can.
|