Ok, so here is my class
public class Student { private String name; // student name private int id; // student id //********************************************************* public void setName(String n) { this.name = n; } public void setId(int id) { this.id = id; } //********************************************************* public String getEmailAccount() { // Include "" in concatenation to convert to strings. return "" + this.name.charAt(0) + this.id + "@park.edu"; } //********************************************************* public boolean isValid() { return this.id >= 100000 && this.id <= 999999; } } // end class Student
Here is my driver
import java.util.Scanner; public class StudentDriver { public static void main(String[] args) { Scanner stdIn = new Scanner(System.in); Student student; // student object String name; // student name // Instantiate Student object and assign it to student. student = new Student(); System.out.print("Enter student name: "); name = stdIn.nextLine(); // Assign name to the student object. student.setName(); System.out.print("Enter student id: "); // In a single statement, read an int for the id value, // and assign it to the student object. name.setId()= stdIn.nextInt(); // If invalid id, execute the loop. // (Use the isValid method in the while loop heading.) while (!isValid) { System.out.print("Invalid student id - reenter: "); // In a single statement, read an int for the id value // and assign it to the student object. student.SetId()= stdIn.nextInt(); } System.out.println("\n" + name + ", your new e-mail account is: \n" + student.getEmailAccount()); // Get email account. } // end main } // end class StudentDriver
And here are my errors
C:\Users\Jennifer\Documents\school\StudentDriver.java:18: error: method setName in class Student cannot be applied to given types; student.setName(); ^ required: String found: no arguments reason: actual and formal argument lists differ in length C:\Users\Jennifer\Documents\school\StudentDriver.java:23: error: cannot find symbol name.setId()= stdIn.nextInt(); ^ symbol: method setId() location: variable name of type String C:\Users\Jennifer\Documents\school\StudentDriver.java:27: error: cannot find symbol while (!isValid) ^ symbol: variable isValid location: class StudentDriver C:\Users\Jennifer\Documents\school\StudentDriver.java:32: error: cannot find symbol student.SetId()= stdIn.nextInt(); ^ symbol: method SetId() location: variable student of type Student 4 errors Tool completed with exit code 1
I can't figure out what I'm doing wrong. The comments in the program are what I need to do and my attempt at the code is beneath them. My first issue is that I can't figure out how to set the name. I believe that I need to use the student variable name because that is what I'm trying to assign the name to. However, any way I try to modify the statement it doesn't work unless I go student.setName(name). Is that really the correct way to use the code? Doesn't that sort of negate the setName Method? Do I need to do the same with the setID?
The boolean is giving me some issues. I want to do something like while(!student.isvalid()) but will that work with the student variable name?
Hopefully I'm making some realtively simple errors, because this is driving me crazy...