Copy_of_Classes_-_5_Classes_w__Additional_Methods_1
Copy_of_Classes_-_5_Classes_w__Additional_Methods_1
Class 1 - Rectangle.java:
Write a default constructor and another initializer constructor that takes 2 parameters:
● public Rectangle( )
● public Rectangle( int len, int wid )
Write the toString method that returns a string that is formatted like this:
Length: 13
Width: 7
Computer Science II K
Classes - 5 Classes w/ Additional Methods
Class 2 - Cat.java:
Write a default constructor and 2 other initializer constructors that take 2 parameters:
● public Cat( )
● public Cat( int a, String c )
● public Cat( String c, int a )
Write the toString method that returns a string that is formatted like this:
This is a brown cat that is 7 years old.
Computer Science II K
Classes - 5 Classes w/ Additional Methods
Class 3 - Monster.java:
Create a file named Monster.java
Write the Monster class.
It should have 3 instance variables:
● String name
● String type
● int age
Write the toString method that returns a string that is formatted like this:
My name is Lenny, I am a vampire and am 212 years old.
Computer Science II K
Classes - 5 Classes w/ Additional Methods
Class 4 - Car.java:
Create a file named Car.java
Write the Car class.
It should have 4 instance variables:
● String make
● String model
● int year
● double cost
Write the accessor for all instance variables and a mutator method for only the cost.
Write the toString method that returns a string that is formatted like this:
2014 Ford Mustang - $26450.85
Computer Science II K
Classes - 5 Classes w/ Additional Methods
Class 5 - BankAccount.java:
Create a file named BankAccount.java
Write the BankAccount class.
It should have 3 instance variables:
● final int ACCOUNT_NUMBER ← final variables can only be assigned one time.
● int pin
● double balance
Write an initializer constructor that takes a 4 digit PIN, assigns a random account number that is
between 100000 - 999999 and starts off with $0.
Write the accessor methods to get the balance and the account number.
● double getBalance( )
● int getAccountNumber( ) ← This should only return the last 3 digits of the account number, because of privacy concerns!!
Write the toString method that returns a string that is formatted like this:
Account #: 123456 (Balance: $212.13)
Computer Science II K