Java Program for Student Project Management, Exercises of Web Design and Development

A java code implementation for managing student projects, including project title, current phase, and status. The code includes classes for project and student, with methods for setting and getting project details, displaying project details on gui, adding and searching for projects, and deleting projects. The student class also includes student name, roll number, phone number, study program, and status.

Typology: Exercises

2011/2012

Uploaded on 08/01/2012

ambuja
ambuja 🇮🇳

4.4

(5)

92 documents

1 / 20

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
Assignment No.1 Web Design and
Development (CS506)
Marks:
20
Due Date: 20/04/2012
Assignment Solution:
//Project.java File
import javax.swing.JOptionPane;
public class Project {
private String title;
private String status; // accepted reject canceled cleared
private String currentPhase;
private String stdRollNum;
//default constructor
public Project(){
this.title = "";
this.status = "";
this.currentPhase = "";
this.stdRollNum = "";
}
//parametrized constructor
public Project(String title, String status, String phase, String studentId){
this.title = title;
this.status = status;
this.currentPhase = phase;
this.stdRollNum = studentId;
}
//Student name getter setter
public void setProjectTitle(String title){
docsity.com
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12
pf13
pf14

Partial preview of the text

Download Java Program for Student Project Management and more Exercises Web Design and Development in PDF only on Docsity!

Assignment No.1 Web Design and Development (CS506)

Marks: 20

Due Date: 20/04/

Assignment Solution: //Project.java File import javax.swing.JOptionPane;

public class Project {

private String title; private String status; // accepted reject canceled cleared private String currentPhase; private String stdRollNum;

//default constructor public Project(){ this.title = ""; this.status = ""; this.currentPhase = ""; this.stdRollNum = ""; }

//parametrized constructor public Project(String title, String status, String phase, String studentId){ this.title = title; this.status = status; this.currentPhase = phase; this.stdRollNum = studentId; }

//Student name getter setter public void setProjectTitle(String title){

this.title = title; } public String getProjectTitle(){ return this.title; }

//Student name getter setter public void setProjectCurrentPhase(String currentphase){ this.currentPhase = currentphase; } public String getProjectCurrentPhase(){ return this.currentPhase; }

//Student name getter setter public void setProjectStatus(String status){ this.status = status; } public String getProjectStatus(){ return this.status; }

//Student name getter setter public void setStudentRollNumber(String id){ this.stdRollNum = id; } public String getStudentRollNumber(){ return this.stdRollNum; }

//display student project detail on GUI

// parametrized constructor public Student(String name, String rollnum, long phone, String program, int status){ this.name = name; this.rollNumber = rollnum; this.phoneNumber = phone; this.studyProgram = program; this.status = status; projects = new ArrayList(); }

//Student name getter setter public void setStudentName(String name){ this.name = name; } public String getStudentName(){ return this.name; }

//Student name getter setter public void setStudentRollNumber(String rollnumber){ this.rollNumber = rollnumber; } public String getStudentRollNumber(){ return this.rollNumber; }

//Student name getter setter public void setStudentPhoneNumber(long phone){ this.phoneNumber = phone; }

public long getStudentPhoneNumber(){ return this.phoneNumber; }

//Student name getter setter public void setStudentStudyProgram(String program){ this.studyProgram = program; } public String getStudentStudyProgram(){ return this.studyProgram; }

//Student name getter setter public void setStudentStatus(int status){ this.status = status; } public int getStudentStatus(){ return this.status; }

// display student information public void studentInfo (){ String stat; if(getStudentStatus() == 0){ stat = "Active"; } else if(getStudentStatus() == 1){ stat = "Freezed"; } else{ stat = "Blocked";

//add new project record to arraylist after taking input public void addProject( ) {

String title = getStudentInfo("Enter Project Title"); if(title.equals("invalid") ){ return; }

String phase = getStudentInfo("Enter Current Phase"); if(phase.equals("invalid") ){ return; }

String stats = getStudentInfo("Enter Current Phase"); if(stats.equals("invalid") ){ return; } //construt new person object Project p = new Project(title, stats, phase, this.getStudentRollNumber());

//add the above project object to arraylist projects.add(p); }

//search person record by name by iterating over arraylist public void searchProject (String n) { int found = 0; for (int i=0; i < projects.size(); i++) { Project p = (Project)projects.get(i);

if ( n.equals(p.getStudentRollNumber() )) { p.print(); found++; }

} // end for if(found == 0) { JOptionPane.showMessageDialog(null, "No Project found for " + n + " Student" ); }

} // end searchPerson

//delete person record by name by iterating over arraylist public boolean deleteProject (String n) { int deleted = 0; for (int i=0; i< projects.size(); i++) { Project p = (Project)projects.get(i); if ( n.equals(p.getStudentRollNumber()) ) { projects.remove(i); JOptionPane.showMessageDialog(null, "All projects of Student " + n + " Deleted" );

deleted++; } } if(deleted == 0) { return false; } return true; }

return temp; }

public static void main (String args[]) {

// specialized array to hold student objects ArrayList students = new ArrayList();

String input, str; int choice;

while (true) {

input = JOptionPane.showInputDialog( "Enter 1 to Add New Student" + "\nEnter 2 to Search Student" + "\nEnter 3 to Delete Student" + "\nEnter 4 to Add Project of a Student" + "\nEnter 5 to Search Projects of a Student" + "\nEnter 6 to Delete All Projects of a Student" + "\nEnter 7 to Exit the Application" );

// check cancel key hit if(input == null){ System.exit(0); }

input = input.replaceAll("\s", ""); // check value not entered

if(input.equals("")) { JOptionPane.showMessageDialog(null, "You should enter any choice"); continue; }

// check value is integer or not try { choice = Integer.parseInt(input); } catch(NumberFormatException e) { JOptionPane.showMessageDialog(null, "Your Choice is not a Number\nEnter Again"); continue; }

int found = 0; int deleted = 0; switch (choice) { case 1:

String name = getInput("Enter Student Name:"); if(name.equals("invalid")){ break; } String rollNum = getInput("Enter Student Roll Number:"); if(rollNum.equals("invalid")){ break; } String phone = getInput("Enter Student Ph. Number: (integer only)"); if(phone.equals("invalid")){ break;

for (int i=0; i< students.size(); i++) { Student p = (Student)students.get(i);

if ( rollNum.equals(p.getStudentRollNumber() )) { JOptionPane.showMessageDialog(null, "Student alreay exist"); found++; } }

if(found == 0){ // instantiating studendent object with the help of parametrized constructor Student std = new Student(name, rollNum, phoneNum,program, status); students.add(std); // add student objec to arraylist } break; case 2:

str = JOptionPane.showInputDialog("Enter the Roll Number of Student to Search");

if(str == null) { break; } str = str.replaceAll("\s", ""); if(str.equals("")){ JOptionPane.showMessageDialog(null, "You should give input value"); break;

for (int i=0; i< students.size(); i++) { Student p = (Student)students.get(i);

if ( str.equals(p.getStudentRollNumber() )) { p.studentInfo(); found++; }

} if(found == 0 ) { JOptionPane.showMessageDialog(null, "Student not Found for Roll Number " + str ); }

break; case 3:

str = JOptionPane.showInputDialog("Enter Roll Number of Student to Delete ");

if(str == null) { break; } str = str.replaceAll("\s", ""); if(str.equals("")){ JOptionPane.showMessageDialog(null, "You should give input value"); break; }

for (int i=0; i< students.size(); i++) {

if(str.equals("")){ JOptionPane.showMessageDialog(null, "You should give input value"); break; }

for (int i=0; i< students.size(); i++) { Student p = (Student)students.get(i);

if ( str.equals(p.getStudentRollNumber() )) { p.addProject(); found++; } } if(found == 0 ) { JOptionPane.showMessageDialog(null, "Student not Found\nFirst add Student then You can add projects of Student" ); } break; case 5: str = JOptionPane.showInputDialog("Enter the Roll Number of Student to Find Projects"); if(str == null) { break; } str = str.replaceAll("\s", ""); if(str.equals("")){ JOptionPane.showMessageDialog(null, "You should give input value"); break; }

for (int i=0; i< students.size(); i++) {

Student p = (Student)students.get(i);

if ( str.equals(p.getStudentRollNumber() )) { p.searchProject(str); found++; } } if(found == 0 ) { JOptionPane.showMessageDialog(null, "Student not Found" ); } break; case 6: str = JOptionPane.showInputDialog("Enter the Roll Number of Student to Delete Projects"); if(str == null) { break; } str = str.replaceAll("\s", ""); if(str.equals("")){ JOptionPane.showMessageDialog(null, "You should give input value"); break; }

for (int i=0; i< students.size(); i++) { Student p = (Student)students.get(i);

if ( str.equals(p.getStudentRollNumber() )) { if(p.deleteProject(str) == false) {

JOptionPane.showMessageDialog(null, "No Project found from Student " + str + " for Deletion" );

Common Mistakes & Explanation:

Mistake 1: Student were unable to handle exception Explanation: Students are unable to manage and handle exceptions (For example managing cancel key hit and invalid value format)

  1. Most of students are unable to handle cancel key event. The input dialog returns null if user will hit cancel key. You can easily handle it with the help of if-else statements. For example, this code is handling the cancel key event temp = JOptionPane.showInputDialog(message);

// if cancel key pressed if(temp == null) { temp = "invalid"; // close the program }

  1. Some students are unable to handle invalid value exception. For example admin entered abc for phone number. You can easily handle it with the help

Projects (Project.java)

Students (Student.java)

Manage Students Information (Driver.java)

Projects information

Student’s information ArrayList to hold Project Objects

ArrayList to hold Student Objects

Hold Project objects in array list, which is member of Student class.

Hold Student objects in array list, which is member of Driver class.

of try-catch block. This code is properly handling invalid value format.

String phone = getInput("Enter Student Ph. Number: (integer only)"); long phoneNum;

try { phoneNum = Long.parseLong(phone); } catch(NumberFormatException e) { JOptionPane.showMessageDialog(null, "Your Choice is not a Number"); break; }