From Problem Descriptions to Classes
From the Description |
In Java… |
||||||||
1. What is the name of the class you are
creating: __BankAccount_____________
(ex. Rectangle) |
public class _ BankAccount
____________ { (ex. public class Rectangle) |
||||||||
2. What are the attributes (nouns)?
|
//instance variables (ex.private double myLength;) private
String myAccountNumber; private
double myBalance; |
||||||||
3. What are the initializers (how do you
create an object)?
|
//constructors (ex. public Rectangle(double length,
double width)) public BankAccount(String acctNum,
double balance) public BankAccount(String acctNum) |
4. What are the behaviors (verbs)?
|
//methods
(ex.//add amount to balance public double
perimeter()) public void withdraw(double amount) public void deposit(double amount) public double getBalance() |
||||||||||||||||||||
5. Write the java code filling in the
constructors & methods. |
|
||||||||||||||||||||
6. Write a main method to test our your code. |
public
static void main(String[] args) { (ex.
Rectangle rec = new Rectangle(5, 4);
System.out.println(rec.perimeter()); } |