| cpas |
Nov 21st, 2004 10:41 PM |
This is my school assignment.Implement a Java program with the following screen outputs:Menu1) Add New Student Record2) Display All Student Records3) Enquire Student RecordI finished doing function 1 and 2, but for the third one: Enquire Student Record, I don't know how to write search function, can anyone write for me a simple program to search Student record? Thanks.
This is my program with first two function:
:
import java.io.*;
class student
{
String studentID;
String Name;
String Address;
String Telephone;
public void setData() throws IOException
{//to set data of each student
BufferedReader stuData = new BufferedReader
(new InputStreamReader (System.in));
System.out.print("\n\t\tEnter StudentID: ");
studentID = stuData.readLine();
System.out.print("\n\t\tEnter Name of the Student: ");
Name = stuData.readLine();
System.out.print("\n\t\tEnter Address: ");
Address = stuData.readLine();
System.out.print("\n\t\tEnter Telephone number: ");
Telephone = stuData.readLine();
}
public void Display ()
{
//display detail of each student
System.out.println();
System.out.print (studentID + "\t\t"+Name + "\t" +Address+ "\t\t" +Telephone);
}
}//end of student class
class StudentProgram
{
//student_count gives Number of student records in Array.
static int student_count = 0;
/*studnetRec is an Array of student objects which can store
up to the mazimum of 20 student objects*/
static student studentRec[] = new student[20];
public static void clear_screen()
//to clear screen
{for (int i=0; i<5; i++)
System.out.println();
}
public static void Add_Rec() throws IOException
{
clear_screen();
studentRec[student_count] = new student();
//calling setdata to set data
studentRec[student_count].setData();
//To count student record just added
student_count++;
//to display main menu
Menu();
}
public static void View_All() throws IOException
{
clear_screen();
/*creation of student object uf the
user choose choice 1 to add
new Student Record*/
BufferedReader ch = new BufferedReader
(new InputStreamReader(System.in));
System.out.print("StudID \t\tName \t\tAddress \t\t\tTel");
//to display all student records in Array
for (int i=0; i <student_count; i++)
studentRec [i].Display();
System.out.println("\nPress Any key to display menu ");
String anykey = ch.readLine();
}
public static void Menu() throws IOException
{
int choice;
BufferedReader br = new BufferedReader(
new InputStreamReader(System.in));
do{
clear_screen();
for (int i=0; i<4; i++)//i<4 (no. of lines from the top)
System.out.println();
System.out.println("\t\t\t###################################");
System.out.println("\n\t \t\t(1) Add New Student Record");
System.out.println("\n\t \t\t(2) Display All Student Records");
System.out.println("\n\t \t\t(3) Enquire Student Record");
System.out.println("\n\t \t\t(4) Exit Program");
System.out.println("\t\t\t###################################");
System.out.print("Enter Your Choice");
choice = Integer.parseInt(br.readLine());
//to read any data from the keyboard(readline)
switch(choice)
{
case 1:
Add_Rec();
break;
case 2:
View_All();
break;
case 3:
System.out.println("You choose enquire student record");
break;
}
}while(choice!=4);
System.out.println("\n\t\t\tThank you for using Program");//n\t\t(alignment)
}
public static void main (String args[]) throws IOException
{
Menu();
}
}//end of class
I WILL BE GREATFUL WITH YOUR HELP.
(You have been [code] tagged and slightly formatted! - SykkN)
|