I'm having difficulty executing the "LastName" portion of the code. I'm trying to have it so the program will respond with the Name of the student. Unfortunately, the IDE (Eclipse) has stated that "lastName" is a lost token, and that the token "lastName" should be deleted. I'm not sure why it accepts firstName, but lastName causes an issue. Any help would be greatly appreciated.
import java.util.Scanner; public class Student { private String studentName; private Grades studentGrades = new Grades(); public void setup(){ setStudentName(); setStudentGrades(); } private void setStudentName(){ Scanner keyboard = new Scanner(System.in); System.out.println("\nProvide Your Name in the Following Order: Lastname, Firstname"); studentName = keyboard.nextLine(); studentName = studentName.trim(); int between = studentName.indexOf(","); String lastName = studentName.substring(0, between); String firstName = studentName.substring(between+2, studentName.length()); studentName = firstName + " " lastName; } private void setStudentGrades(){ studentGrades.setup(); } public void display(){ System.out.println("\n Your Name is the Following: " + studentName); studentGrades.display(); } public double overallGrade(){ return studentGrades.average(); } }
Sorry if the post is unorganized, this is my first time posting here, and I'm not sure how to have the code recognized as Java code here.