0% found this document useful (0 votes)
51 views19 pages

Individual Assignment of ISD (Introduction To Software Development)

This document contains an individual assignment for an Introduction to Software Development (ISD) module. It includes: 1) Assumptions made to simplify the program design, such as tickets only being available on a single date and for two ferry routes. 2) An overview of the program design, including its structure and flowchart. The program has functions for the main menu, purchasing tickets, viewing seating, and more. 3) The Java source code for the ferry ticketing program. It includes classes, methods for the main menu, purchasing tickets, viewing seating, and other functions.

Uploaded by

Li Xuan
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
51 views19 pages

Individual Assignment of ISD (Introduction To Software Development)

This document contains an individual assignment for an Introduction to Software Development (ISD) module. It includes: 1) Assumptions made to simplify the program design, such as tickets only being available on a single date and for two ferry routes. 2) An overview of the program design, including its structure and flowchart. The program has functions for the main menu, purchasing tickets, viewing seating, and more. 3) The Java source code for the ferry ticketing program. It includes classes, methods for the main menu, purchasing tickets, viewing seating, and other functions.

Uploaded by

Li Xuan
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 19

Individual Assignment for ISD

Individual Assignment of ISD (Introduction to Software Development)

Student Name:0000 Student ID:TP000000 Student Intake:TP0000COM Module Code: CE00371-1-ISD

1 / 19

Individual Assignment for ISD

Table of Contents
1. Assumptions made..... ..... ..3 2. Design of the program..... .. .. ....4 3. Source code of the program.. .. .. .. 5-9 4. Test plan.. .. .. .. .. ...10-13 5. Sample outputs.. .. .. .. 14-17 6. Additional features .... .. .. ...18 7. References..... .. .. 19

2 / 19

Individual Assignment for ISD

Assumptions made
According to the basic requirements of the assignment, considering of the difficulty of the whole mentioned details designed by a simple java console program without supporting of some other techniques(Such as database ,GUI etc.),Some assumptions are made to make the program easier for implement. The assumptions made in this assignment are: 1.The tickets users allowed to purchase are all on 14:00 to 15:00, Dec 03,2009, while there are only two ferrys available: Ferry ID:07 - From Langkawi to Penang. Ferry ID:08 - From Penang to Langkawi. 2.The input of users names are ignored, since the useless of names according to the basic requirements.

3 / 19

Individual Assignment for ISD

Design of the Program


Structure: (The structure heres just an overview design of the program, some parts such as scope of class has ignored) variables declaration function main(gets the return value from each function to determine which function to run next) function mm(includes all functions during main menu displayed) function p_cf(includes all functions during choosing ferry submenu of purchasing displayed) function p_cc(includes all functions during choosing class submenu of purchasing displayed) function p_a(includes all functions during seating alternative submenu of purchasing displayed) function p_pt(includes all functions during printing ticket submenu of purchasing displayed) function p_v(includes all functions during view seating arrangement submenu of purchasing displayed) function clr(to clear the screen of the console, used to refresh the menu) Overview Flow Chart of structure of the program: (Since the detail of structure of the program is very complicated, only flow chart to show how the divided functions work is provided.)

4 / 19

Individual Assignment for ISD

Source Code of the Program


/** * @(#)FerryTicketing.java * * * @author HuPu,TP016188 * @version 1.00 2009/12/3 */ import java.util.Scanner; public class FerryTicketing { public static Scanner scanner=new Scanner(System.in); public static int r[]=new int[2]; /*r[0]-recent ferry r[1]-recent num*/ public static int seat[][]=new int[2][50]; public static int count[][]=new int[2][2]; /*count[0][0]-number of people in ID07,BusinessClass count[0][1]-number of people in ID07,EconomicClass count[1][0]-number of people in ID08,BusinessClass count[1][1]-number of people in ID08,EconomicClass*/ public static void main(String args[])throws Exception{ int c=0; do{ clr(); switch (c){ case 0:{c=mm();break;} /*Main menu*/ case 1:{c=p_cf();break;} /*purchase_choose ferry*/ case 11:{c=p_cc(1);break;} /*ID07-choose class*/ case 12:{c=p_cc(2);break;} /*ID08-choose class*/ case 111:{c=p_a(1);break;} /*ID07-Business Class full,change to Economic Class*/ case 112:{c=p_a(2);break;} /*ID07-Economic Class full,change to Business Class*/ case 121:{c=p_a(3);break;} /*ID08-Business Class full,change to Economic Class*/ case 122:{c=p_a(4);break;} /*ID08-Economic Class full,change to Business Class*/ case 13:{c=p_pt();break;} /*purchase_print ticket*/ case 2:{c=v();break;} /*view seating arrangement*/ default:break; /*useless here*/ } }while(true); } public static int mm()throws Exception{ System.out.println("FERRY TICKETING SYSTEM"); System.out.println("<P>Purchase Ticket"); System.out.println("<V>View Seating Arrangement"); System.out.println("<Q>Quit the Sysem");
5 / 19

Individual Assignment for ISD

String k = scanner.nextLine(); /*input p or P*/ if(k.equals("p")||k.equals("P")){return 1;} /*input v or V*/ else if(k.equals("v")||k.equals("V")){return 2;} /*input q or Q*/ else if(k.equals("q")||k.equals("Q")){System.exit(0);} /*input another key*/ return 0; } public static int p_cf()throws Exception{ System.out.println("FERRY TICKETING SYSTEM"); System.out.println("Ticket Purchasing>>>Choose Ferry"); System.out.println("<A>Ferry ID:07:Langkawi to Penang"); System.out.println("<B>Ferry ID:08:Penang to Langkawi"); System.out.println("<M>Return to Main Menu"); String k = scanner.nextLine(); /*input a or A*/ if(k.equals("a")||k.equals("A")){if((count[0][0]==10)&&(count[0][1]==40)) {System.out.println("All seats of Ferry ID:07 has been sold out.\n"); System.out.println("input enter to choose ferry again."); scanner.nextLine();return 1;} return 11;} /*input b or B*/ else if(k.equals("b")||k.equals("B")){if((count[1][0]==10)&&(count[1][1]==40)) {System.out.println("All seats of Ferry ID:08 has been sold out.\n"); System.out.println("input enter to choose ferry again."); scanner.nextLine();return 1;} return 12;} /*input m or M*/ else if(k.equals("m")||k.equals("M")){return 0;} /*input another key*/ else {return 1;} } public static int p_cc(int i)throws Exception{ int f07b=count[0][0]; int f07e=count[0][1]; int f08b=count[1][0]; int f08e=count[1][1]; System.out.println("FERRY TICKETING SYSTEM"); System.out.println("Ticket Purchasing>>>Choose Ferry>>>Choose Class");
6 / 19

Individual Assignment for ISD

System.out.println("<B>Purchase ticket for Business Class"); System.out.println("<E>Purchase ticket for Economic Class"); System.out.println("<U>Return to Upper Menu"); System.out.println("<M>Return to Main Menu"); String k = scanner.nextLine(); /*input b or B*/ if(k.equals("b")||k.equals("B")){if(i==1){/*Ferry07-BusinessClass*/ if(f07b<10){count[0][0]+=1;r[0]=1; r[1]=count[0][0];seat[0][f07b]=1;return 13;} else{return 111;}} else {/*Ferry08-BusinessClass*/ if(f08b<10){count[1][0]+=1;r[0]=2; r[1]=count[1][0];seat[1][f08b]=1;return 13;} else{return 121;}}} /*input e or E*/ else if(k.equals("e")||k.equals("E")){if(i==1){/*Ferry07-EconomicClass*/ if(f07e<40){count[0][1]+=1;r[0]=1; r[1]=count[0][1]+10;seat[0][f07e+10]=1;return 13;} else {return 112;}} else {/*Ferry08-EconomicClass*/ if(f08e<40){count[1][1]+=1;r[0]=2; r[1]=count[1][1]+10;seat[1][f08e+10]=1;return 13;} else{return 122;}}} /*input u or U*/ else if(k.equals("u")||k.equals("U")){return 1;} /*input m or M*/ else if(k.equals("m")||k.equals("M")){return 0;} /*input another key*/ else {return i;} } public static int p_a(int i)throws Exception{ int f07b=count[0][0]; int f07e=count[0][1]; int f08b=count[1][0]; int f08e=count[1][1]; System.out.println("FERRY TICKETING SYSTEM"); System.out.println("Ticket Purchasing>>>Choose airline>>>Choose class"); if(i==1)System.out.println("The Business Class of Ferry ID:07 is full!"); if(i==1)System.out.println("Change to Economic Class?"); if(i==2)System.out.println("The Economic Class of Ferry ID:07 is full!"); if(i==2)System.out.println("Change to Business Class?"); if(i==3)System.out.println("The Business Class of Ferry ID:08 is full!"); if(i==3)System.out.println("Change to Economic Class?");
7 / 19

Individual Assignment for ISD

if(i==4)System.out.println("The Economic Class of Ferry ID:08 is full!"); if(i==4)System.out.println("Change to Business Class?"); System.out.println("<Y>Yes\n"); System.out.println("<N>No\n"); String k = scanner.nextLine(); /*input y or Y*/ if(k.equals("y")||k.equals("Y")){ switch(i){ case 1:{count[0][1]+=1;r[0]=1; r[1]=count[0][1]+5;seat[0][f07e+10]=1;return 13;} /*07b-07e*/ case 2:{count[0][0]+=1;r[0]=1; r[1]=count[0][0];seat[0][f07b]=1;return 13;} /*07e-07b*/ case 3:{count[1][1]+=1;r[0]=2; r[1]=count[1][1]+5;seat[1][f08e+10]=1;return 13;} /*08b-08e*/ case 4:{count[1][0]+=1;r[0]=2; r[1]=count[1][0];seat[1][f08b]=0;return 13;} /*08e-08b*/ }} /*input n or N*/ else if(k.equals("n")||k.equals("N")){System.out.println("\nNext trip leaves in 1 hours.\n"); System.out.println("input anykey return to main menu.\n");return 0;} /*input another key*/ return i; } public static int p_pt(){ System.out.println("FERRY TICKETING SYSTEM"); System.out.println("Ticket Purchasing successful!Your boarding ticket:"); System.out.println("*************************************************"); System.out.println("* Name : XXX XXX XXX *"); if(r[0]==1)System.out.println("* Ferry ID : 07 - Langkawi to Penang *"); if(r[0]==2)System.out.println("* Ferry ID : 08 - Penang to Langkawi *"); if(r[1]<6)System.out.println("* Seat : "+r[1]+" (Business Class) *"); if(r[1]>5)System.out.println("* Seat : "+r[1]+" (Economic Class) *"); System.out.println("* Departure: Dec 03,2009 14:00-15:00 *"); System.out.println("*************************************************"); System.out.println("input enter return to main menu.\n");scanner.nextLine(); return 0; } public static int v()throws Exception{ int c,i; System.out.println("FERRY TICKETING SYSTEM"); System.out.println("View Seating Arrangement>>>Choose ferry ID:"); System.out.println("<A>Ferry 07:Langkawi to Penang");
8 / 19

Individual Assignment for ISD

System.out.println("<B>Ferry 08:Penang to Langkawi"); System.out.println("<M>Return to Main Menu\n"); String k = scanner.nextLine(); /*input a or A or b or B*/ if(k.equals("a")||k.equals("A")||k.equals("b")||k.equals("B")){ clr(); System.out.println("*****************************************"); System.out.println("* Ferry ID:00"+((k.equals("a")||k.equals("A"))?7:8) +" Date:03 Dec 2009 *"); System.out.println("*****************************************"); System.out.println("* Business Class *"); System.out.print("*****************************************\n*"); for(i=1;i<51;i++){ System.out.print(" "+seat[((k.equals("a")||k.equals("A"))?0:1)][i-1]+" *"); if(i%5==0){System.out.print("\n*****************************************\n*");} if(i==10){System.out.print(" Economy Class *\n"); System.out.print("*****************************************\n*");} } System.out.println(" input enter return to upper menu. *"); System.out.println("*****************************************"); scanner.nextLine(); return 2;} /*input m or M*/ else if(k.equals("m")||k.equals("M")){return 0;} /*input another key*/ else {return 2;}} public static void clr(){for(int i=0;i<400;i++)System.out.println("");} }

9 / 19

Individual Assignment for ISD

Test Plan
Therere four tests here I made to test if the program runs correctly and if it can handle some sudden events(Such as the ticket user want has sold out). Test1.To test if boarding tickets printed correctly after purchasing successfully. (1)After purchasing a ticket for Ferry ID:07,Business Class.

(2) after purchasing a ticket for Ferry ID:08,Economic Class.

Result: Boarding tickets printed correctly after purchasing successfully.

10 / 19

Individual Assignment for ISD

Test2.To test if seating arrangement displayed correctly after purchasing successfully. (1)After purchasing 2 tickets for Ferry ID:07 Business Class.

11 / 19

Individual Assignment for ISD

(2) After purchasing 3 tickets for Ferry ID:08 Economic Class.

Result: Seating arrangement displayed correctly after purchasing successfully.

12 / 19

Individual Assignment for ISD

Test3.To test the seating alternative while one class is full on a ferry. (1)Purchasing a ticket while ferry ID:07 Business Class is full.

(1.1)Press Yes.

(1.2)Press No.

Result: Seating alternative function runs well.

Test4.To test the situation while purchasing a ticket on which ferry that all seats has sold out. (1) Purchasing ticket for ferry ID:07 while all its seats has sold out.

Result: No logic errors.


13 / 19

Individual Assignment for ISD

Sample outputs
Heres some sample outputs that the user do some operations after the program executing.(For exception handling, please execute the program or check the test plan) The steps of the users operations are: 1.Purchase a ticket of Business Class on ferry ID:07. 2.Purchase a ticket of Economic Class on ferry ID:08. 3.View seating arrangement on ferry ID:07. 4.View seating arrangement on ferry ID:08. Sample Outputs: Execute the program from CMD:

Press P.

Press A.

Press B.

14 / 19

Individual Assignment for ISD

Press enter.

Press P.

Press B.

Press E.

Press enter.

Press V.

15 / 19

Individual Assignment for ISD

Press A.

Press enter.

16 / 19

Individual Assignment for ISD

Press B.

Press enter.

Press M.

Press Q.

The program exit.


17 / 19

Individual Assignment for ISD

Additional Features
1. Design The program was not designed as a traditional water-fall structured application. Each part of the functions was divided as a single function with a return value in the java source code. The idea is using a looping switch function in main function to determine which function to execute next, then each function except main function returns a value to tell main function what to do next. The advantage of this kind of design is that each function isolated so that the codes are easy for programmer to read or modify. 2. Code The program used most programming concepts mentioned in basic requirements of the assignment such as displaying and reading of texts , variables , declare and assignment of values, comments, selection control structures, loops, use of arrays, strings.etc. Some additional features are also used in the source code, such as functions (with return value), throws exception while reading texts .etc.

18 / 19

Individual Assignment for ISD

References
1. P.J.Deitel,Java How To Program,Seventh Edition.Upper Saddle River,2007.ISBN 0-13-613247-2. 2. Slides of ISD module. 3. http://www.java-cn.com/

19 / 19

You might also like