Individual Assignment of ISD (Introduction To Software Development)
Individual Assignment of ISD (Introduction To Software Development)
1 / 19
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
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
4 / 19
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
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
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
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
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.
10 / 19
Test2.To test if seating arrangement displayed correctly after purchasing successfully. (1)After purchasing 2 tickets for Ferry ID:07 Business Class.
11 / 19
12 / 19
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.
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.
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
Press enter.
Press P.
Press B.
Press E.
Press enter.
Press V.
15 / 19
Press A.
Press enter.
16 / 19
Press B.
Press enter.
Press M.
Press Q.
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
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