Assignment 5:
Due: 4/4/2011
Introduction to Programming Using Java is a free on-line textbook.
Read the chapter on Applets and GUIs, http://www.faqs.org/docs/javap/c6/index.html
You might find it helpful to take the quiz at the end of the chapter. (There is a link to the answers so you can grade yourself.) The programming exercises are worth trying. They also have sample solutions.
Other tutorials on Applets and GUIs: http://www.realapplets.com/tutorial/
and
http://jtf.acm.org/tutorial/GraphicalUserInterfaces.html
Assignment:
Creat an applet to calculate compound interest. Provide textboxes for the present value (PV), interest rate (i), and number of periods (n).
The equation is FV = PV(1+i)^n where Future Value (FV) is the amount the user will have at the end of the timespan. Provide a button to (re)caluclate the FV.
Note: The pow method of the Math class performs exponentiation.
Assignment 4:
EZ Pass project
Include constructors for each class, accessor and mutator methods as needed. Use this and super whenever possible to simplify the code.
Write a toString method in each class that prints out the name of the subclass using the getClass() method of class Object followed by the instance variables, each preceded by a description.
EZPassAccount
-
Create a class named EZPassAccount that can keep track of its account information, such as owner info, credit card, balance. Each account can have several tags associated with it. Each tag has a unique serial number that is scanned and belongs to a specific vehicle.
Note: there are different types of vehicles. You will probably need a Vehicle class (or set of related classes).
-
An account should be charged when one of its tagged vehicles passes a toll booth. Beware of insufficient funds!
-
The credit card information is stored for each account. The CreditCard class has the information about the card. Make sure a credit card number is valid using the Mod 10 check!
-
The system works with prepayments. Tolls are deducted from the balance. The owner should be able to make payments to increase the available balance.
TollBooth
- There are different types of toll booths:
- Bridge / Tunnel
- Expressway
-
At some toll booths, the toll is charged whenever the vehicle uses the bridge/tunnel and sometimes the toll is only collected in one direction.
-
Each toll booth has its toll price. The price can change depending on the
- type of vehicle bearing tag (truck is charged per axle)
- time of day (off peak hours can be cheaper)
- number of passengers (carpool special)
- All toll booths have common characteristics. They should inherit from a common base class. Should the base class be an interface or abstract since only specialized versions exist?
This system is not complete yet. Which features can you think of that we missed?
Construct a UML class diagram for your classes. Confused about how it should look? Look at this file.
Bonus: Think of an appropriate interface to create and implement it in more than one class.
Confused about how the EZ Pass works? Visit their website http://www.ezpass.com
Assignment 2: Submit by email
Due 2/16/11
Programming Exercise 5.31 - Mod 10 check:
Credit card numbers follow certain patterns. A credit card number must have between 13 and 16 digits. It must start with:
- 4 for Visa cards
- 5 for Master cards
- 37 for American Express cards
- 6 for Discover cards
In 1954, Hans Luhn of IBM proposed an algorithm for validating credit card numbers. The algorithm is useful to determine if a card number is entered correctly or if a credit card is scanned correctly by a scanner. Almost all credit card numbers are generated following this validity check, commonly known as the Luhn check or the Mod 10 check, which can be described as follows (for illustration, consider the card number 4388576018402625):
- Double every second digit from right to left. If doubling of a digit results in a two-digit number, add up the two digits to get a single-digit number.
2*2=4
2*2=4
4*2=8
1*2=2
6*2=12 (1+2=3)
5*2=10 (1+0=1)
8*2=16 (1+6=7)
4*2=8
- Now add all single-digit numbers from Step 1.
4+4+8+2+3+1+7+8=37
- Add all digits in the odd places from right to left in the card number.
5+6+0+8+0+7+8+3=37
- Sum the results from Setp 2 and Step 3.
37+37=74.
- If the result from Step 4 is divisible by 10, the card number is valid; otherwise, it is invalid. For example, the number 4388576018420625 is invalid, but the number 4388576018410707 is valid.
Write a program that begins with a credit card number as a long integer. Display whether the number is valid. Design your program to use the following methods:
/** Return true if the card number is valid */
public static boolean isValid(long number)
/** Extract a digit from the long*/
public static int separateDigit(long number, int position)
/* You can convert a long to a String and use String methods
OR
You can use modulus with division.*/
/** Get the result from Steps 1 and 2*/
public static int sumAndSquareOfEvenPlace(long number)
/** Return this number if it is a single digit, otherwise, return the sum of the two digits */
public static int getAsOneDigit(int number)
/** Return sum of odd place digits in number, Step 3 */
public static int sumOfOddPlace(long number)
Feel free to add any other methods that you deem necessary!