473,324 Members | 2,567 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,324 software developers and data experts.

Java Assignment

Good Morning Guys! -- i printed the 65 page tutorial at work EXCELLENT HELP! ...

I have to write an Employee.class which grabs a (string first name, string last name, string salary) also is salary is below 0.0 - set it to = 0...

is this correct?


"//Lab4 - Employee.java
//Create a Java Class for storing employee information

public class employee
{
private String firstname; //saves first name
private String lastname; //saves lastname for input
private double salary; //saves salary for input

public employee( String firstname, String lastname, double salary) //begin constructor
{
firstname = firstname;
lastname = lastname;
salary = salary;
}

public String getfirstname()
{
return firstname;
}

public void setfirstname(String firstname)
{
firstname = firstname; //is this neccessary? =)
}
public String getlastname()
{
return lastname;

}
public void setlastname(String lastname)
{
lastname = lastname;
}
public double getsalary()
{
return salary;
}
public void setsalary(double salary)
{
if(salary < 0)
{
salary = 0;
}
}
}"
Nov 16 '07 #1
10 1614
JosAH
11,448 Expert 8TB
public void setfirstname(String firstname)
{
firstname = firstname; //is this neccessary? =)
}
That is not necessary; it's wrong: it sets the parameter 'firstname' to itself which
is a useless operation; change the assignment to:
Expand|Select|Wrap|Line Numbers
  1. this.firstname= firstname;
  2.  
You'll see the same problem over and over again in your code.

kind regards,

Jos
Nov 16 '07 #2
That is not necessary; it's wrong: it sets the parameter 'firstname' to itself which
is a useless operation; change the assignment to:
Expand|Select|Wrap|Line Numbers
  1. this.firstname= firstname;
  2.  
You'll see the same problem over and over again in your code.

kind regards,

Jos
Do'h! - no wonder i was recieving errors :)
alright, so if i use 'this.lastname = lastname ; that's correct?

what does 'this' mean by definition when used in java?
Nov 16 '07 #3
Do'h! - no wonder i was recieving errors :)
alright, so if i use 'this.lastname = lastname ; that's correct?

what does 'this' mean by definition when used in java?

btw : when i compile and then execute - i am recieving ::
"java.lang.NoClassDefFoundError: Lab4/employee (wrong name: employee)
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java :620)
at java.security.SecureClassLoader.defineClass(Secure ClassLoader.java:124)
at java.net.URLClassLoader.defineClass(URLClassLoader .java:260)
at java.net.URLClassLoader.access$100(URLClassLoader. java:56)
at java.net.URLClassLoader$1.run(URLClassLoader.java: 195)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.j ava:188)
at java.lang.ClassLoader.loadClass(ClassLoader.java:3 06)
at sun.misc.Launcher$AppClassLoader.loadClass(Launche r.java:268)
at java.lang.ClassLoader.loadClass(ClassLoader.java:2 51)
at java.lang.ClassLoader.loadClassInternal(ClassLoade r.java:319)
Exception in thread "main" "


is that just due to the fact its a class with no action?
Nov 16 '07 #4
JosAH
11,448 Expert 8TB
btw : when i compile and then execute - i am recieving ::
"java.lang.NoClassDefFoundError: Lab4/employee (wrong name: employee)
I assume your class compiled fine then. Your class is named 'employee', not
'Lab4/employee'. Go to the directory where your employee class file is stored
and type 'java -cp . employee'.

The '-cp .' flag tells the jvm to search for .class files in the current directory.
Don't think you're ready now because that class doesn't contain a method named
public static void main(String[] args) so it still won't run but you'll get another
error message.

kind regards,

Jos
Nov 16 '07 #5
I assume your class compiled fine then. Your class is named 'employee', not
'Lab4/employee'. Go to the directory where your employee class file is stored
and type 'java -cp . employee'.

The '-cp .' flag tells the jvm to search for .class files in the current directory.
Don't think you're ready now because that class doesn't contain a method named
public static void main(String[] args) so it still won't run but you'll get another
error message.

kind regards,

Jos
ohh, i know, thats the next step i believe....i need to create an app with a method and all that stuff, called employeetest.java -- that pulls FROM that java class...


Desktop\Lab4>java -cp . employee
Exception in thread "main" java.lang.NoSuchMethodError: main
Nov 16 '07 #6
JosAH
11,448 Expert 8TB
ohh, i know, thats the next step i believe....i need to create an app with a method and all that stuff, called employeetest.java -- that pulls FROM that java class...


Desktop\Lab4>java -cp . employee
Exception in thread "main" java.lang.NoSuchMethodError: main
Yep, as I wrote: there's no main method in that class. The jvm complains about it.

kind regards,

Jos
Nov 16 '07 #7
Yep, as I wrote: there's no main method in that class. The jvm complains about it.

kind regards,

Jos

alright maybe i am going about this incorrectly??
//Lab4 - Employee.java
//Create a Java Class for storing employee information

public class employee
{
private String firstname; //saves first name
private String lastname; //saves lastname for input
private double salary; //saves salary for input

public employee( String firstname, String lastname, double salary) //begin constructor
{
firstname = firstname;
lastname = lastname;
salary = salary;
}

public String getfirstname()
{
return firstname;
}

public void setfirstname(String firstname)
{
this.firstname = firstname; //is this neccessary? =)
}
public String getlastname()
{
return lastname;

}
public void setlastname(String lastname)
{
this.lastname = lastname;
}
public double getsalary()
{
return salary;
}
public void setsalary(double salary)
{
if(salary < 0)
{
salary = 0;
}
}
}

that is how employee.java / employee.class ends.

//Lab 4 - 3.14
//Bring in employee.class and configure to run as an app

public class employeetest
{
public static void main(String args[])
{
employee employee1 = new employee("John", "Smith", 50400);
employee employee2 = new employee("Jack", "Russell", 100000);

System.out.println( "Salary:");

}
}

i'm stuck here, because i am trying to bring in employee class info here...
am i doing something wrong ?
Nov 16 '07 #8
JosAH
11,448 Expert 8TB
alright maybe i am going about this incorrectly??
//Lab4 - Employee.java
//Create a Java Class for storing employee information

public class employee
{
private String firstname; //saves first name
private String lastname; //saves lastname for input
private double salary; //saves salary for input

public employee( String firstname, String lastname, double salary) //begin constructor
{
firstname = firstname;
lastname = lastname;
salary = salary;
}

public String getfirstname()
{
return firstname;
}

public void setfirstname(String firstname)
{
this.firstname = firstname; //is this neccessary? =)
}
public String getlastname()
{
return lastname;

}
public void setlastname(String lastname)
{
this.lastname = lastname;
}
public double getsalary()
{
return salary;
}
public void setsalary(double salary)
{
if(salary < 0)
{
salary = 0;
}
}
}

that is how employee.java / employee.class ends.

//Lab 4 - 3.14
//Bring in employee.class and configure to run as an app

public class employeetest
{
public static void main(String args[])
{
employee employee1 = new employee("John", "Smith", 50400);
employee employee2 = new employee("Jack", "Russell", 100000);

System.out.println( "Salary:");

}
}

i'm stuck here, because i am trying to bring in employee class info here...
am i doing something wrong ?
Note that 'javac' (your Java compiler) uses the same flag '-cp .' that tells it where
it can find compiled .class files. It needs those .class files because it needs to
know what that 'employee' class is all about when it has to compile your employeetest
class.

kind regards,

Jos
Nov 16 '07 #9
Note that 'javac' (your Java compiler) uses the same flag '-cp .' that tells it where
it can find compiled .class files. It needs those .class files because it needs to
know what that 'employee' class is all about when it has to compile your employeetest
class.

kind regards,

Jos
that definately makes sense - could you let me know what i need to do for that? I thought i was doing good. lol
Nov 16 '07 #10
JosAH
11,448 Expert 8TB
that definately makes sense - could you let me know what i need to do for that? I thought i was doing good. lol
Just type 'javac' on your command line and the compiler tells you everything you
wanted to know but were too afraid to ask ;-)

kind regards,

Jos
Nov 16 '07 #11

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Mondo Dynamo | last post by:
A friend of mine is learning java as part of a Business Studies Degree and is finding it very hard to get to grips with. She has an assignment coming up soon and needs some help, she is offering...
458
by: wellstone9912 | last post by:
Java programmers seem to always be whining about how confusing and overly complex C++ appears to them. I would like to introduce an explanation for this. Is it possible that Java programmers...
51
by: erikcw | last post by:
DiveIntoPython.org was the first book I read on python, and I really got a lot out of it. I need to start learning Java (to maintain a project I've inherited), and was wondering if anyone knew of...
0
by: south622 | last post by:
I'm taking a beginning Java course and I'm stuck in week eight of a nine week course. If anyone could help me I would greatly appreciate it. This assignment was due yesterday and each day I go past...
4
by: Tigger2000 | last post by:
I keep getting an error when trying to compile this for Java prog class, below is the instructions for the assignment and my code. Loop Assignment Write, compile, and run a Java program that...
6
by: penny | last post by:
In this assignment we shall look at a possible representation of rational numbers in java using objects. The java language represents rational numbers using the same representation used for other...
2
by: toprahman | last post by:
Hi guys, I'm a student teacher at a high school in Washington D.C. and I've come across a slight problem. See, I'm a math major, but one of the computer science teachers just quit and they need me to...
29
by: s0suk3 | last post by:
Hello, I was hoping to get some opinions on a subject. I've been programming Python for almost two years now. Recently I learned Perl, but frankly I'm not very comfortable with it. Now I want to...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.