Moha Ali Mustafa

Moha Ali Mustafa

  • 2.1k
  • 1
  • 1.2k

Student Registeration Program

Nov 28 2014 4:35 AM
Hi dear am supposed to write a program which used to save a student information for register with their nameS IDs and DEPARTments
I got confused I could write this kind of code and still has alot to write but couldnt manage it I f you can help me or at least  give some recommendation I would really appreciate.




/*Title:Basic Student register program

**
*Description:This program takes 2 .text files about student and department available on the university,and reads it.
*In this program you can you can register new students with their name and ID'S in a specific department or you can delete. Additionally,
*You can limit the number of student registering in a department as well as you can view the registered students and available departments.
*into 2 .text files.
*
*User Guide:After you run the program you can see the menu as output.You can select 
*any choice by selecting 
*
* @author Ahmed S.Mustafa**
*/
import java.io.*;
import java.util.Scanner;
import java.applet.*;


class student {
private String sID;
private String sName;
 
public student (String Name, String ID) {
sID = ID;
sName = Name;
}
public void setsName (String Name) {
sName = Name;
}
public String getsName () {
return sName;
}
public void setsID (String ID) {
sID = ID ;
}
public String getsID () {
return sID;
}
public void Displaystudent ()
{
System.out.println("Name:" + sName + " ID:" + sID);
}
class department {
private String dDepartName;
private String dDID; //DID Means Department ID/code
private student [] stu = new student [5];
private Integer dNumOfStudents;

public department (String DepartName, String DID) {
dDepartName = DepartName;
dDID = DID;
}
public void setdDID (String DID) {
dDID = DID;
}
public String getdDID () {
return dDID;
}
public void setdDepart (String DepartName) {
dDepartName = DepartName; //
}
public String getdDepart () {
return dDepartName;
}
public int getdNumOfStudents () {
return dNumOfStudents;
}
public student [] getstu () {
return stu;
}
public void addstudent (student s){
if (dNumOfStudents < 6){
stu [dNumOfStudents] = s;
dNumOfStudents++;
}
else {
System.out.println("You cant add anymore students into the department of " + dDepartName);
}
}
public int Search (student s){
for (int i = 0; i < dNumOfStudents; i++) {
if (stu [i] .getsID () .equalsIgnoreCase(s.getsID() )) {
return i;
}
}
return -1; //// WHY -1  !!!!!!!!!!!!!!!!!!!!!!!!!!!!!
}
public void Displaydepartment () {
System.out.println("DID:" + dDID + " DepartName:" + dDepartName );
System.out.println(dDepartName + "'s Students:");/////WHY !!!!!
if (dNumOfStudents == 0) {
System.out.print("<>None");
} else {
for (int i = 0; i <  dNumOfStudents; i++) {
System.out.print(stu [i].getsName() + " ");
}
}
}

}
abstract class Regist {

   public abstract void ReadSt();
   public abstract void ReadDp();

   public abstract int SearchSt(String ID);
   public abstract int SearchDp(String ID);

   public abstract void Insertstudent(student s);
   public abstract void Insertdepartment(department d);

   public abstract void DeleteSt(String ID);    
   public abstract void DeleteDp(String DID);
   
   public abstract void UpdateSt(String ID);    
   public abstract void UpdateDp(String DID);
   
   public abstract void SelectDp(String DIDdp, String IDSt);
   
   public abstract void studentQuery(String ID);
   public abstract void departmentQuery(String DID);
   
   public void ListDp() {
       System.out.println("DID  " + "Name " + "NumOfStudents;");
       System.out.println("");
   }

   public void ListSt() {
       System.out.println("ID  " + "Name ");
       System.out.println("");
   }

   public abstract void WriteFileDp();
   public abstract void WriteFileSt();
   public abstract void DisplayMenu();
}

class StuRegist extends Regist {        ///ERRROR!!!!!!!!

   protected department[] dp = new department[100];
   protected student[] st = new student[100];
   protected int countdp = 0;
   protected int countst = 0;

  public void ReadDp() {
       try {
           FileReader FRead = new 
           FileReader
("C://Users//hp//Documents//eclipseProjects//SemesterProject//department.txt");

           BufferedReader in = new BufferedReader(FRead);
           String line = in.readLine();
           line = in.readLine();
           while (line != null) {
               String data[] = line.split("\t");
               department d = new department(data[0], data[1]);
               dp[countdp] = d;
               countdp++;
               line = in.readLine();
           }
       } catch (IOException e) {
           System.out.println("Error:" + e);
       }
   }
   public void ReadSt() {
       try {
           FileReader FRead = new 
        FileReader("C://Users//hp//Documents//eclipseProjects//SemesterProject//department.txt");
           BufferedReader in = new BufferedReader(FRead);
           String line = in.readLine();
           line = in.readLine();
           while (line != null) {
             String data[] = line.split("\t");
             student s = new student(data[0], data[1]);
               st [countst] = s;
               countst++;
               line = in.readLine();
           }
       } catch (IOException e1) {
           System.out.println("Error:" + e1);
       }
   }

   public int SearchSt(String ID) {
       for (int i = 0; i < countst; i++) {
           if (st[i].getsID().equalsIgnoreCase(ID)) {
               return i;
           }
       }
       return -1;
   }

   public void Insertstudent(student s) {
       if (SearchSt(s.getsID()) == -1) {
           if (countst <= 100) {
               st[countst] = s;
               countst++;
           } else {
               System.out.println("You cannot add anymore student!");
           }
       } else {
           System.out.println("Student " + st[SearchSt(s.getsID())].getsName() + " already exist");
       }
   }

   public void DeleteSt(String ID) {
       Scanner in = new Scanner(System.in);
       if (SearchSt(ID) != -1) {
           System.out.println("You re going to delete student " + st[SearchSt(ID)].getsName() + "!");
           System.out.println("Enter y to continue or n to stop deletion");
           String ans = in.next();
           if (ans.equalsIgnoreCase("y")) {
               st[SearchSt(ID)] = null;
               System.out.println("Student is succesfully deleted.");
           }
       } else {
           System.out.println("There is no student with the ID:" + ID + " in this university!");
       } 
   }
   
   public void SelectDp(String DIDdp, String IDst) {
       if (SearchDp(DIDdp) != -1) {
           if (SearchSt(IDst) != -1) {
               dp[SearchDp(DIDdp)].addstudent(st[SearchSt(IDst)]);
               System.out.println("Student" + st[SearchSt(IDst)].getsName() 
                   + " is succesfully selected dp " + dp[SearchDp(DIDdp)].getdDepart()); ////Error!!!!!!!!!!!
               } else {
               System.out.println("There is no student with the ID:" + IDst + " in this university!");
           }
       } else {
           System.out.println("There is no department with the DID:" + IDst + " in this university!");
       }
   }

   @Override
   public void departmentQuery(String DID) {
       if (SearchDp(DID) != -1) {
           if (dp[SearchDp(DID)] != null) {
               dp[SearchDp(DID)].Displaydepartment();
           }
       } else {
           System.out.println("There is no department with the ID:" + DID + " in this university!");
       }
   }
   
   ///There  may be an error you should check the parameters

   
   

   public void DoctorQuery(String DID) {
       if (SearchDp(DID) != -1) {
           if (dp[SearchDp(DID)] != null) {
               dp[SearchDp(DID)].Displaydepartment();
           }
       } else {
           System.out.println("There is no department with the DID:" + DID + " in in our school!");
       }
   }

   public void StudentQuery(String ID) {
       if (SearchSt(ID) != -1) {
           if (st[SearchSt(ID)] != null) {
               st[SearchSt(ID)].Displaystudent();
           }
       } else {
           System.out.println("There is no student with the ID:" + ID + " in this university!");
       }
   }
   
   
       public void ListDp() {
       super.ListDp();
       for (int i = 0; i < countdp; i++) {
           if (dp[i] != null) {
               System.out.println(dp[i].getdDID() + " " + dp[i].getddepartName() + "    " + dp[i].getdNumOfStudents());
           }
       }
   }

   @Override
   public void ListSt() {
       super.ListSt();
       for (int i = 0; i < countst; i++) {
           if (st[i] != null) {
               System.out.println(st[i].getsID() + " " + st[i].getsName());
           }
       }
   }
}



}


Thanks In advance

Answers (1)