473,326 Members | 2,023 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,326 software developers and data experts.

Java Question - i am REALLY confused

Hi all,

I am taking a Java Course in Michigan to get into the flow of things , but i am completely stuck on one of the Labs.

Here is what the Lab Asks for -

Create a class called 'Employee' that includes three pieces of information as instance variaveles -- a first name (type String), a last name (type String) and a monthly salary (double). Your class should have a constructor that initializes the three instance variabvles. Provide a set and a get method for each instance variable. If the monthly slaary is not prositive, set it to 0.0. Write a test application named EmployeeTest that demonstrates class Employee's capabilitis. Create two Employee objects and display each object's yearly salary. Then give each Employee a 10% raise and display each Employee's yearly salary again.

I AM SOOOO LOSTTTT in this.

please if you can't give me the 'answer' can you maybe break it down for me? Im not quite sure how to even begin this....

Thanks SOOO much in advance
Nov 14 '07 #1
13 3026
r035198x
13,262 8TB
Hi all,

I am taking a Java Course in Michigan to get into the flow of things , but i am completely stuck on one of the Labs.

Here is what the Lab Asks for -

Create a class called 'Employee' that includes three pieces of information as instance variaveles -- a first name (type String), a last name (type String) and a monthly salary (double). Your class should have a constructor that initializes the three instance variabvles. Provide a set and a get method for each instance variable. If the monthly slaary is not prositive, set it to 0.0. Write a test application named EmployeeTest that demonstrates class Employee's capabilitis. Create two Employee objects and display each object's yearly salary. Then give each Employee a 10% raise and display each Employee's yearly salary again.

I AM SOOOO LOSTTTT in this.

please if you can't give me the 'answer' can you maybe break it down for me? Im not quite sure how to even begin this....

Thanks SOOO much in advance
Start with the Employee class and write it as specified by your question.
Nov 14 '07 #2
I've really had a tough time

so is this two separate codes? [i am using NetBeans IDE]

based on your response --- this is as far as i got without re-confusing myself :)

public class Employee {


public Employee() {
}

}

Class was started, but what exactly do i do to create the instance variables [could i get any sample code or something that really breaks this down for me? - i feel worthless :) ]

i want to understand this - as i know it will pop back up ...but within the class how are all of these instance variables defined, and set and get methods brought up?
Nov 14 '07 #3
r035198x
13,262 8TB
I've really had a tough time

so is this two separate codes? [i am using NetBeans IDE]

based on your response --- this is as far as i got without re-confusing myself :)

public class Employee {


public Employee() {
}

}

Class was started, but what exactly do i do to create the instance variables [could i get any sample code or something that really breaks this down for me? - i feel worthless :) ]

i want to understand this - as i know it will pop back up ...but within the class how are all of these instance variables defined, and set and get methods brought up?
Read this.
Nov 14 '07 #4
JosAH
11,448 Expert 8TB
I've really had a tough time

so is this two separate codes? [i am using NetBeans IDE]

based on your response --- this is as far as i got without re-confusing myself :)

public class Employee {


public Employee() {
}

}

Class was started, but what exactly do i do to create the instance variables
[could i get any sample code or something that really breaks this down for
me? - i feel worthless :) ]

i want to understand this - as i know it will pop back up ...but within the class how are all of these instance variables defined, and set and get methods brought up?
Here's you own assignment text again. Follow it closely:

"Create a class called 'Employee' that includes three pieces of information as
instance variaveles -- a first name (type String), a last name (type String) and a
monthly salary (double)."


This can only lead to the following skeleton of a class:

Expand|Select|Wrap|Line Numbers
  1. public class Employee {
  2.  
  3.    private String firstName;
  4.    private String lastName;
  5.    private double salary;
  6.  
  7.    ...
  8. }
  9.  
"Your class should have a constructor that initializes the three instance
variabvles. Provide a set and a get method for each instance variable."


Here's the constructor for the above class:

Expand|Select|Wrap|Line Numbers
  1.    ...
  2.    public Employee(String firstName, String lastName, double salary) {
  3.       this.firstName= firstName;
  4.       this.lastName= lastName;
  5.       this.salary= salary;
  6.    }
  7.  
Now it's your turn: create methods that get and set those three values that belong
to an instantiation of an Employee.

kind regards,

Jos
Nov 14 '07 #5
i love you guys, thanks so much it does help a lot !!!

I will try to write this out, if i get stuck, ill be back :) printing this

God Bless!
Nov 14 '07 #6
Here's you own assignment text again. Follow it closely:

"Create a class called 'Employee' that includes three pieces of information as
instance variaveles -- a first name (type String), a last name (type String) and a
monthly salary (double)."

This can only lead to the following skeleton of a class:


Code: ( java )
public class Employee {

private String firstName;
private String lastName;
private double salary;

...
}


"Your class should have a constructor that initializes the three instance
variabvles. Provide a set and a get method for each instance variable."

Here's the constructor for the above class:


Code: ( java )
...
public Employee(String firstName, String lastName, double salary) {
this.firstName= firstName;
this.lastName= lastName;
this.salary= salary;
}


Now it's your turn: create methods that get and set those three values that belong
to an instantiation of an Employee.

kind regards,

Jos
public class Employee {

private String firstName;
private String lastName;
private double salary;

public Employee( String firstName, String lastName, double salary);
}

i am getting this when compiling::'


Lab1/Employee.java [7:1] missing method body, or declare abstract
public Employee( String firstName, String lastName, double salary);
^
1 error
Errors compiling Employee.



what did i do wrong? am i supposed to do something else? :P -- man, i am really bad at this ....
Nov 14 '07 #7
r035198x
13,262 8TB
public class Employee {

private String firstName;
private String lastName;
private double salary;

public Employee( String firstName, String lastName, double salary);
}

i am getting this when compiling::
public class Employee {

private String firstName;
private String lastName;
private double salary;

public Employee( String firstName, String lastName, double salary);
}


what did i do wrong? am i supposed to do something else? :P -- man, i am really bad at this ....
For starters you are putting a semi colon where an opening brace is needed
Expand|Select|Wrap|Line Numbers
  1.      public Employee( String firstName, String lastName, double salary);
should really be
Expand|Select|Wrap|Line Numbers
  1.      public Employee( String firstName, String lastName, double salary) {
You'll want to do something with all those values you are taking in the constructors.

P.S Note my use of [code=java] tags when posting code
P.P.S Going over a tutorial on constructors wouldn't hurt.
Nov 14 '07 #8
JosAH
11,448 Expert 8TB
what did i do wrong? am i supposed to do something else? :P -- man, i am really bad at this ....
You sure are because all you had to do was copy/paste or type in what I had
written. Programming and sloppyness don't go well together.

kind regards,

Jos
Nov 14 '07 #9
lol, this is cracking me up, @ work right now losing my mind with this.

and yea - i felt there was more that needed to be added because i had an extra mark in there which was giving me an error, which is why i added the semi-colon.


import java.util.Scanner;

public class Employee {
private String firstName;
private String lastName;
private double salary;

public Employee( String firstName, String lastName, double salary){
Scanner input = new Scanner(System.in);

now from here - is there where the public void - setFirstName() and all that comes in?

am i on the right path? its an online course - so there is no teacher interaction as well as book is slightly confusing...

Thanks - and sorry for seeming like such an idiot, you guys have been more than wonderful!
Nov 14 '07 #10
r035198x
13,262 8TB
lol, this is cracking me up, @ work right now losing my mind with this.

and yea - i felt there was more that needed to be added because i had an extra mark in there which was giving me an error, which is why i added the semi-colon.


import java.util.Scanner;

public class Employee {
private String firstName;
private String lastName;
private double salary;

public Employee( String firstName, String lastName, double salary){
Scanner input = new Scanner(System.in);

now from here - is there where the public void - setFirstName() and all that comes in?

am i on the right path? its an online course - so there is no teacher interaction as well as book is slightly confusing...

Thanks - and sorry for seeming like such an idiot, you guys have been more than wonderful!
... and now I really insist that you read some tutorial/book first.
Nov 14 '07 #11
... and now I really insist that you read some tutorial/book first.
LOL - yep, i guess im lost.

Read the 'Small Java' How To Program book

after reading, i try to follow the diagrams they show me -- basically im seeing the class being built

public class Gradebook

private String courseName;

public void setCourseName( String name )

course name = name;

i am missing some characters, i know - but its basically that layout...


Now that you've made me feel completely worthless in this - i guess i will try to read up a little more.
Nov 14 '07 #12
r035198x
13,262 8TB
LOL - yep, i guess im lost.

Read the 'Small Java' How To Program book

after reading, i try to follow the diagrams they show me -- basically im seeing the class being built

public class Gradebook

private String courseName;

public void setCourseName( String name )

course name = name;

i am missing some characters, i know - but its basically that layout...


Now that you've made me feel completely worthless in this - i guess i will try to read up a little more.
You are not completely worthless if you still have your powers of reading with you.
Nov 14 '07 #13
My teacher pointed out a great tutorial under

http://sourceforge.net/projects/eclipsetutorial/

I think the first 3 or 4 are all about getters and setters. It won't take you long to catch on watching these! They were a great help to me. -
Nov 18 '07 #14

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

Similar topics

3
by: StealthMonkey | last post by:
Let me prefix this by saying that I know next to nothing about Java (so please try to keep explainations simple). I use PHP for my server-side web programming. Here is my dilemma: I need a...
54
by: Spammay Blockay | last post by:
I've been tasked with doing technical interviews at my company, and I have generally ask a range of OO, Java, and "good programming technique" concepts. However, one of my favorite exercises I...
37
by: asj | last post by:
awhile back, eBay decided to switch from a Microsoft/.NET/Windows architecture on the backend to a J2EE one, which might explain why their java backend will handle up to 1 BILLION page views a day!...
47
by: Theatre Mgmt | last post by:
Sun project seeks to solve Java memory, execution issues http://story.news.yahoo.com/news?tmpl=story&u=/infoworld/20050325/tc_infoworld/58059&e=1&ncid= San Francisco (InfoWorld) - Sun...
11
by: DrUg13 | last post by:
In java, this seems so easy. You need a new object Object test = new Object() gives me exactly what I want. could someone please help me understand the different ways to do the same thing in...
4
by: Khan | last post by:
hi, i'm writing java code inside <body> tag of java script file. all the java code is executing at frame startup. how can i call that java code only when i click on a button. I can call jscript...
17
by: ToddLMorgan | last post by:
I'm just starting out with python, after having a long history with Java. I was wondering if there were any resources or tips from anyone out there in Python-land that can help me make the...
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...
4
AmberJain
by: AmberJain | last post by:
I'm not a JAVA newbie..... I'm ABSOLUTE JAVA illiterate person.................. Recently, while I was planning to learn a new programming language, one of my friends advised me to learn JAVA....
8
intruderX
by: intruderX | last post by:
When programing robots with java, how they program hardware with java? Can java do the port programming? Or it is done in some other way? for an example... 1). A basic O/S is running to work with...
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...
1
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...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
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.