02-8-2012, 12:49 PM | #1 |
Digital Dancing!
Join Date: Feb 2006
Location: 80 billion club, NE
Age: 31
Posts: 12,980
|
[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); Code:
lastName = ln; firstName = fn; middleInitial = mi; gender = g; employeeNumber = en; fulltime = f; I might have more questions later as I haven't even started on the manager class yet. Thanks in advance for any help.
__________________
|
02-8-2012, 01:48 PM | #2 | |
Celestial Harbor
|
Re: [College] Java 2 programming
Quote:
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. |
|
02-8-2012, 02:08 PM | #3 |
Digital Dancing!
Join Date: Feb 2006
Location: 80 billion club, NE
Age: 31
Posts: 12,980
|
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.. |
02-8-2012, 02:10 PM | #4 | |
Celestial Harbor
|
Re: [College] Java 2 programming
Quote:
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 |
|
02-8-2012, 02:13 PM | #5 |
Digital Dancing!
Join Date: Feb 2006
Location: 80 billion club, NE
Age: 31
Posts: 12,980
|
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.. |
02-8-2012, 02:14 PM | #6 |
Celestial Harbor
|
Re: [College] Java 2 programming
well, get the information from the manager, getting the information from the Employee subclasses, yes.
|
02-8-2012, 02:30 PM | #7 |
Digital Dancing!
Join Date: Feb 2006
Location: 80 billion club, NE
Age: 31
Posts: 12,980
|
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.. |
02-8-2012, 02:34 PM | #8 | |
Celestial Harbor
|
Re: [College] Java 2 programming
Quote:
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) |
|
02-8-2012, 02:38 PM | #9 |
Digital Dancing!
Join Date: Feb 2006
Location: 80 billion club, NE
Age: 31
Posts: 12,980
|
Re: [College] Java 2 programming
lol I have AIM and skype.
<account info over thur
__________________
|
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
|
|