College Administration project
: Insert delete and edit student details
Java Example for student manipulations, insertion, deletion, updates and search to an arraylist
The program explains how to use java arraylist,java bean class, java enumerator and how to create a model class for a project
Main class
import com.nij.ca.view.InputClass;
public class Main {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
InputClass inputClass_ins = new InputClass();
inputClass_ins.getInput();
}
}
---------------------------------------------
Student bean : StudentBean.java
package com.nij.ca.bean;
public class StudentBean {
private String studentName = null;
private int studentRegNo =0;
public String getStudentName() {
return studentName;
}
public void setStudentName(String studentName) {
this.studentName = studentName;
}
public int getStudentRegNo() {
return studentRegNo;
}
public void setStudentRegNo(int studentRegNo) {
this.studentRegNo = studentRegNo;
}
}
-----------------------------------------
ChoiceEnum.java
package com.nij.ca.Enum;
public enum ChoiceEnum {
INSERT,VIEW,EDIT,SEARCH,DELETE,EXIT
}
------------------------------------
Inputclass.java
package com.nij.ca.view;
import java.util.List;
import java.util.Scanner;
import com.nij.ca.Enum.ChoiceEnum;
import com.nij.ca.bean.StudentBean;
public class InputClass {
StudentManipulation studentManipulation_ins = null;
Scanner scanner_ins = null;
ChoiceEnum userChoice;
public void getInput() {
scanner_ins = new Scanner(System.in);
studentManipulation_ins = new StudentManipulation();
int totalStudent =0;
do {
System.out.println("\t\t STUDENT MANIPULATION \n\n");
System.out.println(" INSERT\n VIEW\n EDIT\n SEARCH\n DELETE\n EXIT ");
System.out.println(" Enter user choice :");
try{
userChoice = userChoice.valueOf(scanner_ins.next());
}
catch(IllegalArgumentException iae)
{
System.out.println(" check the choice you entered (Caps Lock)");
}
switch (userChoice) {
case INSERT:
studentManipulation_ins.insert();
break;
case VIEW:
studentManipulation_ins.view();
break;
case EDIT:
System.out.println(" edit ..");
break;
case SEARCH:
studentManipulation_ins.searchRegNo();
break;
case DELETE:
studentManipulation_ins.delete();
break;
case EXIT:
System.exit(0);
break;
default:
break;
}
} while (userChoice != null);
}
}
---------------------------------------
StudentManipulation.java
package com.nij.ca.view;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.LinkedList;
import java.util.List;
import java.util.Scanner;
import com.nij.ca.bean.StudentBean;
public class StudentManipulation {
//List<StudentBean> studentBean_lst = null;
Collection<StudentBean> studentBean_lst = null;
Scanner scanner_ins = null;
StudentBean studentBean_ins = null;
int regNo =0;
public StudentManipulation(){
studentBean_lst = new ArrayList<StudentBean>();
//studentBean_lst = new LinkedList<StudentBean>();
}
public void insert() {
scanner_ins = new Scanner(System.in);
studentBean_ins = new StudentBean();
System.out.println(" Enter the name of the student ");
studentBean_ins.setStudentName(scanner_ins.next());
System.out.println(" Enter regno of the student ");
studentBean_ins.setStudentRegNo(scanner_ins.nextInt());
studentBean_lst.add(studentBean_ins);
System.out.println(" Data Inserted Succesfully ");
}
public void view() {
System.out.println(" \n\n\t LIST OF DATA \n ");
for(StudentBean student : studentBean_lst)
{
System.out.println("\t"+(((ArrayList<StudentBean>) studentBean_lst).indexOf(student)+1)+" :) Name :"+student.getStudentName());
System.out.println("\t"+(((ArrayList<StudentBean>) studentBean_lst).indexOf(student)+1)+" :) ID :"+student.getStudentRegNo() );
System.out.println("\n");
}
}
public void delete() {
System.out.println(" Enter the regNo to Delete ");
regNo = scanner_ins.nextInt();
String name = null;
for(StudentBean student: studentBean_lst)
{
if(student.getStudentRegNo() == regNo)
{
name = student.getStudentName();
studentBean_lst.remove(student);
}
}
System.out.println(" DATA DELETED : "+name);
}
public void searchRegNo() {
// TODO Auto-generated method stub
System.out.println("Search by regNo ");
}
}
Please copy and paste the code to your eclipse ide.
http://javabelazy.blogspot.in/
No comments:
Post a Comment
Your feedback may help others !!!