4100COMP: Introduction to Computer Programming

Added on - 20 Sep 2019

  • 4100COMP

    course code

  • 15

    pages

  • 4518

    words

  • 181

    views

  • 0

    downloads

Showing pages 1 to 4 of 15 pages
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 astudent 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 providecustomers 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 isdefined 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 tablenumber and the meal number for that particular meal. A particular meal can have up to 10orders (i.e. list of 10 table numbers)The Cancel a Meal option will allow a customer to cancel a meal that was orderedpreviously.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 byallowing 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 ofmeals, which can be used for the simulation.The first step to developing the application is working out what classes we need andwhat shape and form these classes will take. These things will be considered in moredetail in Problem Solving modules in semester 2, but for now we can perform a basicanalysis by applying the “Nous and Verbs” approach to the system description.Step 1We have repeated the system description text below and highlighted the main nounsand verbs in red and blue respectively. The idea is that the main Nouns will representthe “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.Arestaurantrequiresanautomated meal ordering system. Thesystemis intended toprovidecustomerswith atouchscreenat eachtable. The touchscreenwill provideamain menuwith 3options:-Displaymeals available-Orderameal-Cancela meal-QuitThe Display Meal option willdisplayalist of mealsthatcan be ordered. Each meal isdefinedby:- Anid number- Adescription of the meal- Avegetarian option(set as true if the ingredients are vegetarian)- avegan option(set as true if the ingredients are vegan)The Order a Meal option willallowa customer toorder a mealbyinputof theirtablenumberand themeal numberfor that particular meal. A particular meal can have up to 10orders (i.e.list of 10 table numbers)The Cancel a Meal option will allow a customer tocancel a mealthat was orderedpreviously.The Quit option will display agoodbye messageand the touchscreen willhibernate.Liverpool John Moores UniversityDepartment of Computer Science
4100COMP: Introduction to ProgrammingTutorial SolutionsYou are required toproduceanapplicationthatsimulatethe Meal Ordering Systems byallowing ausertoselectthe various menu options of displaying meals, ordering meals,cancelling orders and quitting. On startup your application will need toload a series ofmeals, which can be used for the simulation.The process takes a bit of getting used to as there are lots of unnecessary nouns andverbs that we don’t actually need. For example we don’t actually need restaurant, ortouchscreen, but we do need meal ordering system and meal. There is also a lot ofrepetition, so meal is repeated many times but we only need to consider oneoccurrence.After going through this process once or twice we can draw up an initial list which wecan then refine to something like below.Main Nouns----------1. Restaurant2. Automated Meal Ordering System3. Customer4. Main menu5. Meal6. Vegetarian Option7. Vegan Option8. Table Number9. List of Table NumbersMain Verb Phrases-----------------1. Provide a Main Menu2. Display a List of Meals3. 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
desklib-logo
You’re reading a preview
card-image

To View Complete Document

Become a Desklib Library Member.
Subscribe to our plans

Download This Document