Ask a question to Desklib · AI bot

Ask NowBETA

4100COMP: Introduction to Computer Programming

Added on -2019-09-20

| 4100COMP
| 15 pages
| 4518 words
| 489 views

Trusted by 2+ million users,
1000+ happy students everyday

4100COMP: Introduction toProgrammingTutorial17: Coursework2- Design andImplementation ExerciseLiverpool John Moores UniversityDepartment of Computer Science
4100COMP: Introduction to ProgrammingTutorial SolutionsIntroductionUp to the first coursework you have been writing Java programs that exist in a singleclass and just recently you have seen how Java’s strengths lie in the use of classes tobuild larger programs out of a series of individual classes, which at runtime createobjects which cooperate with one another. For this second coursework you arerequired to build a larger program, which consists of two or more classes, which willwork together to provide an effective solution to a problem. In the last week you have been using classes in lab sessions, but this has largely beenbased on a precise description of how you should create the class and define itsstructure, as shown in the example belowWrite a class to represent a student according to the specification below:Private members:int id – id number for the studentString name – name of the studentString course – programme of studyint [] marks – an array of size 5 to store 5 marks (0-100)Public methods:Student(int id, String name, String course, int [] marks) – constructor which creates a student according to the specified parametersint average() – calculates and returns the average mark for the student,void print() – prints student detailsWrite a main program to create 3 student objects as:1234 Joe Bloggs, Computer Studies, {67, 55, 78, 72, 50}2341 Sue White, Computer Science, {57, 85, 58, 49, 61}3412 Ben Black, Software Engineering, {71, 45, 66, 70, 51}For each student print the details and calculate the average.For this tutorial we will walk through an example to show you how you can build aprogram, based on two classes from a realistic system description. The classes will notbe quite as obvious as they were in the precise descriptions of the lab sessions, butwe will show you how to follow a systematic process to determine the classes andthen go on to develop a program based on these classes.You should apply these techniques when tackling coursework 2.Problem SpecificationThe description below describes the system that we will develop in this tutorial.A restaurant requires an automated meal ordering system. The system is intended to provide customers with a touchscreen at each table. The touchscreen will provide a main menu with 3options: - Display meals available - Order a meal - Cancel a mealLiverpool John Moores UniversityDepartment of Computer Science
4100COMP: Introduction to ProgrammingTutorial Solutions - QuitThe Display Meal option will display a list of meals that can be ordered. Each meal is defined by: - An id number - A description of the meal - A vegetarian option (set as true if the ingredients are vegetarian) - a vegan option (set as true if the ingredients are vegan)The Order a Meal option will allow a customer to order a meal by input of their table number and the meal number for that particular meal. A particular meal can have up to 10 orders (i.e. list of 10 table numbers) The Cancel a Meal option will allow a customer to cancel a meal that was ordered previously.The Quit option will display a goodbye message and the touchscreen will hibernate. You are required to produce an application that simulate the Meal Ordering Systems by allowing a user to select the various menu options of displaying meals, ordering meals, cancelling orders and quitting. On startup your application will need to load a series of meals, which can be used for the simulation. The first step to developing the application is working out what classes we need and what shape and form these classes will take. These things will be considered in more detail in Problem Solving modules in semester 2, but for now we can perform a basic analysis by applying the “Nous and Verbs” approach to the system description.Step 1 We have repeated the system description text below and highlighted the main nouns and verbs in red and blue respectively. The idea is that the main Nouns will represent the “things” or classes that make up our system and the main verbs will represent the“operations” or methods that we need to include within the classes. A restaurant requires an automated meal ordering system. The system is intended to provide customers with a touchscreen at each table. The touchscreen will provide a main menu with 3options: - Display meals available - Order a meal - Cancel a meal - QuitThe Display Meal option will display a list of meals that can be ordered. Each meal is defined by: - An id number - A description of the meal - A vegetarian option (set as true if the ingredients are vegetarian) - a vegan option (set as true if the ingredients are vegan)The Order a Meal option will allow a customer to order a meal by input of their table number and the meal number for that particular meal. A particular meal can have up to 10 orders (i.e. list of 10 table numbers) The Cancel a Meal option will allow a customer to cancel a meal that was ordered previously.The Quit option will display a goodbye message and the touchscreen will hibernate. Liverpool John Moores UniversityDepartment of Computer Science
4100COMP: Introduction to ProgrammingTutorial SolutionsYou are required to produce an application that simulate the Meal Ordering Systems by allowing a user to select the various menu options of displaying meals, ordering meals, cancelling orders and quitting. On startup your application will need to load a series of meals, which can be used for the simulation. The process takes a bit of getting used to as there are lots of unnecessary nouns and verbs that we don’t actually need. For example we don’t actually need restaurant, or touchscreen, but we do need meal ordering system and meal. There is also a lot of repetition, so meal is repeated many times but we only need to consider one occurrence.After going through this process once or twice we can draw up an initial list which we can then refine to something like below.Main Nouns----------1. Restaurant2. Automated Meal Ordering System3. Customer 4. Main menu 5. Meal6. Vegetarian Option7. Vegan Option8. Table Number9. List of Table NumbersMain Verb Phrases-----------------1. Provide a Main Menu2. Display a List of Meals 3. Order a Meal3. Cancel a Meal4. Load a Series of Meals5. Input a Meal Number6. Input Table Number7. QuitStep 2Liverpool John Moores UniversityDepartment of Computer Science

Found this document preview useful?

You are reading a preview
Upload your documents to download
or
Become a Desklib member to get accesss

Students who viewed this