Programming Assignment 2 (Due by 9
pm, Friday, September 12, 2008)
Goals of project: Practice with string manipulation, writing methods,
defining and instantiating classes
I: Practice with Strings - Pig Latin
Note: For this project, treat y as a consonant.
The Pig Latin rules are:
1. If a word begins with a consonant - such as "string" - divide the
word at the first vowel, swapping the front and back halves and append
"ay" to the word - "ingstray".
2. If the word begins with a vowel - such as "am" - append "yay" to the
word - "amyay".
3. If the word has no vowels (other than y) - such as "my" - append
"yay" to it - "myyay".
Your PigLatin class should allow an English sentence to be converted to
pig latin. Translate each word in the sentence to pig latin, preserving
punctuation symbols as they are in the original sentence. Your class
should contain the following methods:
translate(String) - this method translates its String parameter into
translateWord(String) - this method translates a single word into Pig
findFirstVowel(String) - this method returns the location of the first
vowel in its String parameter.
Of these methods, only the translate method needs to be public.
Your PigLatin class (main method) should prompt the user to enter an
sentence or phrase from the keyboard. It should then display the
sentence in Pig Latin.
Sample Run (the user's input is in
Please enter a sentence: Hello
Your sentence in Pig Latin: elloHay orldWay!
Submit your program in file PigLatin.java. Use an appropriate header as
indicated in the description of project 1. Make sure that you use
documentation to make your program readable.
II: Defining and instantiating your own classes - Bank Account
For this programming assignment, you will write two classes. First
write a class called BankAccount that represents a checking or savings
account at a bank. The class should have methods that allow:
Your BankAccount class should store the account balance and an account
number. Account numbers should begin with one; the first account
created will have account number 1, the second account created will
have account number 2, etc.
- Account creation (constructors) with either a default 0 balance,
or a specified balance which is passed in to the constructor
- Withdrawals, given a specified withdrawal amount - if the
withdrawal amount is greater than the account balance, do not carry out
the transaction, and charge the account an overdraw fee of $25. The
header for your method should be: public void withdraw(double amount).
- Deposits, given a deposit amount. Only allow non-negative deposit
amounts. The header for your method should be: public void
- Balance statement - return the current account balance. The
header for your method should be: public double getBalance()
- Another accessor method for the account number. This method
should have this header: public double getAccountNumber()
The second class that you write will be called AccountTest, and you
will use it to test your BankAccount class. This class should create
some BankAccount instances, and you will be graded on how adequately
you test the functionality of the BankAccount class.
Make sure that your files have the appropriate headers, and
documentation to make your program readable. Submit BankAccount.java
and AccountTest.java via turnin.