King Abdulaziz University Faculty of Computing and Information Technology Computer Science Department

Similar documents
King Abdulaziz University Faculty of Computing and Information Technology Computer Science Department

King Abdulaziz University Faculty of Computing and Information Technology Computer Science Department

King Abdulaziz University Faculty of Computing and Information Technology Computer Science Department

King Abdulaziz University Faculty of Computing and Information Technology Computer Science Department

King Abdulaziz University Faculty of Computing and Information Technology Computer Science Department

King Abdulaziz University Faculty of Computing and Information Technology Computer Science Department

King Abdulaziz University Faculty of Computing and Information Technology Computer Science Department

Project#1: Grade Book

Homework Assignment #3

Programming Assignment #2

Final Exam Practice. Partial credit will be awarded.

CMPSC 111 Introduction to Computer Science I Fall 2016 Lab 8 Assigned: October 26, 2016 Due: November 2, 2016 by 2:30pm

CSCI 1301: Introduction to Computing and Programming

H212 Introduction to Software Systems Honors

9/19/2018 Programming Data Structures. Polymorphism And Abstract

EE 422C HW 6 Multithreaded Programming

CS 116. Lab Assignment # 1 1

This exam is open book. Each question is worth 3 points.

Note: This is a miniassignment and the grading is automated. If you do not submit it correctly, you will receive at most half credit.

Assignment3 CS206 Intro to Data Structures Fall Part 1 (50 pts) due: October 13, :59pm Part 2 (150 pts) due: October 20, :59pm

CSCI315 Database Design and Implementation Singapore Assignment 2 11 January 2018

Object Oriented Programming (II)

Assessment details for All students Assessment item 1

Object-Oriented Programming in Java. Topic : Objects and Classes (cont) Object Oriented Design

Data Structures. Data structures. Data structures. What is a data structure? Simple answer: a collection of data equipped with some operations.

CS 2210a Data Structures and Algorithms Assignment 5 Solving a Labyrinth Due Date: December 6, 11:59 pm Total marks: 20

CSCI 1301: Introduction to Computing and Programming Spring 2019 Lab 10 Classes and Methods

Object-Oriented Programming (OOP) Basics. CSCI 161 Introduction to Programming I

Fall CS 101: Test 2 Name UVA ID. Grading. Page 1 / 4. Page3 / 20. Page 4 / 13. Page 5 / 10. Page 6 / 26. Page 7 / 17.

CPSC 233: Assignment 4 (Due March 26 at 4 PM)

Note: This is a miniassignment and the grading is automated. If you do not submit it correctly, you will receive at most half credit.

Software and Programming 1

Programming Assignment 2 ( 100 Points )

CMSC 201 Fall 2016 Homework 6 Functions

CS1004: Intro to CS in Java, Spring 2005

Part 1: Group Brainstorm (NO computers during this time) Part 2: Submit Individual Brainstorm (You can now use a computer)

Tips from the experts: How to waste a lot of time on this assignment

Assignments 3 & 4. COMP248/Winter Assignment 3 & 4 Page 1 of 7

CS 2704 Project 3 Spring 2000

CS1083 Week 2: Arrays, ArrayList

CS2 Practical 1 CS2A 22/09/2004

CS161: Introduction to Computer Science Homework Assignment 10 Due: Monday 11/28 by 11:59pm

************ THIS PROGRAM IS NOT ELIGIBLE FOR LATE SUBMISSION. ALL SUBMISSIONS MUST BE RECEIVED BY THE DUE DATE/TIME INDICATED ABOVE HERE

Tips from the experts: How to waste a lot of time on this assignment

Claremont McKenna College Computer Science

CSCI 1301: Introduction to Computing and Programming Summer 2018 Lab 07 Classes and Methods

Programming Assignment 2

Announcements for the Class

Software and Programming 1

CS 134 Programming Exercise 9:

Tips from the experts: How to waste a lot of time on this assignment

COMP 250 Winter 2011 Reading: Java background January 5, 2011

Concur Getting Started QuickStart Guide. Concur Technologies Version 1.2

CS 200, Section 1, Programming I, Fall 2017 College of Arts & Sciences Syllabus

Concur Getting Started QuickStart Guide. Concur Technologies Version 1.3

CS2 Practical 2 CS2Ah

EECS168 Exam 3 Review

Regis University CC&IS CS362 Data Structures

Lecture 13 & 14. Single Dimensional Arrays. Dr. Martin O Connor CA166

Note: This is a miniassignment and the grading is automated. If you do not submit it correctly, you will receive at most half credit.

CIT 590 Homework 6 Fractions

Project 1. Java Control Structures 1/17/2014. Project 1 and Java Intro. Project 1 (2) To familiarize with

COMP 401 Midterm. Tuesday, Oct 18, pm-3:15pm. Instructions

Chapter 6 Lab Classes and Objects

(a) Write the signature (visibility, name, parameters, types) of the method(s) required

Computer Engineering Department COM 102 OBJECT ORIENTED PROGRAMMING POSTLAB #5

Booking vacation packages (general)

Binghamton University. CS-140 Fall Problem Solving. Creating a class from scratch

CSE115 Lab 4 Fall 2016

Arrays. Eng. Mohammed Abdualal

CSE 131 Introduction to Computer Science Fall Exam II

CS 101 Fall 2006 Midterm 3 Name: ID:

Programming Languages and Techniques (CIS120)

Our second exam is Monday, April 3. Note that it will not be possible to get all the homework submissions graded before the exam.

Important Project Dates

Assignment 5: MyString COP3330 Fall 2017

CS2110 Assignment 2 Lists, Induction, Recursion and Parsing, Summer

Faculty of Science COMP-202B - Introduction to Computing I (Winter 2009) Midterm Examination

Assignment 3: Distance COP3330 Fall 2017

CT 229 Fundamentals of Java Syntax

Welcome to CompSci 201

CS 463 Project 1 Imperative/OOP Fractals

Introduction to Programming COIT 20245

a) Answer all questions. b) Write your answers in the space provided. c) Show all calculations where applicable.

Australian Informatics Olympiad Thursday 23 August, Information Booklet

Recommended Group Brainstorm (NO computers during this time)

Due: 9 February 2017 at 1159pm (2359, Pacific Standard Time)

EECE.2160: ECE Application Programming

AL GHURAIR UNIVERSITY College of Computing. Objectives: Examples: if Single-Selection Statement CSC 209 JAVA I. week 3- Control Statements: Part I

CS61BL: Data Structures & Programming Methodology Summer Project 1: Dots!

Regis University CC&IS CS310 Data Structures Programming Assignment 2: Arrays and ArrayLists

This project is worth 600 points Due on April 17 Pick one from the following project to create complete running program with documentation

Name: Checked: Access the Java API at the link above. Why is it abbreviated to Java SE (what does the SE stand for)?

Encapsulation. Administrative Stuff. September 12, Writing Classes. Quick review of last lecture. Classes. Classes and Objects

Computer Based Testing (CBT) Information

Extegrity Exam4 Take Home Exam Guide

Assignment 1 due Monday at 11:59pm

CONCORDIA UNIVERSITY Summer 2005 Comp 248 /1 Section AA Introduction to Programming Final Examination/A

Computer Science E-119 Fall Problem Set 1. Due before lecture on Wednesday, September 26

CS/ENGRD 2110 SPRING Lecture 4: The class hierarchy; static components

Transcription:

King Abdulaziz University Faculty of Computing and Information Technology Computer Science Department CPCS203, 1 st Term 2013 Program 2: KAU Air Booking System (Objects & Classes) Assigned: Wednesday, October 17 th, 2012 Due: 1:00PM on Monday, November 4 th, 2012 Read Carefully: The deadline for this project is 1:00 PM on Monday November 4 th, 2012. WARNING: This is an individual project; you must solve it by yourself. Any form of plagiarism will result in receiving zero in the project. WARNING: Late submission will not be accepted. Any project submitted after the cutoff time will receive zero. This project has to be submitted online via Email to: Cpcs.203@hotmail.com The subject line of your email message should be as the following form: SectionNumber_StudentID_ProjectNumber Example: EA_ 1110348_ P1 The source file(s) of your program should be zipped up. You must name the zip file using the following naming convention: SectionNumber_StudentID_ProjectNumber.zip Example: EA_ 1110348_ P1.zip You will be given 10 minutes to demonstrate your project. Questions asked will be related to the working of your project (program). This project worth 4% of the overall module marks (100%). The project discussion will start on Saturday, the 10 th of November, 2012 and will remain for one week only, it is advised that you contact your project discussion teacher next week to fix a time/schedule for project discussion. For project discussion, check the teacher name below: Teacher Name (Location) Section Names Mr. Asif I. Khan (I st floor, Room No. 134) AA Mr. Abdullah (I st floor, Room No. 148) CA Mr. Mohammed Imran (I st floor, Room No. 148) BA, ZA, ZC

Program 2: KAU Air Booking System Objective Learn how to use classes and objects to create more powerful programs. Program Description This program is an extension of Program 1. The overall idea is the SAME. You will write a program to assign tickets/seats AND passengers for a commercial airplane. The airplane has 12 rows, with 7 seats in each row. Rows 1 and 2 are first class. Rows 3 to 7 are business class, and rows 8 to 12 are economy class. You must display the following menu to the user: ---------------------------------------------------- Welcome To KAU Air --- Seat Reservation System ---------------------------------------------------- 1. Book First Class Seats 2. Book Business Class Seats 3. Book Economy Class Seats 4. View Air Plane Seating Assignment 5. View Passenger List 6. System Status 7. Know Fair 8. System Reset 9. Exit From The Booking System Enter Your Choice: In this menu, there are two new options: View Passenger List (option 5) and System Status (option 6). All of the options, including these two new ones, will be discussed in detail starting on page 5. *** Difference between Program 1 and Program 2 *** For Program 2, each time you book a seat, that seat will have a specific ticket issued and a specific passenger will sit at that seat. Therefore, each booked seat will be represented by an object of type Ticket. Also, each ticket object will have a reference variable (psngr) that will point to (refer to) an object of type Passenger. You will need to use three *.java files, as follows: 1. Ticket.java : this file will have the Ticket class. You will make Ticket objects from the Ticket class. 2. Passenger.java : this file will have the Passenger class. You will make Passenger objects from the Passenger class. 3. KAUairBookingSystem.java : this file will contain main and all other auxiliary methods used or needed by your program.

For Program 1, you used a 2-d array of integers to represent the seats: 0 meant the seat was available, and 1 meant that the seat was taken (booked). Perhaps you declared your 2-d array as follows: int[][] x = new int[12][7]; Now, for Program 2, you will have a 2-d array of object references. Remember, in JAVA, we do not have a 2-d array of actual objects. Instead, we have a 2-d array of object references. Each cell of the array is a reference that refers to an object that you must create. ***For more information, see the notes on Chapter 8, Objects & Classes (pages 74 77). As an example, if you want your array variable to be called ticket, you can declare and create your array as follows: Ticket[][] ticket = new Ticket[12][7]; What does this line do? It creates a 12x7 (two dimensional) array of references. Note: each reference has a default value of null. Until now, we have NOT created any objects. Now, for example, you could create a new Ticket object and store the reference to that object at index [0][0], as follows: Ticket[0][0] = new Ticket(); So now, the reference at Ticket[0][0] does not store null. Instead, it stores an address to the new Ticket object we just created. The seat at index Ticket[0][0] is now booked. When you make a new Ticket object, new Ticket(), the constructor for the Ticket class is invoked to initialize the Ticket object. Here, inside the Ticket constructor, you will create a new Passenger object, and you will save the reference (address) of that object into the variable psngr. So now, the Ticket object is created and one of its data members is psngr, which is a variable pointing to a Passenger object. See the diagram below: Ticket Object int ticketnumber; // other variables Passenger psngr; Passenger Object String fname; String lname; int ID; ticket *the n stands for null n n n n n n

Description of the three Java Files (Classes) 1. Here is the UML diagram for the Ticket class (Ticket.java): There are 6 data members in this class. The first 4 data members are static (UML says package ). These variables are shared by ALL objects of the Ticket class. 1) numfirstclass is an int that stores the total number of First Class tickets 2) numbusinessclass is an int that stores the total number of Business Class tickets 3) numeconomyclass is an int that stores the total number of Economy Class tickets 4) ticketcounter is an int that represents the first ticket number assigned in the program. For example, the first seat assigned will get the ticket number KAU23730221. Then, ticketcounter is incremented. As a result, the next seat assigned will be given the ticket KAU23730222. 5) ticketnumber is an int that stores that actual ticket number for that specific Ticket object 6) psngr is a reference variable of type Passenger. This variable will store a reference to the Passenger object belonging to this ticket. The actual Passenger object will get created inside the constructor, Ticket(). This class has three methods: 1) Ticket() is the constructor. The constructor should do the following: It should save the current ticketcounter value into ticketnumber ticketnumber = ticketcounter++; See item 4 (above) for more information on what this line does. It should also create a new Passenger object as follows: psngr = new Passenger(); So now psngr stores a reference to the new Passenger object 2) getticketnumber() is the accessor method to get the ticketnumber 3) getpsngr() is the accessor method, which returns a reference to the Passenger object pointed to by this Ticket object.

2. Here is the UML diagram for the Passenger class (Passenger.java): This class has three private data fields, fname (first name), lname (last name), and ID This class has 7 methods 1) The first method is the constructor, Passenger(). This method should initialize fname and lname to unassigned This method should also initialize ID to -1. The other 6 methods are the standard accessor/mutator methods 3. The third java file should be called KAUairBookingSystem.java. KAUairBookingSystem.java This is your main program. This class file will have main and all of the other methods to run your program. The functionality of main will remain the same. You must display the menu, scan the user input (choice), and then perform appropriate methods. The following methods must be inside the KAUairBookingSystem.java file: 1. public static void showmenu() The menu gets printed/displayed on the screen. 2. public static void bookfirstclass(ticket[][] ticket, Scanner input, double ff) We send to this method three parameters: (1) a reference to the 2-d array of tickets, (2) a reference to the Scanner object, and (3) the cost of the first class fair (ff). You must first ask the customer how many seats they want, and then you will use the Scanner variable, input, to scan/save their input. The customer can requested more than one seat, and you must first make sure the seats are available. If the seats are available, you will create a new Ticket object for each seat requested. Once you create a new Ticket object, you must then scan the first name, last name, and ID of

the passenger and save them into the Passenger object. Finally, you will print a confirmation message. This message should print the first name, last name, ID, seat number, and ticket number for the passenger. (see sample output file). If the seats are not available, you should print an appropriate message (see sample output file). 3. public static void bookbusinessclass(ticket[][] ticket, Scanner input, double bf) We send to this method three parameters: (1) a reference to the 2-d array of tickets, (2) a reference to the Scanner object, and (3) the cost of the business class fair (bf). This methods works exactly like the previous methods, except that it works on Business Class. 4. public static void bookeconomyclass(ticket[][] ticket, Scanner input, double ef) We send to this method three parameters: (1) a reference to the 2-d array of tickets, (2) a reference to the Scanner object, and (3) the cost of the business class fair (bf). This methods works exactly like the previous methods, except that it works on Economy Class. 5. public static void displayseat(ticket[][] ticket) We send to this method the 2-d array of Ticket references. The method should display the current seating assignment (see sample output file). ***Hint: if (Ticket[i][j] == null), this means that no one is booked in that seat. If (Ticket[i][j]!= null), this means that the seat is booked and this index stores a reference to a specific Ticket object. 6. public static void passengerlist(ticket[][] ticket) We send to this method the 2-d array of Ticket references. The method should print out a list of all passengers booked on the flight (see sample output file). ***Hint: To do this, you must iterate over the 2-d array of references. If the reference does not equal null, this means that the seat is booked, and it means that a passenger is sitting there. So you must print out this passenger! However, from main, you do NOT have direct access to the fname, lname, and ID data fields of the Passenger object. From main, you only have access to the data fields of the Ticket objects. As such, you must invoke the getpassenger() method of the Ticket class. This method returns a reference to the Passenger object pointed to by this Ticket object. Of course, you must store this reference inside main. Here is an example of this: Passenger p1; p1 = ticket[i][j].getpsngr(); Now, from main, you have direct access to a specific Passenger object. As such, you can now use the mutator methods of the Passenger class (getfname, getlname, getid)to print the passenger data. 7. public static void statussystem(ticket[][] ticket, double ff, double bf, double ef) We send to this method four parameters: the 2-d array of Ticket references and the three prices for the cost of the fare. If at least one seat has been assigned, this method should display the total number of passengers booked in each class and the Total Fare paid for each class. If no seats are booked, an error message should be displayed (see sample output file).

8. public static void knowfair(double ff, double bf, double ef) This method simply prints out the fare (see sample output file). 9. public static void resetsystem(ticket[][] ticket) We send to this method the 2-d array of Ticket references. The method should reset the system. This means that all cells in the 2-d array should be reset to null. Note: before performing the reset, you must confirm with the user by asking them if they are sure they want to perform a system reset. If they answer y or Y, then you should reset the system and print an appropriate message (see sample output file). 10. public static void main(string[] args) Of course, you must have a main method to test your system. Output Format Your program should output in a similar format to the sample provided (see below). Sample and Output Files A sample run of the program will be provided on Moodle. Study this output carefully and make sure your program works similarly. Grading Details Your program will be graded upon the following criteria: 1) Adhering to the implementation specifications listed on this write-up. 2) Your algorithmic design. 3) Correctness. 4) Use of Classes and 2-d array of objects. If your program does not use objects, you will NOT get credit for the assignment. Period. 5) The frequency and utility of the comments in the code, as well as the use of white space for easy readability. (We're not kidding here. If your code is poorly commented and spaced and works perfectly, you could earn as low as 80-85% on it.) 6) Your program should include a header comment with the following information: your name, course number, section number, assignment title, and date. Deliverables You should submit three files: 1. Ticket.java 2. Passenger.java 3. KAUairBookingSystem.java NOTE: your name, ID, section number should be included as comments in all files!