So I created a class called student and I wanted to define myself using a scanner to fullfill all the parameters i.e Age name etc and I got a problem when it gets to fullfill one parameter. I dont't know why when I enter the gpa it automatically go to Age by skiping the Major. So I guess I've a problem when I use the scanner :/
Thanks in advance.
Here's the code ...
import java.util.Scanner;
public class ClassObject {
public static void main(String[] args) {
Student a = new Student();
Scanner student = null;
try {
student = new Scanner(System.in);
System.out.println("First Name --> ");
a.firstName = student.nextLine();
System.out.println("Last Name --> ");
a.lastName = student.nextLine();
System.out.println("GPA --> ");
a.gpa = student.nextDouble();
System.out.println("Major --> ");
a.major = student.nextLine();
System.out.println("Age --> ");
a.age = student.nextInt();
System.out.println("Are you on probation --> ");
a.onProbation = student.nextBoolean();
} finally {
if(student != null)
{
student.close();
}
}
}
}
Here's is the student class
public class Student {
String firstName;
String lastName;
double gpa;
String major;
int age;
boolean onProbation;
}