Write java application with the following information:
- Class Name ; Student
- Method1: AddStudent
- Method2: Print Students
- Method 3: totalStudent
- Method 4: Delete Student
public class Main
{
public static void main(String[] args) {
Student s=new Student();
s.addStudent(0,123,"abc");
s.addStudent(0,124,"efg");
s.addStudent(0,125,"hij");
s.printStudents();
s.totalStudents();
s.deleteStudent();
s.printStudents();
s.totalStudents();
}
}
class Student{
private int [] student_id=new int[100];
private String [] student_name=new String [100];
int count=0;
public void addStudent(int i,int id,String name){
student_id[i]=id;
student_name[i]=name;
count++;
}
public void printStudents(){
for(int i=0;i<count;i++){
System.out.println("ID\tName");
System.out.println(student_id[i]+"\t"+student_name[i]);
}
}
public void totalStudents(){
System.out.println("Total number of students is "+count);
}
public void deleteStudent(){
count--;
}
}
Comments
Leave a comment