0% found this document useful (0 votes)
10 views3 pages

Oop

The document contains a Java program for a school registration system where users can register as students by providing their name, age, and course. It utilizes a loop to continuously prompt the user for registration until they choose to exit. The program also includes input validation for age to ensure that only valid integers are accepted.

Uploaded by

beatboxkeane
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
10 views3 pages

Oop

The document contains a Java program for a school registration system where users can register as students by providing their name, age, and course. It utilizes a loop to continuously prompt the user for registration until they choose to exit. The program also includes input validation for age to ensure that only valid integers are accepted.

Uploaded by

beatboxkeane
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 3

package OopTest;

import codes.Student;
import java.util.*;

public class School {

public static void main(String[] args) {

Scanner scan = new Scanner(System.in);


ArrayList<Student> sd = new ArrayList<>();
int count = 0;

while (true) {

System.out.println("Do you wanna Register as a Student? Yes/No");


String s = scan.nextLine();
if (!s.equalsIgnoreCase("Yes")) {
System.out.println("EXITING PROGRAM!");
break;
}

System.out.println("Type your name: ");


String n = scan.nextLine();

System.out.println("Enter your age: ");


int a;

while(true) {
try {
a = Integer.parseInt(scan.nextLine());
break;
} catch (NumberFormatException e) {
System.out.println("Invalid input. Please enter your real Age!");
}
}

System.out.println("Enter your course: ");


String c = scan.nextLine();

Student student = new Student(n, a, c);


sd.add(student);
count++;

System.out.println("\n--- Registration Receipt ---");


System.out.println("STUDENT " + count + ":");
System.out.println("Name: " + student.getName());
System.out.println("Course: " + student.getCourse());
System.out.println("Age: " + student.getAge());
System.out.println("---------------------------");

}
scan.close();
}
}
package OopTest;

import codes.Student;
import java.util.*;

public class School {

public static void main(String[] args) {

Scanner scan = new Scanner(System.in);


ArrayList<Student> sd = new ArrayList<>();
int count = 0;

while (true) {

System.out.println("Do you wanna Register as a Student? Yes/No");


String s = scan.nextLine();
if (!s.equalsIgnoreCase("Yes")) {
System.out.println("EXITING PROGRAM!");
break;
}

System.out.println("Type your name: ");


String n = scan.nextLine();

System.out.println("Enter your age: ");


int a = 0;

while(true) {
try {
a = scan.nextInt();
scan.nextLine();
break;
} catch (InputMismatchException e) {
System.out.println("Invalid input. Please enter your real Age!");
scan.nextLine();
}
}

System.out.println("Enter your course: ");


String c = scan.nextLine();

Student student = new Student(n, a, c);


sd.add(student);
count++;

System.out.println("\n--- Registration Receipt ---");


System.out.println("STUDENT " + count + ":");
System.out.println("Name: " + student.getName());
System.out.println("Course: " + student.getCourse());
System.out.println("Age: " + student.getAge());
System.out.println("---------------------------");

}
scan.close();
}
}

You might also like