What's new
  • Welcome to PHCorner forums. Take a moment to sign up and gain unlimited access and extra privileges that guests are not entitled to, such as: All that and more! Registration is quick, simple and absolutely free. Join our community today!

Java Patulong sa mga magaling sa JAVA

raigan

Established
Joined
Apr 29, 2015
Messages
227
Reaction
33
Code:
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

class STUDENT{
   
    String Student_id;
    String last_name;
    String first_name;
    String email;

    public STUDENT(String Student_id, String last_name, String first_name, String email) {
        this.Student_id = Student_id;
        this.last_name = last_name;
        this.first_name = first_name;
        this.email = email;
    }
 
   
}



public class studentInfo {
   
    public static Scanner scanner = new Scanner(System.in);
    public static List<STUDENT> toAddStudent = new ArrayList<>();
    public static String actions;
 
    public static void main(String[] args) {
        menu();
    }
   
   
    public static void menu(){
       
        //insert the first batch of student
        inserted_student();
        System.out.println("-----STUDENT LIST-----");
        //display after the student inserted
        fetch_student();
       
        System.out.println();
       
        System.out.println("[1] Add Student");
        System.out.println("[2] Remove Student");
        System.out.println("[3] Search Student");
       
        System.out.println();
        System.out.println("Select your Action:");
        actions = scanner.next();
     
        if(actions.equals("1"))
        {insert_student();}
        else if(actions.equals("2"))
        {remove_student();}
        else if(actions.equals("3"))
        {search_student();}
    }
   
    // display the data
    public static void fetch_student(){
        int count=0;
        for(STUDENT list:toAddStudent)
        {
            count++;
            System.out.println(count+" |"+list.Student_id +" |"+ list.last_name +" |"+list.first_name +" |"+ list.email);
        }
   
    }
    //insert 4 student
    public static void inserted_student(){
       
        toAddStudent.add(new STUDENT("02-19-1239","Angcay","Barbiey Jean","BarbieyJean@gmail.com"));
        toAddStudent.add(new STUDENT("02-19-1283","Mong  ","Debby Ela   ","DebbyEla@gmail.com"));
        toAddStudent.add(new STUDENT("02-17-0413","Gulfan","Gian Jake L ","GianJakeL@gmail.com"));
        toAddStudent.add(new STUDENT("02-19-1267","Pamisa","Dale Kristan","DaleKristan@gmail.com"));
       
    }
    //insert new student
    public static void insert_student(){
       
         String id, last_name,first_name,email;
       
         System.out.println("Student Id: ");
         id =scanner.next();
         System.out.println("Lastname: ");
         last_name =scanner.next();
         System.out.println("Firstname: ");
         first_name =scanner.next();
         System.out.println("Email: ");
         email =scanner.next();
       
         toAddStudent.add(new STUDENT(id,last_name,first_name,email));
       
       
    }
    //remove a student
    public static void remove_student(){
       
         System.out.println(scanner.nextLine());
         System.out.println("Remove Student : "+scanner);
    }
    //search a student
    public static void search_student(){
        System.out.println(scanner.nextLine());
        System.out.println("StudentInfo: "+scanner);
    }
}
 

Attachments

Last edited:
ts, paki lagay po sa container para codes.
1611214687683.png
 

Attachments

16 Comments View more comments…
R
raigan
na kuha ko na po yung sa insert yung pag remove na lang po ano kaya problema gusto ko sana ma remove yung student gamit yung student id nya
Code:
}
    //remove a student
    public static void remove_student(){
        
         System.out.println("implement the code here!!..");
         System.out.println("remove the student info using student ID");
    }
    //search a student
    public static void search_student(){
        System.out.println("implement the code here!!..");
        System.out.println("search the student info using student ID");
 
ito ts, makiki try nalang po.
Test:
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

class STUDENT{
    String Student_id;
    String last_name;
    String first_name;
    String email;
    public STUDENT(String Student_id, String last_name, String first_name, String email) {
        this.Student_id = Student_id;
        this.last_name = last_name;
        this.first_name = first_name;
        this.email = email;
    }
}
public class Student_Info  {
    public static Scanner scanner = new Scanner(System.in);
    public static List<STUDENT> toAddStudent = new ArrayList<>();
    public static String actions;
    static Scanner sc = new Scanner(System.in);
    public static void main(String[] args) {
        inserted_student();
        String choice;
       do { menu();
       System.out.println("Do you want to continue? [Y/N]");
       choice = scanner.next();
       }while(choice != "n" || choice != "N");
      }
    public static void menu(){
        //insert the first batch of student
        //inserted_student();
        System.out.println("-----STUDENT LIST-----");
        //display after the student inserted
        fetch_student();
    
        System.out.println();
    
        System.out.println("[1] Add Student");
        System.out.println("[2] Remove Student");
        System.out.println("[3] Search Student");
    
        System.out.println();
        System.out.println("Select your Action:");
        actions = scanner.next();
  
        if(actions.equals("1"))
        {insert_student();}
        else if(actions.equals("2"))
        {remove_student();}
        else if(actions.equals("3"))
        {search_student();}
    }

    // display the data
    public static void fetch_student(){
        int count=0;
        for(STUDENT list:toAddStudent)
        {
            count++;
            System.out.println(count+" |"+list.Student_id +" |"+ list.last_name +" |"+list.first_name +" |"+ list.email);
        }

    }
    //insert 4 student
    public static void inserted_student(){
    
        toAddStudent.add(new STUDENT("02-19-1239","Angcay","Barbiey Jean","BarbieyJean@gmail.com"));
        toAddStudent.add(new STUDENT("02-19-1283","Mong  ","Debby Ela   ","DebbyEla@gmail.com"));
        toAddStudent.add(new STUDENT("02-17-0413","Gulfan","Gian Jake L ","GianJakeL@gmail.com"));
        toAddStudent.add(new STUDENT("02-19-1267","Pamisa","Dale Kristan","DaleKristan@gmail.com"));
    }
    //insert new student
    public static void insert_student(){
    
         String id, last_name,first_name,email;
    
         System.out.println("Student Id: ");
         id =scanner.next();
         System.out.println("Lastname: ");
         last_name =scanner.next();
         System.out.println("Firstname: ");
         first_name =scanner.next();
         System.out.println("Email: ");
         email =scanner.next();
    
         toAddStudent.add(new STUDENT(id,last_name,first_name,email));
    
    
    }
    //remove a student
    public static void remove_student(){
        boolean studentFound = false;
        System.out.println("Input Student ID: ");
        String student_id = sc.nextLine();
        for(int i = 0 ; i <toAddStudent.size(); i++) {
            if(toAddStudent.get(i).Student_id.equalsIgnoreCase(student_id)) {
                 studentFound = true;
                System.out.println("Student Found, Deleting...");
                toAddStudent.remove(i);
                System.out.println("Succesfully Deleted");
            }
        }
        if(!studentFound)
           System.out.println("Student not found");
    }
    private static void displayStudent(int index) {
            STUDENT student = toAddStudent.get(index);
            System.out.println("Student ID: " + student.Student_id);
            System.out.println("First Name: " + student.first_name);
            System.out.println("Last Name: " + student.last_name);
            System.out.println("Email: " + student.email);

        }
    //search a student
    public static void search_student(){
        boolean studentFound = false;
         System.out.println("Input Student ID: ");
         String student_id = sc.nextLine();
         for(int i = 0; i < toAddStudent.size(); i++) {
             if(toAddStudent.get(i).Student_id.equalsIgnoreCase(student_id)) {
                 studentFound = true;
                 System.out.println("Student Found!");
                displayStudent(i);     
                }
         }
         if(!studentFound)
             System.out.println("Student Not Found");
    }
}
 
Last edited:
1 Comment
R
raigan
salamat po didto TS galing nyo po magandang pang future refernce ko po ito
 

Online statistics

Members online
520
Guests online
1,652
Total visitors
2,172

Forum statistics

Threads
1,044,467
Messages
17,783,876
Members
1,503,840
Comments
888,790
Attachments
1,331,902
Profile posts
97,091
Top