What's new

Pa help java scanner array

Block_MC

Eternal Poster
Joined
Apr 29, 2018
Posts
349
Solutions
1
Reaction
64
Points
292
Mga boss pa help po pano po i set yung command na
add,10001,Jay,20
bale iisa lang lahat into 1 line?


ito po code ko
Java:
package College;

import java.util.Scanner;

public class studentMenu {
    public static void showStudentMenu(){
        studentMethod sm = new studentMethod();
        
        Student record = new Student();
        Scanner input = new Scanner(System.in);
        
        String option;
        
        do {
            studMenu();
            option = input.nextLine();

            // Switch case
            switch (option) {

            // Case 1
            case "add":

                // Display message
                
                int idNumber = input.nextInt();
                input.nextLine();
                String name = input.nextLine();
                int age = input.nextInt();
                input.nextLine();

                // Create record object and pass constructor
                // parameters.
                record = new Student(name, idNumber,age);
                // Call add() record
                sm.add(record);
                record.listHeader();
                System.out.println(record.toString());

                // Break statement used to terminate program
                // from here only once it entered this case
                break;

            // Case 2
            case "delete":

                // Display message
                System.out.print(
                    "What is the Student id number ? ");
                int rId = input.nextInt();

                // Invoke remove/delete record
                sm.delete(rId);

                break;

            // Case 3
            case "update":

                // Display message
                System.out.print(
                    "What is the Student id number? ");

                int rIdNo = input.nextInt();
                sm.update(rIdNo, input);

                break;

            // Case 4
            case "search":

                // Display message
                System.out.print(
                    "What is the Student id ? ");
                int bookId = input.nextInt();

                if (!sm.find(bookId)) {
                    System.out.println(
                        "Student id does not exist\n");
                }

                break;

            // Case 5
            case "all":
                sm.display();
                break;

            // Case 6
            case "exit":
                mainMenu.showMainMenu();

                break;

            // Case 7: Default case
            // If none above case executes
            default:

                // Print statement
                System.out.println("\nInvalid input\n");
                break;
            }
        }

        // Checking condition
        while (option != "0");
    }
    
    public static void studMenu() {
        // Printing statements displaying menu on console
        System.out.println("MENU");
        System.out.println("1: Add Student            =        add,1001,Jayson,19");
        System.out.println("2: Delete Student        =");
        System.out.println("3: Update Student        =");
        System.out.println("4: Search Student        =");
        System.out.println("5: Display Students        =");
        System.out.println("9: Stop program            =        exit");
        System.out.print("Enter your selection: ");
    }

}
 
Last edited:
string ba to paps? printing string in one line? kung oo, search mo lang string concatenation kung pano gawin
 

Similar threads

Back
Top