I'm new to Java, and am confused when reading other solutions to this problem. Can I get some layman's terms to how to do this in my case?
I'm making a program that will take information from a student and be able to print out a full report or print out a full name of the student.
I'm using BlueJ to write my code.
Here is what I have so far for my first class that takes in the information.
import java.util.Scanner; public class StudentData2 { public static final Scanner input = new Scanner(System.in); public static void main(String[] args){ long student_id; String firstName; String lastName; String classification; String fullGender = "none"; char gender = 'n'; double gpa = 0.0; switch (fullGender.toLowerCase()) { case("female"): gender = 'f'; break; case("male"): gender = 'm'; break; default: System.out.println("That's not a selectable gender."); } boolean isPassing; if (gpa > 2.0) { isPassing = true; }else { isPassing = false; } char averageGrade; if (gpa == 4.0) { averageGrade = 'A'; } if(gpa >= 3.0){ averageGrade = 'B'; } if (gpa >= 2.0){ averageGrade = 'C'; } if (gpa >= 1.00) { averageGrade = 'D'; }else{ averageGrade = 'F';} } } Now I want to make another class called 'StudentData2Demo', and I want it to print out some questions, and then whatever is input into the terminal, it puts that into the value of the objects in the other class.
Here is what I have so far.
import java.util.Scanner; public class StudentData2Demo{ public static void main(String[] args) { StudentData2 student = new StudentData2(); System.out.println("What is your First Name?"); student.firstName = input.next(); } } Yet, when I try to reference the 'input' scanner I made in the other class, it says it can't find that variable. This is also the same for firstName, and likely the rest when I type those in.
Help?
mainmethod and there its visibility is scoped to themainmethod, if you want greater visibility then move the scanner variable to be a class field