Class MealCard

java.lang.Object
  extended by MealCard

public class MealCard
extends java.lang.Object

A meal card is assigned to an individual student. When a meal card is initially issued, the balance is set to the number of points purchased. If the student does not specify the number of points, then the initial balance is set to 100 points. A student can purchase additional points at any time during the quarter. Points cost 25 cents each. Each time food items are bought, points are deducted from the balance. If the balance becomes negative, the purchase of food items is not allowed.


Field Summary
private  int balance
           
private static double DOLLARS_PER_POINT
           
private static int INIT_BALANCE
           
private  Student student
           
 
Constructor Summary
MealCard()
          Default constructor for objects of class MealCard
MealCard(Student std, int bal)
          Constructor for objects of class MealCard.
 
Method Summary
 boolean buyFood(double cost)
          User wishes to purchase cost worth of food.
 void buyPoints(double amt)
          User wishes to purchase amt worth of points.
 int getBalance()
          Accessor method to get the students current balance.
private  int points(double x)
          Convert dollar amount into points.
 void setStudent(java.lang.String fname, java.lang.String lname, int sid)
          Sets the student instance variable.
 java.lang.String toString()
          For printing MealCard objects.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

INIT_BALANCE

private static final int INIT_BALANCE
See Also:
Constant Field Values

DOLLARS_PER_POINT

private static final double DOLLARS_PER_POINT
See Also:
Constant Field Values

student

private Student student

balance

private int balance
Constructor Detail

MealCard

public MealCard()
Default constructor for objects of class MealCard


MealCard

public MealCard(Student std,
                int bal)
Constructor for objects of class MealCard. Initializes student and balance.

Method Detail

setStudent

public void setStudent(java.lang.String fname,
                       java.lang.String lname,
                       int sid)
Sets the student instance variable.

Parameters:
fname - the first name of the student
lname - the last name of the student
sid - the students 5 digit ID number

getBalance

public int getBalance()
Accessor method to get the students current balance.

Parameters:
-
Returns:
balance

points

private int points(double x)
Convert dollar amount into points.

Parameters:
x - a dollar amount
Returns:
the equivalent of x in points (round to nearest point)

buyPoints

public void buyPoints(double amt)
User wishes to purchase amt worth of points. Update his or her balance accordingly.

Parameters:
amt - a dollar amount

buyFood

public boolean buyFood(double cost)
User wishes to purchase cost worth of food. If the balance is sufficient to cover the cost of the food, update his or her balance accordingly and return true. If not, return false.

Parameters:
cost - a dollar amount
Returns:
true or false

toString

public java.lang.String toString()
For printing MealCard objects.

Overrides:
toString in class java.lang.Object
Parameters:
-
Returns:
a String representing the MealCard object