public String getStudentID()
{
return studentID;
}
In this lab, you will be working with a Flex class which represents the form of credit used by Trinity students to purchase food including meals and snacks at food service locations throughout the Trinity College campus. You will create a FlexDriver class to create instances of the Flex class and to manipulate the instances.
Pair Programming:
In this lab, we will be working with a Flex.java class. This class represents the form of credit used by Trinity students to purchase food including meals and snacks at food service locations throughout the Trinity College campus. The Flex class supports two distinct forms of credit. One is a set number of meals that may be purchased at Trinity dining halls. The second is called "meal flex" and it represents a dollar amount that may be used at any Trinity location to purchase meals or snacks. Meal flex provides flexibility in the meal plan, allowing students to purchase meals and snacks at the location of their choice.
Tuesday Lab
Wednesday Lab
Kristen Anderson Jeff Young
Chelsea Bainbridge-Donner Ryan Ersland
Jake Elder Nick Dragu
Catherine Doyle John Wilsterman
Jesse Vazquez Greg Vaughan
Corazon Irizarry Jin Feng Liu
The UML class diagram for the Flex class is shown below:
| Flex |
|---|
|
- studentID: String
- numberOfMeals: int - mealFlex: double |
|
+ setStudentID(n: String):void
+ setNumberOfMeals(meals: int):void + setMealFlex(c: double):void + buyMeal(): void + buySnack(double amt): void + addFlex(double amt): void + toString(): String |
Once you are familiar with the Flex class, create a FlexDriver class. Your FlexDriver class should contain only a main method which should do the following:
The first Flex: Student ID: 1234 Number of meals remaining: 121 Amount of meal flex remaining: 100.0 The second Flex: Student ID: 5678 Number of meals remaining: 200 Amount of meal flex remaining: 200.0 AFTER MODIFICATIONS: The first Flex: Student ID: 1234 Number of meals remaining: 121 Amount of meal flex remaining: 79.5 The second Flex: Student ID: 5678 Number of meals remaining: 199 Amount of meal flex remaining: 230.0Show the instructor your FlexDriver class before continuing to part 2.
The first Flex: Student ID: 1234 Number of meals remaining: 0 Amount of meal flex remaining: 10.0 The second Flex: Student ID: 5678 Number of meals remaining: 200 Amount of meal flex remaining: 200.0 There is an insufficient number of meals. Incorrect amount or insufficient funds. Cannot add negative funds. AFTER MODIFICATIONS: The first Flex: Student ID: 1234 Number of meals remaining: 0 Amount of meal flex remaining: 10.0 The second Flex: Student ID: 5678 Number of meals remaining: 200 Amount of meal flex remaining: 200.0Show the instructor your modified Flex and FlexDriver classes before continuing to part 3.
Note that the equals method calls several methods that have not yet been implemented on the Flex class: getStudentID, getNumberOfMeals and getMealFlex. Add these methods to your Flex class and uncomment the equals method.
Now test the equals method in the FlexDriver class by creating three Flex instances. Two of the instances should contain the same data while the third should contain different data. Print out the result of calling the equals method on each combination of Flex instances. The output should look something like:
The first Flex: Student ID: 1234 Number of meals remaining: 121 Amount of meal flex remaining: 100.0 The second Flex: Student ID: 5678 Number of meals remaining: 200 Amount of meal flex remaining: 200.0 The third Flex: Student ID: 1234 Number of meals remaining: 121 Amount of meal flex remaining: 100.0 The first and second flex are equal is: false The second and third flex are equal is: false The first and third flex are equal is: trueTest your code carefully to make sure that it operates correctly under a variety of test cases. Your code should have good programming style and follow all Java conventions. Don't forget to use constants where appropriate.