I am in an Introduction to Programming class for Roane State Community College. I have read the entire chapter 3 chapter, taken the quize, and passed.
So, now I am beyond frustrated after many hours of attempting to create an Employee class file with 3 different instance variables that will then be initialized by an Employee Constructor.
The three variables are as such:
- first name (String type variable)
- last name (String type variable)
- monthly salary (double type floating variable)
The instructor provided us with some "signatures of the constructor and the methods for your reference:"
public Employee(String fName, String lName, double empSalary )
public void setFirstName( String fName )
public void setLastName( String lName )
public void setSalary(double empSalary )
public String getFirstName()
public String getLastName()
public double getSalary()
So, I have driven myself insane twice, and am once again at my wits end as I have manipulated my code, and replaced variables such as int with variations that I thought could possible yield a correct result, then changed them back, all the while consulting the Internet, threads on this site, and my textbook. Here's my code in its "Vanilla Format" before I've added any form of alternatives to its code:
/************************************************** File: 9-27.java Author: Steven Dorsey Date: Sept. 2014 Description: This is an Employee Class File **************************************************/
//Initiation the Class file first iirc
public class Employee { int FirstName, LastName, Salary; //Instance variables
// main method begins program execution
public static void main( String[] args )
{
// should introduce and initialize the constructor Employee
public Employee( String fName, String lName, double empSalary )
{
FirstName = fName;
LastName = lName;
Salary = empSalary;
}
// Below: the set and get methods
public void setFirstName( int fName ) // set the First Name
{
FirstName = fName;
}
public void setLastName( int lName ) // set the Last Name
{
LastName = lName;
}
public void setSalary( int empSalary ) // set the Employee Salary
{
Salary = empSalary;
}
public int getFirstName() // get the First Name
{
return FirstName;
}
public int getLastName() // get the Last Name
{
return LastName;
}
public int getSalary() // get the Employee Salary
{
return Salary;
}
} // End of Main
} // End of Class
(For some reason the last two lines here that close my Main and my Class file are not being included in the quotation and stuff, but you get the idea. )
Now, I believe I must first create the class Employee, and then create the Main in the Employee class file so that the Constructor can initialize the instance variables therein using the set and get commands.
What I believe should happen, is that a Command Prompt should show up and ask for first name, then retrieve it, and do so again for last name, and then salary.
However, my TextPad program does not make it past compiling thanks to the following errors being presented. These will be difficult to read unless you are forewarned there are about 14 errors, adn all start with a "> E:[DRIVE LOCATION] which is then followed with a Colon, error message, and the line of code in question with an upwards arrow pointing at the exact location, which is systematically moved by your block quotes, and there is no way for me to keep the upwards error symbol to show you where the issue occurs on every error. I've been going insane since 8:30 in the monring, and this website too is seeming to be giving me trouble with just trying to post a help message. :(
E:\Libraries\School\Intro to Programming\Programming Assignment 2\Program 2\Employee.java:16: error: illegal start of expression public Employee( String fName, String lName, double empSalary ) ^
E:\Libraries\School\Intro to Programming\Programming Assignment 2\Program 2\Employee.java:16: error: ')' expected public Employee( String fName, String lName, double empSalary ) ^
E:\Libraries\School\Intro to Programming\Programming Assignment 2\Program 2\Employee.java:16: error: illegal start of expression public Employee( String fName, String lName, double empSalary ) ^
E:\Libraries\School\Intro to Programming\Programming Assignment 2\Program 2\Employee.java:16: error: ';' expected public Employee( String fName, String lName, double empSalary ) ^
E:\Libraries\School\Intro to Programming\Programming Assignment 2\Program 2\Employee.java:16: error: not a statement public Employee( String fName, String lName, double empSalary ) ^
E:\Libraries\School\Intro to Programming\Programming Assignment 2\Program 2\Employee.java:16: error: ';' expected public Employee( String fName, String lName, double empSalary ) ^
E:\Libraries\School\Intro to Programming\Programming Assignment 2\Program 2\Employee.java:16: error: ';' expected public Employee( String fName, String lName, double empSalary ) ^
E:\Libraries\School\Intro to Programming\Programming Assignment 2\Program 2\Employee.java:23: error: illegal start of expression public void setFirstName( int fName ) // set the First Name ^
E:\Libraries\School\Intro to Programming\Programming Assignment 2\Program 2\Employee.java:23: error: illegal start of expression public void setFirstName( int fName ) // set the First Name ^
E:\Libraries\School\Intro to Programming\Programming Assignment 2\Program 2\Employee.java:23: error: ';' expected public void setFirstName( int fName ) // set the First Name ^
E:\Libraries\School\Intro to Programming\Programming Assignment 2\Program 2\Employee.java:23: error: ';' expected public void setFirstName( int fName ) // set the First Name ^
E:\Libraries\School\Intro to Programming\Programming Assignment 2\Program 2\Employee.java:28: error: illegal start of expression public void setLastName( int lName ) // set the Last Name ^
E:\Libraries\School\Intro to Programming\Programming Assignment 2\Program 2\Employee.java:28: error: illegal start of expression public void setLastName( int lName ) // set the Last Name ^
E:\Libraries\School\Intro to Programming\Programming Assignment 2\Program 2\Employee.java:28: error: ';' expected public void setLastName( int lName ) // set the Last Name ^
E:\Libraries\School\Intro to Programming\Programming Assignment 2\Program 2\Employee.java:28: error: ';' expected public void setLastName( int lName ) // set the Last Name ^
E:\Libraries\School\Intro to Programming\Programming Assignment 2\Program 2\Employee.java:33: error: illegal start of expression public void setSalary( int empSalary ) // set the Employee Salary ^
E:\Libraries\School\Intro to Programming\Programming Assignment 2\Program 2\Employee.java:33: error: illegal start of expression public void setSalary( int empSalary ) // set the Employee Salary ^
E:\Libraries\School\Intro to Programming\Programming Assignment 2\Program 2\Employee.java:33: error: ';' expected public void setSalary( int empSalary ) // set the Employee Salary ^
E:\Libraries\School\Intro to Programming\Programming Assignment 2\Program 2\Employee.java:33: error: ';' expected public void setSalary( int empSalary ) // set the Employee Salary ^
E:\Libraries\School\Intro to Programming\Programming Assignment 2\Program 2\Employee.java:38: error: illegal start of expression public int getFirstName() // get the First Name ^
E:\Libraries\School\Intro to Programming\Programming Assignment 2\Program 2\Employee.java:38: error: ';' expected public int getFirstName() // get the First Name ^
E:\Libraries\School\Intro to Programming\Programming Assignment 2\Program 2\Employee.java:43: error: illegal start of expression public int getLastName() // get the Last Name ^
E:\Libraries\School\Intro to Programming\Programming Assignment 2\Program 2\Employee.java:43: error: ';' expected public int getLastName() // get the Last Name ^
E:\Libraries\School\Intro to Programming\Programming Assignment 2\Program 2\Employee.java:48: error: illegal start of expression public int getSalary() // get the Employee Salary ^
E:\Libraries\School\Intro to Programming\Programming Assignment 2\Program 2\Employee.java:48: error: ';' expected public int getSalary() // get the Employee Salary ^
25 errors
Tool completed with exit code 1
Ultimately, the first error says public is not a valid start of expression for declaring the constructor, adn teh rest follow in declaring that I need parenthesis where parenthesis do not go, and semicolons where tehy do not go (after an instance variable, or int command, or whatever), and they all say how my exact code here requires some code that eimplies something unrelated to the parameters that follow a constructor, or the set/get command parameters. :\
Now, if I remove public static void main( String[] args ) from the code entirely, and just declare a class file, then a constructor with the instance variables and commands, it will compile the Java file just fine. My only issue then, is that the Command Prompt will demand I include a main. And upon including a main, all 14-26 of those errors occur to everything relating to the constructor, instance variables, and commands.
I'm sure that I won't get this program done by tomorrow now. :(
main(), and the other functions. - musical_coder