All pastes #267772 Raw Edit

Stuff

public java v1 · immutable
·published 2006-12-05 02:15 UTC
rendered paste body
/* switchStatement *///importing JOptionPane classimport javax.swing.JOptionPane;//menu options using switchStatementpublic class Step1Driver	{				 				public static void main(String[] args) 			{				String idno, name, dob;				Double fees;				Step1Class step1[] = new Step1Class[Step1Class.MAXNUMS];								Step1Class s1 = new Step1Class(); // Initialise Database				step1[Step1Class.nStudents] = s1;				Step1Class.nStudents++;								 								String menu="Enter a number to choose one of the following :\n"+							  "(1) Add a student\n"+							  "(2) Search for student ID number\n"+							  "(3) Search for student name\n"+							  "(4) Calulate total number of students\n"+							  "(5) Calculate total fees\n"+							  "(6) Display current database\n"+							  "(0) Quit\n";							  								int option;	// used to store users selection			 			 	String strOption;							 											do					{   // Reading menu-input						strOption=JOptionPane.showInputDialog(null,menu,						           "Student-TrialTest",JOptionPane.INFORMATION_MESSAGE );						option = Integer.parseInt(strOption);												// switch statement						switch(option){														// add a student to the database														case 1: 									if (Step1Class.nStudents == step1.length)									{										JOptionPane.showMessageDialog(null,"Class is full!!!","!!!",										JOptionPane.ERROR_MESSAGE);																				return;									}																idno = JOptionPane.showInputDialog("Enter ID-NO of new Student");									name = JOptionPane.showInputDialog("Enter Name of new Student");									dob = JOptionPane.showInputDialog("Enter Date of birth of new Student");									fees = Double.parseDouble(JOptionPane.showInputDialog("Enter Fees of new Student"));									Step1Class s2 = new Step1Class(idno, name, dob, fees);									step1[Step1Class.nStudents] = s2;									Step1Class.nStudents++;								   break;															// search for an ID number of a student								case 2: JOptionPane.showMessageDialog(null,"InsertCode","Search for ID", JOptionPane.INFORMATION_MESSAGE );								   break;															// find students name							case 3: JOptionPane.showMessageDialog(null,"InsertCode","Search for student name", JOptionPane.INFORMATION_MESSAGE );								 								   break;															case 4: JOptionPane.showMessageDialog(null,"InsertCode","Delete a given ID rec", JOptionPane.INFORMATION_MESSAGE );										   			   break;															// calculate total amount of students.								case 5: JOptionPane.showMessageDialog(null,"InsertCode","Total Amount of student", JOptionPane.INFORMATION_MESSAGE );								 								   break;														// calculate total fees for students								case 6:									DisplayDataBase(step1);																 								   break;																	case 0: // to quit and print an activity report								    JOptionPane.showMessageDialog(null,"InsertCode","Quit the program", JOptionPane.INFORMATION_MESSAGE ); 								   break;															default:								 JOptionPane.showMessageDialog(null,"Whoops !!!! Number must" +								    " be between 0 & 7","Error in selection", JOptionPane.ERROR_MESSAGE );					    	} // end of switch 						} while(option != 0); // end of loop															 					System.exit(0);	// terminate the program		  								  			} // end of 'main'				//********************************		//*			methods Defs         *		//********************************					 public static void DisplayDataBase(Step1Class step1[])		 {		 	String AllStudents = "";		 	for(int i = 0; i < Step1Class.nStudents; i++)										{											AllStudents += step1[i].DisplayRecord();										}							JOptionPane.showMessageDialog(null,AllStudents,"Current Database",							JOptionPane.INFORMATION_MESSAGE);		 }		 	}	// end of 'class'