Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp

Niall Doyle

Greenhorn
+ Follow
since Jul 14, 2009
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Niall Doyle

Yes..OK i see what you mean now i can add new Employees as I go along because the Constructor acts as containers for name, role etc...thanks for your patience again!

14 years ago
Ah ok..gotcha...I didnt realise "this" was a special variable in java, thanks again!!

"The variable, this, is used in the source code of an instance method to refer to the object that contains the method. This intent of the name, this, is to refer to "this object," the one right here that this very method is in. If x is an instance variable in the same object, then this.x can be used as a full name for that variable. If otherMethod() is an instance method in the same object, then this.otherMethod() could be used to call that method. Whenever the computer executes an instance method, it automatically sets the variable, this, to refer to the object that contains the method."


14 years ago
OK thanks guys! heres where I am now..



Latest error is:
14 years ago
OK seems to be working ok now but I feel Im not quite going about it the correct way...




Campbell, I appreciate all the tips you have given me including the indentation...I know I have a lot to learn thanks again!

However when I try
in place of


I get the error:
new Employee("Campbell Ritchie", "Bartender", 2345678, 123456.789);
^
C:\JavaPrograms\Employee.java:11: ';' expected
new Employee("Campbell Ritchie", "Bartender", 2345678, 123456.789);
^
C:\JavaPrograms\Employee.java:11: illegal start of type
new Employee("Campbell Ritchie", "Bartender", 2345678, 123456.789);
^
C:\JavaPrograms\Employee.java:11: <identifier> expected
new Employee("Campbell Ritchie", "Bartender", 2345678, 123456.789);

14 years ago
OK guys thanks for your patience, like I said Im new to this (including indentation ) but I am picking up more as I go along..




OK the error Im now getting is:

C:\JavaPrograms\Employee.java:17: invalid method declaration; return type required
public printEmpInfo() {

I hope Im not going backwards
14 years ago
Hi John thanks a lot for your help so far...
I read a bit about Constructors and I added in the line: public Employee() { in the class definition
So heres what I have now:



It still has not created my Employee.class file?? and the new errors are as follows:

C:\JavaPrograms\Employee.java:13: illegal start of expression
public static void main(String args[]) {
^
C:\JavaPrograms\Employee.java:13: illegal start of expression
public static void main(String args[]) {
^
C:\JavaPrograms\Employee.java:13: ';' expected
public static void main(String args[]) {
^
C:\JavaPrograms\Employee.java:13: ')' expected
public static void main(String args[]) {
^
C:\JavaPrograms\Employee.java:13: illegal start of expression
public static void main(String args[]) {
^
C:\JavaPrograms\Employee.java:13: ';' expected
public static void main(String args[]) {
^
C:\JavaPrograms\Employee.java:13: illegal start of expression
public static void main(String args[]) {
^
C:\JavaPrograms\Employee.java:13: ';' expected
public static void main(String args[]) {
^
C:\JavaPrograms\Employee.java:23: class, interface, or enum expected
14 years ago
Hi guys, Im new to programming in general...thanks in advance for your help:

Im using jcreator to compile the following file (Employee.java which I have saved in C:\JavaPrograms):




The errors I am getting are as follows:

C:\JavaPrograms\Employee.java:12: cannot find symbol
symbol : constructor Employee(java.lang.String,java.lang.String,int,double)
location: class Employee
Employee emp = new Employee("John Woo", "Java Programmer", 2125556347, 20000.00);
^
C:\JavaPrograms\Employee.java:14: cannot find symbol
symbol : method printEmpInfo()
location: class Employee
emp.printEmpInfo();


When I run it, should it create an Employee.class file in the same folder? Because this is not happening..any ideas? thanks!
14 years ago