I just started learning java a week ago and I'm trying to make an array with a maximum of 10 individuals.
I need to then have the first name, last name, and date of birth of a student and have it in a loop or something until they type the correct date, for example u can't enter a month of 13 because it is invalid.
There is a part where I have to confirm with the user if the information is correct, where they reply yes or no, I keep getting an error in this part and would like to know what it means.
Sorry if my English is bad it's not my first language. enter image description here
package com.company;
import java.util.Scanner;
import static com.company.ProjectCONSTANTS.*;
public class Main {
public static void main(String[] args) {
Student icsClass[] = new Student[10];
Scanner s = new Scanner(System.in);
Student st = new Student();
Boolean InputOK = true;
String sInput;
String tmpFirstName, tmpLastName;
int a1, a2, a3;
int iInput;
int counter = 0;
while (counter < 2) {
// While loop for First Name
do {
System.out.println("Please enter the first name of the student");
sInput = s.nextLine();
tmpFirstName=sInput;
if (sInput.isEmpty()) {
System.out.println(" String is left empty. Please enter your first name");
InputOK = false;
} else {
InputOK = true;
st.setFName(sInput);
//icsClass[counter].setFName(sInput);
}
} while (!InputOK);
// While loop for Last name
do {
System.out.println(" Pleas enter your last name");
sInput = s.nextLine();
if (sInput.isEmpty()) {
System.out.println(" String is left empty. Please enter your last name");
InputOK = false;
} else {
InputOK = true;
st.setlName(sInput);
//icsClass[counter].setlName(sInput);
}
} while (!InputOK);
// }
// Ask user to input year
do {
System.out.println(" Pleas enter your year of birth");
sInput = s.nextLine();
iInput = Integer.parseInt(sInput);
if (iInput < MIN_YEAR || iInput > MAX_YEAR) {
System.out.println("Not a valid year. Please input a valid Year between 1895 and 2021");
InputOK = false;
} else {
InputOK = true;
st.setYear(iInput);
//icsClass[counter].setYear(sInput);
}
} while (!InputOK);
// Ask user to input month
do {
System.out.println(" Pleas enter your month of birth");
sInput = s.nextLine();
iInput = Integer.parseInt(sInput);
if (iInput < Min_Month || iInput > MAX_MONTH) {
System.out.println("Not a valid month. Please input a valid month between 1 and 12");
InputOK = false;
} else {
InputOK = true;
st.setMonth(iInput);
//icsClass[counter].setMonth(sInput);
}
} while (!InputOK);
// ask user to input day
do {
System.out.println(" Pleas enter your day in your date of birth");
sInput = s.nextLine();
iInput = Integer.parseInt(sInput);
if (iInput < MIN_DAY || iInput > MAX_DAY) {
System.out.println("Not a valid day. Please input a valid day between 1 and 31");
InputOK = false;
} else {
InputOK = true;
st.setDay(iInput);
//icsClass[counter].setDay(sInput);
}
} while (!InputOK);
System.out.println("Student Data Saved:" );
System.out.println("Full Name :" + st.getFName() + " " + st.getLName());
System.out.println("Date of Birth :" + st.getDay() + "/" + st.getMonth() + "/" + st.getYear());
String vConfirm;
System.out.println( "Is the above information correct (yes/no) ?");
vConfirm = s.next();
if (vConfirm.equals("yes")) {
// Save the data to the array
System.out.println("Full Name :" + st.getFName());
System.out.println("array length :" + icsClass.length);
System.out.println("Full Name :" + tmpFirstName);
System.out.println("counter value is : " + counter);
//icsClass[counter].setFName(tmpFirstName);
//icsClass[counter].setlName(st.getLName());
icsClass[0].setYear(2010);
//icsClass[counter].setMonth(st.getMonth());
// icsClass[counter].setDay(st.getDay());
}
if (vConfirm.equals("no")) {
// don't change the counter and ask to re-enter the values
System.out.println (" inside no condition");
}
}
}
}