☕ Java Pa help kung ano po ang main reason ng error

Status
Not open for further replies.

PHC-Shade

Honorary Poster
Code:
package admissionz;

import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.InputMismatchException;
import java.util.Random;
import java.util.Scanner;

class Students {
    String name;
    int age;
    String address;
    String courseIntended;
    double gpa;

    public Students(String name, int age, String address, String courseIntended, double gpa) {
        this.name = name;
        this.age = age;
        this.address = address;
        this.courseIntended = courseIntended;
        this.gpa = gpa;
    }
}

public class Main {
    private ArrayList<Students> students = new ArrayList<>();
    private String[] courses = {"BSCS", "BSIT", "BSChem", "Nursing"};
    private Scanner input = new Scanner(System.in);
    private static final double REQUIRED_GPA = 93.0;
    int year = 2024;
    int month = 4;
    int score = -1;

    public static void main(String[] args) {
        Main mainApp = new Main();
        mainApp.run();
    }

    public void run() {
        System.out.println("| Thank you for Checking on Biglang Gwapo University |");
        System.out.println("Here are the offered Courses: " + Arrays.toString(courses));
        System.out.println("----------------------------");   

        String answer;

        do {   
            System.out.print("Would you like to register? (Yes or No): ");
            answer = input.nextLine().trim().toLowerCase();

            System.out.println("----------------------------");   

            switch (answer) {
                case "yes":
                    studentReg();
                    break;
                case "no":
                    System.out.println("Thank you! Have a great day!");
                    input.close();
                    break;
                default:
                    System.out.println("Invalid input. Please enter Yes or No.");
            }
        } while (!answer.equals("yes") && !answer.equals("no"));
        
        input.close();

    public void studentReg() {
        String info = "Required Info: Name, Age, Address, Course Intended, and GPA";
        boolean detailsCorrect = false;

        while (!detailsCorrect) {
            System.out.println(info);
            System.out.println("----------------------------");   
            System.out.print("Name: ");
            String name = input.nextLine();

            int age = 0;
            boolean validAge = false;

            while (!validAge) {
                System.out.print("Age: ");
                if (input.hasNextInt()) {
                    age = input.nextInt();
                    if (age < 15 || age > 100) {
                        System.out.println("Invalid Age Range. Please enter an age between 15 and 100.");
                    } else {
                        validAge = true;
                    }
                } else {
                    System.out.println("Please enter a valid Age.");
                }
                input.nextLine();
            }

            System.out.print("Address: ");
            String address = input.nextLine();

            boolean validCourse = false;
            String ci = "";
            while (!validCourse) {
                System.out.print("Course Intended: ");
                ci = input.nextLine();

                for (String course : courses) {
                    if (ci.equalsIgnoreCase(course)) {
                        validCourse = true;
                        break;
                    }
                }
                if (!validCourse) {
                    System.out.println("Invalid Course Input. Please select from the offered courses.");
                }
            }

            double gpa;
            while (true) {
                System.out.print("GPA: ");
                if (input.hasNextDouble()) {
                    gpa = input.nextDouble();
                    if (gpa < 0 || gpa > 100) {
                        System.out.println("Please enter a GPA between 0 and 100.");
                        continue;
                    }
                    break;
                } else {
                    System.out.println("Enter a valid GPA.");
                    input.nextLine();
                }
            }


            input.nextLine();

            System.out.println("----------------------------");

            // CONFIRMING DETAILS
            System.out.println("Please double-check your details:");
            System.out.printf("Name: %s\nAge: %d\nAddress: %s\nCourse Intended: %s\nGPA: %.2f\n",
                              name, age, address, ci, gpa);

            System.out.print("Are the information correct? (Yes or No): ");
            String response = input.nextLine().trim();

            if (response.equalsIgnoreCase("Yes")) {
                detailsCorrect = true;

            
                students.add(new Students(name, age, address, ci, gpa));

                System.out.println("----------------------------");

            
                System.out.println("Thanks for applying. Please wait while we verify your details...");

                try {
                    Thread.sleep(2000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }

                System.out.println("----------------------------");

          
                if (gpa >= REQUIRED_GPA) {
                    System.out.println("Congratulations! You are eligible to take the entrance exam.");   
                } else {
                    System.out.println("Thank you for applying. Unfortunately, your GPA does not meet the required 93. We wish you the best in your future endeavors.");
                }
            } else {
                System.out.println("Please re-enter your details.");
            }
        }
    }

    public void Schedule() {
            Random random = new Random();
            DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");

            System.out.println("University Admission Process");
            System.out.println("----------------------------\n");

            boolean satisfied = false;

            while (!satisfied) {
                System.out.println("Scheduling your exam.");
                try {
                    Thread.sleep(2000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
               int day = random.nextInt(30) + 1;
                LocalDate randomDate = LocalDate.of(year, month, day);
                String formattedDate = randomDate.format(formatter);

                System.out.println("Your Exam Date is " + formattedDate);
                System.out.print("Are you satisfied with your scheduled date? (Yes or No): ");
                String answer = input.nextLine();

                if (answer.equalsIgnoreCase("Yes")) {
                    satisfied = true;
                } else {
                
                    System.out.println("Scheduling a new exam date\n");
                    System.out.println("----------------------------\n");
                    
                }
            }


            while (true) {
                  System.out.println("Step 2: Input your exam score:");
                try {
                    score = input.nextInt();
            if (score < 0 || score > 100 ) {
                System.out.println("Input valid score ");
                    continue;
            }   
            break;
                } catch (InputMismatchException e) {
                    System.out.println("Invalid input. Please enter a valid number score.");
                    input.next();
                }
            }
            
            try {
                Thread.sleep(2000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            
            System.out.println("----------------------------\n");
          
            if (score>80) {
                System.out.println("Congratulations! You are qualified to be admitted to the University.");
            }else {
                    System.out.println("Sorry your score did not qualify to be admitted to this University");
                    }   
        }
 
    }
ito po ang error message
Exception in thread "main" java.lang.NoSuchMethodError: 'void admissionz.Students.<init>(java.lang.String, int, java.lang.String, java.lang.String, double)'
at admissionz.Main.studentReg(Main.java:151)
at admissionz.Main.run(Main.java:56)
at admissionz.Main.main(Main.java:38)
 
The error message you are encountering, java.lang.NoSuchMethodError: 'void admissionz.Students.<init>(java.lang.String, int, java.lang.String, java.lang.String, double)', indicates that there is a problem related to the constructor of the Students class.

Looking at your code, the constructor in the Students class seems to be correctly defined with the parameters (String name, int age, String address, String courseIntended, double gpa). However, the error suggests that there might be a mismatch between the constructor definition and the way it is being called in your Main class.

In your Main class, inside the studentReg() method at line 151, you are creating a new Students object like this:

Java:
students.add(new Students(name, age, address, ci, gpa));

This is where the error is occurring. The error message is indicating that it cannot find a constructor in the Students class that matches the parameters you are passing when creating a new Students object.

To resolve this issue, you need to make sure that the constructor call matches the constructor definition in the Students class. In this case, ensure that the constructor call has the correct number of parameters and the correct data types in the correct order.

You can check the constructor call and the constructor definition to ensure they align properly. If you have made any recent changes to the Students class constructor signature, make sure to update all constructor calls accordingly.

Once you correct the constructor call to match the constructor definition, the NoSuchMethodError should be resolved.
 
The error message you are encountering, java.lang.NoSuchMethodError: 'void admissionz.Students.<init>(java.lang.String, int, java.lang.String, java.lang.String, double)', indicates that there is a problem related to the constructor of the Students class.

Looking at your code, the constructor in the Students class seems to be correctly defined with the parameters (String name, int age, String address, String courseIntended, double gpa). However, the error suggests that there might be a mismatch between the constructor definition and the way it is being called in your Main class.

In your Main class, inside the studentReg() method at line 151, you are creating a new Students object like this:

Java:
students.add(new Students(name, age, address, ci, gpa));

This is where the error is occurring. The error message is indicating that it cannot find a constructor in the Students class that matches the parameters you are passing when creating a new Students object.

To resolve this issue, you need to make sure that the constructor call matches the constructor definition in the Students class. In this case, ensure that the constructor call has the correct number of parameters and the correct data types in the correct order.

You can check the constructor call and the constructor definition to ensure they align properly. If you have made any recent changes to the Students class constructor signature, make sure to update all constructor calls accordingly.

Once you correct the constructor call to match the constructor definition, the NoSuchMethodError should be resolved.
already correctedd na po ang code pero same error parin
Code:
package admissionz;

import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.InputMismatchException;
import java.util.Random;
import java.util.Scanner;

class Students {
    String name;
    int age;
    String address;
    String ci;
    double gpa;

    public Students(String name, int age, String address, String courseIntended, double gpa) {
        this.name = name;
        this.age = age;
        this.address = address;
        this.ci = courseIntended;
        this.gpa = gpa;
    }
}

public class Main {
    private ArrayList<Students> students = new ArrayList<>();
    private String[] courses = {"BSCS", "BSIT", "BSChem", "Nursing"};
    private Scanner input = new Scanner(System.in);
    private static final double REQUIRED_GPA = 93.0;
    int year = 2024;
    int month = 4;
    int score = -1;

    public static void main(String[] args) {
        Main mainApp = new Main();
        mainApp.run();
    }

    public void run() {
        System.out.println("| Thank you for Checking on Biglang Gwapo University |");
        System.out.println("Here are the offered Courses: " + Arrays.toString(courses));
        System.out.println("----------------------------");   

        String answer;

        do {   
            System.out.print("Would you like to register? (Yes or No): ");
            answer = input.nextLine().trim().toLowerCase();

            System.out.println("----------------------------");   

            switch (answer) {
                case "yes":
                    studentReg();
                    break;
                case "no":
                    System.out.println("Thank you! Have a great day!");
                    input.close();
                    break;
                default:
                    System.out.println("Invalid input. Please enter Yes or No.");
            }
        } while (!answer.equals("yes") && !answer.equals("no"));
    }


    public void studentReg() {
        String info = "Required Info: Name, Age, Address, Course Intended, and GPA";
        boolean detailsCorrect = false;

        while (!detailsCorrect) {
            System.out.println(info);
            System.out.println("----------------------------");   
            System.out.print("Name: ");
            String name = input.nextLine();

            int age = 0;
            boolean validAge = false;

            while (!validAge) {
                System.out.print("Age: ");
                if (input.hasNextInt()) {
                    age = input.nextInt();
                    if (age < 15 || age > 100) {
                        System.out.println("Invalid Age Range. Please enter an age between 15 and 100.");
                    } else {
                        validAge = true;
                    }
                } else {
                    System.out.println("Please enter a valid Age.");
                }
                input.nextLine();
            }

            System.out.print("Address: ");
            String address = input.nextLine();

            boolean validCourse = false;
            String ci = "";
            while (!validCourse) {
                System.out.print("Course Intended: ");
                ci = input.nextLine();

                for (String course : courses) {
                    if (ci.equalsIgnoreCase(course)) {
                        validCourse = true;
                        break;
                    }
                }
                if (!validCourse) {
                    System.out.println("Invalid Course Input. Please select from the offered courses.");
                }
            }

            double gpa;
            while (true) {
                System.out.print("GPA: ");
                if (input.hasNextDouble()) {
                    gpa = input.nextDouble();
                    if (gpa < 0 || gpa > 100) {
                        System.out.println("Please enter a GPA between 0 and 100.");
                        continue;
                    }
                    break;
                } else {
                    System.out.println("Enter a valid GPA.");
                    input.nextLine();
                }
            }


            input.nextLine();

            System.out.println("----------------------------");

      
            System.out.println("Please double-check your details:");
            System.out.printf("Name: %s\nAge: %d\nAddress: %s\nCourse Intended: %s\nGPA: %.2f\n",
                              name, age, address, ci, gpa);

            System.out.print("Are the information correct? (Yes or No): ");
            String response = input.nextLine().trim();

            if (response.equalsIgnoreCase("Yes")) {
                detailsCorrect = true;

            
                students.add(new Students(name, age, address, ci, gpa));

                System.out.println("----------------------------");

            
                System.out.println("Thanks for applying. Please wait while we verify your details...");

                try {
                    Thread.sleep(2000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }

                System.out.println("----------------------------");

          
                if (gpa >= REQUIRED_GPA) {
                    System.out.println("Congratulations! You are eligible to take the entrance exam.");   
                } else {
                    System.out.println("Thank you for applying. Unfortunately, your GPA does not meet the required 93. We wish you the best in your future endeavors.");
                }
            } else {
                System.out.println("Please re-enter your details.");
            }
        }
    }

    public void Schedule() {
            int year = 2024;
            int month = 4;
            int score = -1;
            Random random = new Random();
            DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");

            System.out.println("University Admission Process");
            System.out.println("----------------------------\n");

            boolean satisfied = false;

            while (!satisfied) {
                System.out.println("Scheduling your exam.");
                try {
                    Thread.sleep(2000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
               int day = random.nextInt(30) + 1;
                LocalDate randomDate = LocalDate.of(year, month, day);
                String formattedDate = randomDate.format(formatter);

                System.out.println("Your Exam Date is " + formattedDate);
                System.out.print("Are you satisfied with your scheduled date? (Yes or No): ");
                String answer = input.nextLine();

                if (answer.equalsIgnoreCase("Yes")) {
                    satisfied = true;
                } else {
                
                    System.out.println("Scheduling a new exam date\n");
                    System.out.println("----------------------------\n");
                    
                }
            }


            while (true) {
                  System.out.println("Step 2: Input your exam score:");
                try {
                    score = input.nextInt();
            if (score < 0 || score > 100 ) {
                System.out.println("Input valid score ");
                    continue;
            }   
            break;
                } catch (InputMismatchException e) {
                    System.out.println("Invalid input. Please enter a valid number score.");
                    input.next();
                }
            }
            
            try {
                Thread.sleep(2000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            
            System.out.println("----------------------------\n");
          
            if (score>80) {
                System.out.println("Congratulations! You are qualified to be admitted to the University.");
            }else {
                    System.out.println("Sorry your score did not qualify to be admitted to this University");
                    }   
      
    }
    }
Exception in thread "main" java.lang.NoSuchMethodError: 'void admissionz.Students.<init>(java.lang.String, int, java.lang.String, java.lang.String, double)'
at admissionz.Main.studentReg(Main.java:150)
at admissionz.Main.run(Main.java:56)
at admissionz.Main.main(Main.java:38)
 
already correctedd na po ang code pero same error parin
Code:
package admissionz;

import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.InputMismatchException;
import java.util.Random;
import java.util.Scanner;

class Students {
    String name;
    int age;
    String address;
    String ci;
    double gpa;

    public Students(String name, int age, String address, String courseIntended, double gpa) {
        this.name = name;
        this.age = age;
        this.address = address;
        this.ci = courseIntended;
        this.gpa = gpa;
    }
}

public class Main {
    private ArrayList<Students> students = new ArrayList<>();
    private String[] courses = {"BSCS", "BSIT", "BSChem", "Nursing"};
    private Scanner input = new Scanner(System.in);
    private static final double REQUIRED_GPA = 93.0;
    int year = 2024;
    int month = 4;
    int score = -1;

    public static void main(String[] args) {
        Main mainApp = new Main();
        mainApp.run();
    }

    public void run() {
        System.out.println("| Thank you for Checking on Biglang Gwapo University |");
        System.out.println("Here are the offered Courses: " + Arrays.toString(courses));
        System.out.println("----------------------------");   

        String answer;

        do {   
            System.out.print("Would you like to register? (Yes or No): ");
            answer = input.nextLine().trim().toLowerCase();

            System.out.println("----------------------------");   

            switch (answer) {
                case "yes":
                    studentReg();
                    break;
                case "no":
                    System.out.println("Thank you! Have a great day!");
                    input.close();
                    break;
                default:
                    System.out.println("Invalid input. Please enter Yes or No.");
            }
        } while (!answer.equals("yes") && !answer.equals("no"));
    }


    public void studentReg() {
        String info = "Required Info: Name, Age, Address, Course Intended, and GPA";
        boolean detailsCorrect = false;

        while (!detailsCorrect) {
            System.out.println(info);
            System.out.println("----------------------------");   
            System.out.print("Name: ");
            String name = input.nextLine();

            int age = 0;
            boolean validAge = false;

            while (!validAge) {
                System.out.print("Age: ");
                if (input.hasNextInt()) {
                    age = input.nextInt();
                    if (age < 15 || age > 100) {
                        System.out.println("Invalid Age Range. Please enter an age between 15 and 100.");
                    } else {
                        validAge = true;
                    }
                } else {
                    System.out.println("Please enter a valid Age.");
                }
                input.nextLine();
            }

            System.out.print("Address: ");
            String address = input.nextLine();

            boolean validCourse = false;
            String ci = "";
            while (!validCourse) {
                System.out.print("Course Intended: ");
                ci = input.nextLine();

                for (String course : courses) {
                    if (ci.equalsIgnoreCase(course)) {
                        validCourse = true;
                        break;
                    }
                }
                if (!validCourse) {
                    System.out.println("Invalid Course Input. Please select from the offered courses.");
                }
            }

            double gpa;
            while (true) {
                System.out.print("GPA: ");
                if (input.hasNextDouble()) {
                    gpa = input.nextDouble();
                    if (gpa < 0 || gpa > 100) {
                        System.out.println("Please enter a GPA between 0 and 100.");
                        continue;
                    }
                    break;
                } else {
                    System.out.println("Enter a valid GPA.");
                    input.nextLine();
                }
            }


            input.nextLine();

            System.out.println("----------------------------");

      
            System.out.println("Please double-check your details:");
            System.out.printf("Name: %s\nAge: %d\nAddress: %s\nCourse Intended: %s\nGPA: %.2f\n",
                              name, age, address, ci, gpa);

            System.out.print("Are the information correct? (Yes or No): ");
            String response = input.nextLine().trim();

            if (response.equalsIgnoreCase("Yes")) {
                detailsCorrect = true;

            
                students.add(new Students(name, age, address, ci, gpa));

                System.out.println("----------------------------");

            
                System.out.println("Thanks for applying. Please wait while we verify your details...");

                try {
                    Thread.sleep(2000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }

                System.out.println("----------------------------");

          
                if (gpa >= REQUIRED_GPA) {
                    System.out.println("Congratulations! You are eligible to take the entrance exam.");   
                } else {
                    System.out.println("Thank you for applying. Unfortunately, your GPA does not meet the required 93. We wish you the best in your future endeavors.");
                }
            } else {
                System.out.println("Please re-enter your details.");
            }
        }
    }

    public void Schedule() {
            int year = 2024;
            int month = 4;
            int score = -1;
            Random random = new Random();
            DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");

            System.out.println("University Admission Process");
            System.out.println("----------------------------\n");

            boolean satisfied = false;

            while (!satisfied) {
                System.out.println("Scheduling your exam.");
                try {
                    Thread.sleep(2000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
               int day = random.nextInt(30) + 1;
                LocalDate randomDate = LocalDate.of(year, month, day);
                String formattedDate = randomDate.format(formatter);

                System.out.println("Your Exam Date is " + formattedDate);
                System.out.print("Are you satisfied with your scheduled date? (Yes or No): ");
                String answer = input.nextLine();

                if (answer.equalsIgnoreCase("Yes")) {
                    satisfied = true;
                } else {
                
                    System.out.println("Scheduling a new exam date\n");
                    System.out.println("----------------------------\n");
                    
                }
            }


            while (true) {
                  System.out.println("Step 2: Input your exam score:");
                try {
                    score = input.nextInt();
            if (score < 0 || score > 100 ) {
                System.out.println("Input valid score ");
                    continue;
            }   
            break;
                } catch (InputMismatchException e) {
                    System.out.println("Invalid input. Please enter a valid number score.");
                    input.next();
                }
            }
            
            try {
                Thread.sleep(2000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            
            System.out.println("----------------------------\n");
          
            if (score>80) {
                System.out.println("Congratulations! You are qualified to be admitted to the University.");
            }else {
                    System.out.println("Sorry your score did not qualify to be admitted to this University");
                    }   
      
    }
    }
Exception in thread "main" java.lang.NoSuchMethodError: 'void admissionz.Students.<init>(java.lang.String, int, java.lang.String, java.lang.String, double)'
at admissionz.Main.studentReg(Main.java:150)
at admissionz.Main.run(Main.java:56)
at admissionz.Main.main(Main.java:38)
The error you are encountering, java.lang.NoSuchMethodError: 'void admissionz.Students.<init>(java.lang.String, int, java.lang.String, java.lang.String, double)', can occur when there is a mismatch between the constructor definition and the constructor call in Java. Let's analyze the code you provided to identify the root cause of the issue.

Based on the provided code snippets, the constructor of the Students class is defined as follows:
Java:
public Students(String name, int age, String address, String courseIntended, double gpa) {
    this.name = name;
    this.age = age;
    this.address = address;
    this.ci = courseIntended;
    this.gpa = gpa;
}

In your studentReg() method, you are trying to create a new Students object using the constructor:
Java:
students.add(new Students(name, age, address, ci, gpa));

The error message is indicating that it cannot find a constructor in the Students class that matches the parameters you are passing when creating a new Students object.

Upon reviewing the constructor definition and the constructor call, it seems there is indeed a discrepancy in the parameter names. In the constructor, the parameter representing the course intended is named courseIntended, but in the studentReg() method, you are passing ci instead of courseIntended.

To resolve this issue, you should update the constructor call in the studentReg() method to match the parameter names in the constructor:
Java:
students.add(new Students(name, age, address, ci, gpa));

Update it to:
Java:
students.add(new Students(name, age, address, ci, gpa));

After making this change, the constructor call should align with the constructor definition, and the NoSuchMethodError should be resolved.
 
The error you are encountering, java.lang.NoSuchMethodError: 'void admissionz.Students.<init>(java.lang.String, int, java.lang.String, java.lang.String, double)', can occur when there is a mismatch between the constructor definition and the constructor call in Java. Let's analyze the code you provided to identify the root cause of the issue.

Based on the provided code snippets, the constructor of the Students class is defined as follows:
Java:
public Students(String name, int age, String address, String courseIntended, double gpa) {
    this.name = name;
    this.age = age;
    this.address = address;
    this.ci = courseIntended;
    this.gpa = gpa;
}

In your studentReg() method, you are trying to create a new Students object using the constructor:
Java:
students.add(new Students(name, age, address, ci, gpa));

The error message is indicating that it cannot find a constructor in the Students class that matches the parameters you are passing when creating a new Students object.

Upon reviewing the constructor definition and the constructor call, it seems there is indeed a discrepancy in the parameter names. In the constructor, the parameter representing the course intended is named courseIntended, but in the studentReg() method, you are passing ci instead of courseIntended.

To resolve this issue, you should update the constructor call in the studentReg() method to match the parameter names in the constructor:
Java:
students.add(new Students(name, age, address, ci, gpa));

Update it to:
Java:
students.add(new Students(name, age, address, ci, gpa));

After making this change, the constructor call should align with the constructor definition, and the NoSuchMethodError should be resolved.
Code:
package admissionz;

import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.InputMismatchException;
import java.util.Random;
import java.util.Scanner;

class Students {
    String name;
    int age;
    String address;
    String ci;
    double gpa;

    public Students(String name, int age, String address, String ci, double gpa) {
        this.name = name;
        this.age = age;
        this.address = address;
        this.ci = ci;
        this.gpa = gpa;
    }
}

public class Main {
    private ArrayList<Students> students = new ArrayList<>();
    private String[] courses = {"BSCS", "BSIT", "BSChem", "Nursing"};
    private Scanner input = new Scanner(System.in);
    private static final double REQUIRED_GPA = 93.0;
    int year = 2024;
    int month = 4;
    int score = -1;

    public static void main(String[] args) {
        Main mainApp = new Main();
        mainApp.run();
    }

    public void run() {
        System.out.println("| Thank you for Checking on Biglang Gwapo University |");
        System.out.println("Here are the offered Courses: " + Arrays.toString(courses));
        System.out.println("----------------------------");   

        String answer;

        do {   
            System.out.print("Would you like to register? (Yes or No): ");
            answer = input.nextLine().trim().toLowerCase();

            System.out.println("----------------------------");   

            switch (answer) {
                case "yes":
                    studentReg();
                    break;
                case "no":
                    System.out.println("Thank you! Have a great day!");
                    input.close();
                    break;
                default:
                    System.out.println("Invalid input. Please enter Yes or No.");
            }
        } while (!answer.equals("yes") && !answer.equals("no"));
    }


    public void studentReg() {
        String info = "Required Info: Name, Age, Address, Course Intended, and GPA";
        boolean detailsCorrect = false;

        while (!detailsCorrect) {
            System.out.println(info);
            System.out.println("----------------------------");   
            System.out.print("Name: ");
            String name = input.nextLine();

            int age = 0;
            boolean validAge = false;

            while (!validAge) {
                System.out.print("Age: ");
                if (input.hasNextInt()) {
                    age = input.nextInt();
                    if (age < 15 || age > 100) {
                        System.out.println("Invalid Age Range. Please enter an age between 15 and 100.");
                    } else {
                        validAge = true;
                    }
                } else {
                    System.out.println("Please enter a valid Age.");
                }
                input.nextLine();
            }

            System.out.print("Address: ");
            String address = input.nextLine();

            boolean validCourse = false;
            String ci = "";
            while (!validCourse) {
                System.out.print("Course Intended: ");
                ci = input.nextLine();

                for (String course : courses) {
                    if (ci.equalsIgnoreCase(course)) {
                        validCourse = true;
                        break;
                    }
                }
                if (!validCourse) {
                    System.out.println("Invalid Course Input. Please select from the offered courses.");
                }
            }

            double gpa;
            while (true) {
                System.out.print("GPA: ");
                if (input.hasNextDouble()) {
                    gpa = input.nextDouble();
                    if (gpa < 0 || gpa > 100) {
                        System.out.println("Please enter a GPA between 0 and 100.");
                        continue;
                    }
                    break;
                } else {
                    System.out.println("Enter a valid GPA.");
                    input.nextLine();
                }
            }


            input.nextLine();

            System.out.println("----------------------------");

      
            System.out.println("Please double-check your details:");
            System.out.printf("Name: %s\nAge: %d\nAddress: %s\nCourse Intended: %s\nGPA: %.2f\n",
                              name, age, address, ci, gpa);

            System.out.print("Are the information correct? (Yes or No): ");
            String response = input.nextLine().trim();

            if (response.equalsIgnoreCase("Yes")) {
                detailsCorrect = true;

            
                students.add(new Students(name, age, address, ci, gpa));

                System.out.println("----------------------------");

            
                System.out.println("Thanks for applying. Please wait while we verify your details...");

                try {
                    Thread.sleep(2000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }

                System.out.println("----------------------------");

          
                if (gpa >= REQUIRED_GPA) {
                    System.out.println("Congratulations! You are eligible to take the entrance exam.");   
                } else {
                    System.out.println("Thank you for applying. Unfortunately, your GPA does not meet the required 93. We wish you the best in your future endeavors.");
                }
            } else {
                System.out.println("Please re-enter your details.");
            }
        }
    }

    public void Schedule() {
            int year = 2024;
            int month = 4;
            int score = -1;
            Random random = new Random();
            DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");

            System.out.println("University Admission Process");
            System.out.println("----------------------------\n");

            boolean satisfied = false;

            while (!satisfied) {
                System.out.println("Scheduling your exam.");
                try {
                    Thread.sleep(2000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
               int day = random.nextInt(30) + 1;
                LocalDate randomDate = LocalDate.of(year, month, day);
                String formattedDate = randomDate.format(formatter);

                System.out.println("Your Exam Date is " + formattedDate);
                System.out.print("Are you satisfied with your scheduled date? (Yes or No): ");
                String answer = input.nextLine();

                if (answer.equalsIgnoreCase("Yes")) {
                    satisfied = true;
                } else {
                
                    System.out.println("Scheduling a new exam date\n");
                    System.out.println("----------------------------\n");
                    
                }
            }


            while (true) {
                  System.out.println("Step 2: Input your exam score:");
                try {
                    score = input.nextInt();
            if (score < 0 || score > 100 ) {
                System.out.println("Input valid score ");
                    continue;
            }   
            break;
                } catch (InputMismatchException e) {
                    System.out.println("Invalid input. Please enter a valid number score.");
                    input.next();
                }
            }
            
            try {
                Thread.sleep(2000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            
            System.out.println("----------------------------\n");
          
            if (score>80) {
                System.out.println("Congratulations! You are qualified to be admitted to the University.");
            }else {
                    System.out.println("Sorry your score did not qualify to be admitted to this University");
                    }   
      
    }
    }
updated na siya pero same error pa din
Exception in thread "main" java.lang.NoSuchMethodError: 'void admissionz.Students.<init>(java.lang.String, int, java.lang.String, java.lang.String, double)'
at admissionz.Main.studentReg(Main.java:150)
at admissionz.Main.run(Main.java:56)
at admissionz.Main.main(Main.java:38)
 
Code:
package admissionz;

import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.InputMismatchException;
import java.util.Random;
import java.util.Scanner;

class Students {
    String name;
    int age;
    String address;
    String ci;
    double gpa;

    public Students(String name, int age, String address, String ci, double gpa) {
        this.name = name;
        this.age = age;
        this.address = address;
        this.ci = ci;
        this.gpa = gpa;
    }
}

public class Main {
    private ArrayList<Students> students = new ArrayList<>();
    private String[] courses = {"BSCS", "BSIT", "BSChem", "Nursing"};
    private Scanner input = new Scanner(System.in);
    private static final double REQUIRED_GPA = 93.0;
    int year = 2024;
    int month = 4;
    int score = -1;

    public static void main(String[] args) {
        Main mainApp = new Main();
        mainApp.run();
    }

    public void run() {
        System.out.println("| Thank you for Checking on Biglang Gwapo University |");
        System.out.println("Here are the offered Courses: " + Arrays.toString(courses));
        System.out.println("----------------------------");   

        String answer;

        do {   
            System.out.print("Would you like to register? (Yes or No): ");
            answer = input.nextLine().trim().toLowerCase();

            System.out.println("----------------------------");   

            switch (answer) {
                case "yes":
                    studentReg();
                    break;
                case "no":
                    System.out.println("Thank you! Have a great day!");
                    input.close();
                    break;
                default:
                    System.out.println("Invalid input. Please enter Yes or No.");
            }
        } while (!answer.equals("yes") && !answer.equals("no"));
    }


    public void studentReg() {
        String info = "Required Info: Name, Age, Address, Course Intended, and GPA";
        boolean detailsCorrect = false;

        while (!detailsCorrect) {
            System.out.println(info);
            System.out.println("----------------------------");   
            System.out.print("Name: ");
            String name = input.nextLine();

            int age = 0;
            boolean validAge = false;

            while (!validAge) {
                System.out.print("Age: ");
                if (input.hasNextInt()) {
                    age = input.nextInt();
                    if (age < 15 || age > 100) {
                        System.out.println("Invalid Age Range. Please enter an age between 15 and 100.");
                    } else {
                        validAge = true;
                    }
                } else {
                    System.out.println("Please enter a valid Age.");
                }
                input.nextLine();
            }

            System.out.print("Address: ");
            String address = input.nextLine();

            boolean validCourse = false;
            String ci = "";
            while (!validCourse) {
                System.out.print("Course Intended: ");
                ci = input.nextLine();

                for (String course : courses) {
                    if (ci.equalsIgnoreCase(course)) {
                        validCourse = true;
                        break;
                    }
                }
                if (!validCourse) {
                    System.out.println("Invalid Course Input. Please select from the offered courses.");
                }
            }

            double gpa;
            while (true) {
                System.out.print("GPA: ");
                if (input.hasNextDouble()) {
                    gpa = input.nextDouble();
                    if (gpa < 0 || gpa > 100) {
                        System.out.println("Please enter a GPA between 0 and 100.");
                        continue;
                    }
                    break;
                } else {
                    System.out.println("Enter a valid GPA.");
                    input.nextLine();
                }
            }


            input.nextLine();

            System.out.println("----------------------------");

      
            System.out.println("Please double-check your details:");
            System.out.printf("Name: %s\nAge: %d\nAddress: %s\nCourse Intended: %s\nGPA: %.2f\n",
                              name, age, address, ci, gpa);

            System.out.print("Are the information correct? (Yes or No): ");
            String response = input.nextLine().trim();

            if (response.equalsIgnoreCase("Yes")) {
                detailsCorrect = true;

            
                students.add(new Students(name, age, address, ci, gpa));

                System.out.println("----------------------------");

            
                System.out.println("Thanks for applying. Please wait while we verify your details...");

                try {
                    Thread.sleep(2000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }

                System.out.println("----------------------------");

          
                if (gpa >= REQUIRED_GPA) {
                    System.out.println("Congratulations! You are eligible to take the entrance exam.");   
                } else {
                    System.out.println("Thank you for applying. Unfortunately, your GPA does not meet the required 93. We wish you the best in your future endeavors.");
                }
            } else {
                System.out.println("Please re-enter your details.");
            }
        }
    }

    public void Schedule() {
            int year = 2024;
            int month = 4;
            int score = -1;
            Random random = new Random();
            DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");

            System.out.println("University Admission Process");
            System.out.println("----------------------------\n");

            boolean satisfied = false;

            while (!satisfied) {
                System.out.println("Scheduling your exam.");
                try {
                    Thread.sleep(2000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
               int day = random.nextInt(30) + 1;
                LocalDate randomDate = LocalDate.of(year, month, day);
                String formattedDate = randomDate.format(formatter);

                System.out.println("Your Exam Date is " + formattedDate);
                System.out.print("Are you satisfied with your scheduled date? (Yes or No): ");
                String answer = input.nextLine();

                if (answer.equalsIgnoreCase("Yes")) {
                    satisfied = true;
                } else {
                
                    System.out.println("Scheduling a new exam date\n");
                    System.out.println("----------------------------\n");
                    
                }
            }


            while (true) {
                  System.out.println("Step 2: Input your exam score:");
                try {
                    score = input.nextInt();
            if (score < 0 || score > 100 ) {
                System.out.println("Input valid score ");
                    continue;
            }   
            break;
                } catch (InputMismatchException e) {
                    System.out.println("Invalid input. Please enter a valid number score.");
                    input.next();
                }
            }
            
            try {
                Thread.sleep(2000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            
            System.out.println("----------------------------\n");
          
            if (score>80) {
                System.out.println("Congratulations! You are qualified to be admitted to the University.");
            }else {
                    System.out.println("Sorry your score did not qualify to be admitted to this University");
                    }   
      
    }
    }
updated na siya pero same error pa din
Exception in thread "main" java.lang.NoSuchMethodError: 'void admissionz.Students.<init>(java.lang.String, int, java.lang.String, java.lang.String, double)'
at admissionz.Main.studentReg(Main.java:150)
at admissionz.Main.run(Main.java:56)
at admissionz.Main.main(Main.java:38)
The error you are facing, java.lang.NoSuchMethodError: 'void admissionz.Students.<init>(java.lang.String, int, java.lang.String, java.lang.String, double)', suggests that the JVM is still trying to find the old constructor signature of the Students class. Let's troubleshoot this issue further to ensure that the changes you made are reflected correctly.

Here are some steps you can take to address this problem:

1. Clean and Rebuild: Sometimes, residual old class files can cause such issues. Try cleaning your project and rebuilding it to ensure that the latest changes are compiled and used.

2. Check Classpath: Verify that the correct version of the class file is being used at runtime. Ensure that the compiled class file for the Students class corresponds to the updated constructor signature.

3. Restart IDE: If you are using an IDE, try restarting it to ensure that all changes are properly propagated.

4. Check Dependencies: If your project is using any external dependencies or libraries, make sure that there are no conflicts with the versions of classes being used.

5. Manual Compilation: If you are not using an IDE, try compiling the classes manually to see if the issue persists.

6. Review Code: Double-check the constructor definition in the Students class and the constructor calls in the Main class to make sure they match.

If after performing these steps you are still encountering the same error, it might be helpful to validate the build process, dependencies, and runtime environment to ensure that the correct version of the class is being used.
 
Status
Not open for further replies.

About this Thread

  • 5
    Replies
  • 403
    Views
  • 1
    Participants
Last reply from:
Unknown user

Trending Topics

Online now

Members online
1,021
Guests online
1,566
Total visitors
2,587

Forum statistics

Threads
2,273,384
Posts
28,949,110
Members
1,235,723
Latest member
xberzerker
Back
Top