Go Back   Flash Flash Revolution > General Discussion > Critical Thinking > Homework & Help
Register FAQ Community Calendar Today's Posts Search

Reply
 
Thread Tools Display Modes
Old 02-8-2012, 12:49 PM   #1
rushyrulz
Digital Dancing!
Retired StaffFFR Simfile AuthorFFR Music ProducerD7 Elite KeysmasherFFR Veteran
 
rushyrulz's Avatar
 
Join Date: Feb 2006
Location: 80 billion club, NE
Age: 31
Posts: 12,980
Default [College] Java 2 programming

I'm a tad bit confused by the monster assignment I got for my java class. The assignment is to create 6 classes: Employee (abstract class inherits Object), [HourlyEmployee, SalaryEmployee, CommissionEmployee] all inherit from Employee, EmployeeManager, and EmployeeDriver (contains the main method and menu system).

Unfortunately, my Java 1 teacher didn't teach us all she was supposed to, and as a result I'm struggling a bit to understand some of the concepts that my current teacher is mentioning that we should have already learned in Java 1. Included in these misunderstood topics are: common classes in Object such as toString and equals, bubble sort, and most of object-oriented programming. So a few questions I have:

1. How to I implement the toString methods of each employee class from the driver where the information is prompted?

2. the prompts for first name, last name, middle initial, gender, employee number, and fulltime in the driver are
Code:
System.out.print("Enter Last Name: ");
ln = in.next();
System.out.print("Enter First Name: ");
fn = in.next();
System.out.print("Enter Middle Initial: ");
mi = in.next().charAt(0);
System.out.print("Enter Gender: ");
g = in.next().charAt(0);
System.out.print("Enter Employee Number: ");
en = in.nextInt();
System.out.print("Full Time? (y/n): ");
f = in.next().charAt(0);
which was given to me by the instructor. These variables are different than the protected variables listed in the UML diagram for Employee, do I need to set the variables equal to to these shortened versions in Employee's constructor? ie.
Code:
lastName = ln;
firstName = fn;
middleInitial = mi;
gender = g;
employeeNumber = en;
fulltime = f;
and is that even legal to do since some of the data members are chars?

I might have more questions later as I haven't even started on the manager class yet.

Thanks in advance for any help.
__________________


rushyrulz is offline   Reply With Quote
Old 02-8-2012, 01:48 PM   #2
YoshL
Celestial Harbor
FFR Simfile AuthorFFR Music ProducerD7 Elite KeysmasherFFR Veteran
 
YoshL's Avatar
 
Join Date: Aug 2008
Location: Celestial Harbor
Age: 30
Posts: 6,156
Send a message via AIM to YoshL Send a message via MSN to YoshL Send a message via Skype™ to YoshL
Default Re: [College] Java 2 programming

Quote:
Originally Posted by rushyrulz View Post
1. How to I implement the toString methods of each employee class from the driver where the information is prompted?

2. the prompts for first name, last name, middle initial, gender, employee number, and fulltime in the driver are
Code:
System.out.print("Enter Last Name: ");
ln = in.next();
System.out.print("Enter First Name: ");
fn = in.next();
System.out.print("Enter Middle Initial: ");
mi = in.next().charAt(0);
System.out.print("Enter Gender: ");
g = in.next().charAt(0);
System.out.print("Enter Employee Number: ");
en = in.nextInt();
System.out.print("Full Time? (y/n): ");
f = in.next().charAt(0);
which was given to me by the instructor. These variables are different than the protected variables listed in the UML diagram for Employee, do I need to set the variables equal to to these shortened versions in Employee's constructor? ie.
Code:
lastName = ln;
firstName = fn;
middleInitial = mi;
gender = g;
employeeNumber = en;
fulltime = f;
and is that even legal to do since some of the data members are chars?

I might have more questions later as I haven't even started on the manager class yet.

Thanks in advance for any help.
1. the toString() method is a method that is inherited for every object, because it's a method of the Object class. Because of this behavior, you can rewrite the function in any class with : public String toString(){ etc. etc.
the String return value is what is to be displayed to the screen.

the main thing that uses the toString() method is any system.out statements you have. what it's doing when you pass a variable into there is calling its toString() method

basically, you implement in the classes, not the driver.

2. yes, that's pretty much what you're supposed to do. Of course, whether setting variables as chars depends on what the variable type in question is. Of course you can set a char as a char. so just data types.
__________________


Quote:
Originally Posted by Charu View Post
Only yours, for an easy price of $19.99! You too can experience the wonders of full motion rump sticking.
YoshL is offline   Reply With Quote
Old 02-8-2012, 02:08 PM   #3
rushyrulz
Digital Dancing!
Retired StaffFFR Simfile AuthorFFR Music ProducerD7 Elite KeysmasherFFR Veteran
 
rushyrulz's Avatar
 
Join Date: Feb 2006
Location: 80 billion club, NE
Age: 31
Posts: 12,980
Default Re: [College] Java 2 programming

Thanks Yoshl, I also don't understand why methods getEmployeeNumber (which returns an int) and setEmployeeNumber(which has an int argument but returns nothing) are necessary in the Employee class when I get all the employee number information from the driver

UML for Employee:


is it because employeeNum isn't a protected variable? If so, why doesn't gender need separate get/set methods?
__________________



Last edited by rushyrulz; 02-8-2012 at 02:11 PM..
rushyrulz is offline   Reply With Quote
Old 02-8-2012, 02:10 PM   #4
YoshL
Celestial Harbor
FFR Simfile AuthorFFR Music ProducerD7 Elite KeysmasherFFR Veteran
 
YoshL's Avatar
 
Join Date: Aug 2008
Location: Celestial Harbor
Age: 30
Posts: 6,156
Send a message via AIM to YoshL Send a message via MSN to YoshL Send a message via Skype™ to YoshL
Default Re: [College] Java 2 programming

Quote:
Originally Posted by rushyrulz View Post
Thanks Yoshl, I also don't understand why methods getEmployeeNumber (which returns an int) and setEmployeeNumber(which has an int argument but returns nothing) are necessary in the Employee class when I get all the employee number information from the driver
basically it's the concept of data hiding. *imagine* a real life scenario where you have written a nice class for people to use. You don't want people writing drivers where they directly access all of your data, you would probably want some means of controlling that, hence all the instance variables in other classes. which is why most classes use get methods and set methods to achieve their purpouses (idk if i explained that correctly :S)

edit:

because Employee is also an abstract class and objects are going to extend off of it, the subclasses will never have direct access to the variables, and would need those get and set methods
__________________


Quote:
Originally Posted by Charu View Post
Only yours, for an easy price of $19.99! You too can experience the wonders of full motion rump sticking.
YoshL is offline   Reply With Quote
Old 02-8-2012, 02:13 PM   #5
rushyrulz
Digital Dancing!
Retired StaffFFR Simfile AuthorFFR Music ProducerD7 Elite KeysmasherFFR Veteran
 
rushyrulz's Avatar
 
Join Date: Feb 2006
Location: 80 billion club, NE
Age: 31
Posts: 12,980
Default Re: [College] Java 2 programming

So I wouldn't be using the get/set methods to prompt the user, but just to get the information from the manager class when I get around to coding that?

edit to your edit: So you're saying that I need get and set methods for all the classes that extend from Employee as well? (sorry I'd never heard of get/set until earlier this semester when I found out another thing that my CS1400 teacher neglected to teach us.)
__________________



Last edited by rushyrulz; 02-8-2012 at 02:16 PM..
rushyrulz is offline   Reply With Quote
Old 02-8-2012, 02:14 PM   #6
YoshL
Celestial Harbor
FFR Simfile AuthorFFR Music ProducerD7 Elite KeysmasherFFR Veteran
 
YoshL's Avatar
 
Join Date: Aug 2008
Location: Celestial Harbor
Age: 30
Posts: 6,156
Send a message via AIM to YoshL Send a message via MSN to YoshL Send a message via Skype™ to YoshL
Default Re: [College] Java 2 programming

Quote:
Originally Posted by rushyrulz View Post
So I wouldn't be using the get/set methods to prompt the user, but just to get the information from the manager class when I get around to coding that?
well, get the information from the manager, getting the information from the Employee subclasses, yes.
__________________


Quote:
Originally Posted by Charu View Post
Only yours, for an easy price of $19.99! You too can experience the wonders of full motion rump sticking.
YoshL is offline   Reply With Quote
Old 02-8-2012, 02:30 PM   #7
rushyrulz
Digital Dancing!
Retired StaffFFR Simfile AuthorFFR Music ProducerD7 Elite KeysmasherFFR Veteran
 
rushyrulz's Avatar
 
Join Date: Feb 2006
Location: 80 billion club, NE
Age: 31
Posts: 12,980
Default Re: [College] Java 2 programming

Ok so breakdown time on how this thing is gonna run hypothetically:

Driver contains the main, so that's executed. Neat little menu pops up. User picks "Add Employee" option and is prompted:
1. hourly
2. salary
3. commission

Lets say they pick hourly, they are prompted
Enter Last Name:
Enter First Name:
Enter Middle Initial:
Enter Gender:
Enter Employee Number:
Full Time (y/n):
Enter Wage:
(there's a separate menu for adding hours)

All this information gets sent to a method in the EmployeeManager class called addEmployee.

Within this addEmployee class am I supposed to call the toString method of HourlyEmployee or what? Unfortunately, the teacher didn't provide a UML on the EmployeeManager class and kinda just left it up to us to come up with something that works.

EDIT: I'm dumb, I'm not supposed to output the employee info til the user asks for it.
__________________



Last edited by rushyrulz; 02-8-2012 at 02:35 PM..
rushyrulz is offline   Reply With Quote
Old 02-8-2012, 02:34 PM   #8
YoshL
Celestial Harbor
FFR Simfile AuthorFFR Music ProducerD7 Elite KeysmasherFFR Veteran
 
YoshL's Avatar
 
Join Date: Aug 2008
Location: Celestial Harbor
Age: 30
Posts: 6,156
Send a message via AIM to YoshL Send a message via MSN to YoshL Send a message via Skype™ to YoshL
Default Re: [College] Java 2 programming

Quote:
Originally Posted by rushyrulz View Post
Ok so breakdown time on how this thing is gonna run hypothetically:

Driver contains the main, so that's executed. Neat little menu pops up. User picks "Add Employee" option and is prompted:
1. hourly
2. salary
3. commission

Lets say they pick hourly, they are prompted
Enter Last Name:
Enter First Name:
Enter Middle Initial:
Enter Gender:
Enter Employee Number:
Full Time (y/n):
Enter Wage:
(there's a separate menu for adding hours)

All this information gets sent to a method in the EmployeeManager class called addEmployee.

Within this addEmployee class am I supposed to call the toString method of HourlyEmployee or what? Unfortunately, the teacher didn't provide a UML on the EmployeeManager class and kinda just left it up to us to come up with something that works.
well, first off, what does addEmployee return? that's a fairly important part.
and it shouldn't call toString at all. most likely you would create a new instance of the HourlyEmployee, and pass in all the values and things you need to the constructor, to create that.

also, are you supposed to be printing the info out or...? (lol this might be easier in chat)
__________________


Quote:
Originally Posted by Charu View Post
Only yours, for an easy price of $19.99! You too can experience the wonders of full motion rump sticking.
YoshL is offline   Reply With Quote
Old 02-8-2012, 02:38 PM   #9
rushyrulz
Digital Dancing!
Retired StaffFFR Simfile AuthorFFR Music ProducerD7 Elite KeysmasherFFR Veteran
 
rushyrulz's Avatar
 
Join Date: Feb 2006
Location: 80 billion club, NE
Age: 31
Posts: 12,980
Default Re: [College] Java 2 programming

lol I have AIM and skype.















<account info over thur
__________________


rushyrulz is offline   Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump



All times are GMT -5. The time now is 09:49 AM.


Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright FlashFlashRevolution