First way : student management system
package java_trainkj;
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
import java.util.Scanner;
/**
*
* @author user
*/
public class Stud {
private int rollno;
String name;
static String School_name;
String address;
String course;
static {
School_name = "Witshaper";
}
Stud() {
}
Stud Add(int l) {
Stud o = new Stud();
if (l > 1000) {
System.out.println(" over flow");
} else {
try {System.out.println("--------------------------");
Scanner s = new Scanner(System.in);
System.out.println(" Enter name :");
o.name = s.next();
System.out.println(" Enter Address :");
o.address = s.next();
System.out.println(" Enter Course :");
o.course = s.next();
System.out.println(" Enter rollno. :");
o.rollno = s.nextInt();
} catch (Exception e) {
System.out.println(e);
e.getMessage();
}
}
return (o);
}
void search(int rollno, int l, Stud s[]) {
for (int i = 0; i < l; i++) {
if (s[i].rollno == rollno) {
s[i].display(s[i]);
}
}
}
boolean delete(int rollno, Stud o[], int l) {
boolean t = false;
for (int i = 0; i < l; i++) {
if (rollno == o[i].rollno) {
for (int j = i; j < l - 1; j++) {
o[j] = o[j + 1];
}
t = true;
return (t);
}
}
return (t);
}
boolean update(int rollno, Stud obj[], int l) {
boolean t = false;
for (int i = 0; i < l; i++) {
if (rollno == obj[i].rollno) {
try {System.out.println("--------------------------");
Scanner s = new Scanner(System.in);
System.out.println(" Enter name :");
obj[i].name = s.next();
System.out.println(" Enter Address :");
obj[i].address = s.next();
System.out.println(" Enter Course :");
obj[i].course = s.next();
t = true;
return (t);
} catch (Exception e) {
System.out.println(e);
e.getMessage();
}
}
}
return (t);
}
void display(Stud s) {
System.out.println("--------------------------");
System.out.println(" name :" + s.name);
System.out.println(" Address :" + s.address);
System.out.println(" course :" + s.course);
System.out.println(" rollno. :" + s.rollno);
}
void show(int l,Stud s[]) {
for(int i=0;i<l;i++){
System.out.println("--------------------------");
System.out.println(" Name :" + s[i].name);
System.out.println(" Address :" + s[i].address);
System.out.println(" course :" + s[i].course);
System.out.println(" rollno. :" + s[i].rollno);
}
}
public static void main(String args[]) {
Stud obj[] = new Stud[1000];
Scanner s = new Scanner(System.in);
boolean f = true;
int choice;
int l = 0;
int r;
Stud o = new Stud();
do {
try {System.out.println("#### WELCOME ####");
System.out.println(" Enter your choice ");
System.out.println("1) ......Add");
System.out.println("2).......Delete");
System.out.println("3).......Search");
System.out.println("4).......Update");
System.out.println("5).......Display");
choice = s.nextInt();
try {
switch (choice) {
case 1:
obj[l] = o.Add(l);
l++;
break;
case 2:
System.out.println(" Enter rollno.for deletion ");
r = s.nextInt();
boolean b = o.delete(r, obj, l);
if (b = true) {l--;
System.out.println("Successfully deleted");
} else {
System.out.println(" rollno. not found");
}
break;
case 3:
System.out.println(" Enter rollno. to search student ");
r = s.nextInt();
o.search(r, l, obj);
break;
case 4:
System.out.println(" Enter rollno. for update");
r = s.nextInt();
boolean c = o.update(r, obj, l);
if (c = true) {
System.out.println("Successfully updated");
} else {
System.out.println(" rollno. not found");
}
break;
case 5:
o.show(l,obj);
default:
System.out.println(" Enter right choice");
}
} catch (Exception m) {
System.out.println(m);
}
} catch (Exception e) {
System.out.println(e);
}
System.out.println(" want to do more ... true/false");
f = s.nextBoolean();
} while (f);
}
}
// second way : student management system
package myproj.exceptionhandling;
import java.util.Scanner;
public class studentmanagement {
public static void main(String args[]) {
Scanner s = new Scanner(System.in);
int c, usr;
store ob = new store();
do {
System.out.println("::::MENU::::");
System.out.println("ENTER 1 FOR ADDING DETAIL");
System.out.println("ENTER 2 FOR SEARCHING");
System.out.println("ENTER 3 FOR DELETION");
System.out.println("ENTER 4 FOR UPDATION");
System.out.println("ENTER 5 TO EXIT");
int ch = s.nextInt();
switch (ch) {
case 1:
System.out.println("enter the no of entries");
usr = s.nextInt();
ob.add(usr);
break;
case 2:
ob.search();
break;
case 3:
ob.delete();
break;
case 4:
ob.update();
break;
case 5:
System.exit(0);
}
System.out.println("press any key other than 5 to do more operations else press 5 to exit");
c = s.nextInt();
} while (c != 5);
}
}
abstract class student {
protected String name[];
protected int roll[];
abstract void display();
}
class store extends student {
int usr;
Scanner s = new Scanner(System.in);
int i = 0, c = 0, r = 0;
store() {
roll = new int[10];
name = new String[10];
}
public void add(int usr) {
this.usr = usr;
for (i = 0; i < usr; i++) {
System.out.println("Enter name and roll no ");
name[i] = s.next();
roll[i] = s.nextInt();
}
display();
}
public void search() {
System.out.println("Enter the roll no you want to search");
r = s.nextInt();
for (i = 0; i < roll.length; i++) {
if (roll[i] == r) {
break;
}
}
System.out.println(" ");
System.out.println(" ");
System.out.println("---DETAILS OF THE SPECIFIED STUDENT IS---");
System.out.println("NAME ROLL NO");
System.out.print(name[i]+" ");
System.out.print(roll[i]);
System.out.println(" ");
System.out.println(" ");
System.out.println(" ");
}
public void delete() {
System.out.println("Enter the rollno to be deleted");
r = s.nextInt();
for (i = 0; i < roll.length; i++) {
if (roll[i] == r) {
roll[i] = 0;
name[i] = " ";
}
}
display();
}
public void update() {
System.out.println("Enter the rollno to be updated");
r = s.nextInt();
for (i = 0; i < roll.length; i++) {
if (roll[i] == r) {
System.out.println("Enter the new name and roll no");
name[i] = s.next();
roll[i] = s.nextInt();
}
}
display();
}
@Override
void display() {
System.out.println("----THE UPDATED RECORDS OF STUDENTS ARE----");
System.out.println("NAME ROLL NO");
for (i = 0; i < roll.length; i++) {
if(roll[i]!=0)
{
System.out.print(name[i]+" ");
System.out.print(roll[i]);
System.out.println(" ");
}
}
}
}
package java_trainkj;
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
import java.util.Scanner;
/**
*
* @author user
*/
public class Stud {
private int rollno;
String name;
static String School_name;
String address;
String course;
static {
School_name = "Witshaper";
}
Stud() {
}
Stud Add(int l) {
Stud o = new Stud();
if (l > 1000) {
System.out.println(" over flow");
} else {
try {System.out.println("--------------------------");
Scanner s = new Scanner(System.in);
System.out.println(" Enter name :");
o.name = s.next();
System.out.println(" Enter Address :");
o.address = s.next();
System.out.println(" Enter Course :");
o.course = s.next();
System.out.println(" Enter rollno. :");
o.rollno = s.nextInt();
} catch (Exception e) {
System.out.println(e);
e.getMessage();
}
}
return (o);
}
void search(int rollno, int l, Stud s[]) {
for (int i = 0; i < l; i++) {
if (s[i].rollno == rollno) {
s[i].display(s[i]);
}
}
}
boolean delete(int rollno, Stud o[], int l) {
boolean t = false;
for (int i = 0; i < l; i++) {
if (rollno == o[i].rollno) {
for (int j = i; j < l - 1; j++) {
o[j] = o[j + 1];
}
t = true;
return (t);
}
}
return (t);
}
boolean update(int rollno, Stud obj[], int l) {
boolean t = false;
for (int i = 0; i < l; i++) {
if (rollno == obj[i].rollno) {
try {System.out.println("--------------------------");
Scanner s = new Scanner(System.in);
System.out.println(" Enter name :");
obj[i].name = s.next();
System.out.println(" Enter Address :");
obj[i].address = s.next();
System.out.println(" Enter Course :");
obj[i].course = s.next();
t = true;
return (t);
} catch (Exception e) {
System.out.println(e);
e.getMessage();
}
}
}
return (t);
}
void display(Stud s) {
System.out.println("--------------------------");
System.out.println(" name :" + s.name);
System.out.println(" Address :" + s.address);
System.out.println(" course :" + s.course);
System.out.println(" rollno. :" + s.rollno);
}
void show(int l,Stud s[]) {
for(int i=0;i<l;i++){
System.out.println("--------------------------");
System.out.println(" Name :" + s[i].name);
System.out.println(" Address :" + s[i].address);
System.out.println(" course :" + s[i].course);
System.out.println(" rollno. :" + s[i].rollno);
}
}
public static void main(String args[]) {
Stud obj[] = new Stud[1000];
Scanner s = new Scanner(System.in);
boolean f = true;
int choice;
int l = 0;
int r;
Stud o = new Stud();
do {
try {System.out.println("#### WELCOME ####");
System.out.println(" Enter your choice ");
System.out.println("1) ......Add");
System.out.println("2).......Delete");
System.out.println("3).......Search");
System.out.println("4).......Update");
System.out.println("5).......Display");
choice = s.nextInt();
try {
switch (choice) {
case 1:
obj[l] = o.Add(l);
l++;
break;
case 2:
System.out.println(" Enter rollno.for deletion ");
r = s.nextInt();
boolean b = o.delete(r, obj, l);
if (b = true) {l--;
System.out.println("Successfully deleted");
} else {
System.out.println(" rollno. not found");
}
break;
case 3:
System.out.println(" Enter rollno. to search student ");
r = s.nextInt();
o.search(r, l, obj);
break;
case 4:
System.out.println(" Enter rollno. for update");
r = s.nextInt();
boolean c = o.update(r, obj, l);
if (c = true) {
System.out.println("Successfully updated");
} else {
System.out.println(" rollno. not found");
}
break;
case 5:
o.show(l,obj);
default:
System.out.println(" Enter right choice");
}
} catch (Exception m) {
System.out.println(m);
}
} catch (Exception e) {
System.out.println(e);
}
System.out.println(" want to do more ... true/false");
f = s.nextBoolean();
} while (f);
}
}
// second way : student management system
package myproj.exceptionhandling;
import java.util.Scanner;
public class studentmanagement {
public static void main(String args[]) {
Scanner s = new Scanner(System.in);
int c, usr;
store ob = new store();
do {
System.out.println("::::MENU::::");
System.out.println("ENTER 1 FOR ADDING DETAIL");
System.out.println("ENTER 2 FOR SEARCHING");
System.out.println("ENTER 3 FOR DELETION");
System.out.println("ENTER 4 FOR UPDATION");
System.out.println("ENTER 5 TO EXIT");
int ch = s.nextInt();
switch (ch) {
case 1:
System.out.println("enter the no of entries");
usr = s.nextInt();
ob.add(usr);
break;
case 2:
ob.search();
break;
case 3:
ob.delete();
break;
case 4:
ob.update();
break;
case 5:
System.exit(0);
}
System.out.println("press any key other than 5 to do more operations else press 5 to exit");
c = s.nextInt();
} while (c != 5);
}
}
abstract class student {
protected String name[];
protected int roll[];
abstract void display();
}
class store extends student {
int usr;
Scanner s = new Scanner(System.in);
int i = 0, c = 0, r = 0;
store() {
roll = new int[10];
name = new String[10];
}
public void add(int usr) {
this.usr = usr;
for (i = 0; i < usr; i++) {
System.out.println("Enter name and roll no ");
name[i] = s.next();
roll[i] = s.nextInt();
}
display();
}
public void search() {
System.out.println("Enter the roll no you want to search");
r = s.nextInt();
for (i = 0; i < roll.length; i++) {
if (roll[i] == r) {
break;
}
}
System.out.println(" ");
System.out.println(" ");
System.out.println("---DETAILS OF THE SPECIFIED STUDENT IS---");
System.out.println("NAME ROLL NO");
System.out.print(name[i]+" ");
System.out.print(roll[i]);
System.out.println(" ");
System.out.println(" ");
System.out.println(" ");
}
public void delete() {
System.out.println("Enter the rollno to be deleted");
r = s.nextInt();
for (i = 0; i < roll.length; i++) {
if (roll[i] == r) {
roll[i] = 0;
name[i] = " ";
}
}
display();
}
public void update() {
System.out.println("Enter the rollno to be updated");
r = s.nextInt();
for (i = 0; i < roll.length; i++) {
if (roll[i] == r) {
System.out.println("Enter the new name and roll no");
name[i] = s.next();
roll[i] = s.nextInt();
}
}
display();
}
@Override
void display() {
System.out.println("----THE UPDATED RECORDS OF STUDENTS ARE----");
System.out.println("NAME ROLL NO");
for (i = 0; i < roll.length; i++) {
if(roll[i]!=0)
{
System.out.print(name[i]+" ");
System.out.print(roll[i]);
System.out.println(" ");
}
}
}
}
Thanks for sharing this good blog.This is very important and imformative
ReplyDeleteblog for Java . very interesting and useful for students
Java Online Training
Great Article
DeleteJava Project Ideas for Final Year Students
FInal Year Project Centers in Chennai
JavaScript Training in Chennai
JavaScript Training in Chennai
what is class of first way javaprogram
ReplyDeleteDevouring a number of articles on your blog, I perceived that the way you share such worthwhile information here is truly commendable. Keep up with this admirable work and continue updating.
ReplyDeleteEnglish practice App | English speaking app