Groups | Search | Server Info | Keyboard shortcuts | Login | Register
Groups > comp.lang.java.programmer > #5719
| From | Lew <noone@lewscanon.com> |
|---|---|
| Newsgroups | comp.lang.java.programmer |
| Subject | Re: Needs help in editing |
| Date | 2011-06-28 00:09 -0400 |
| Organization | albasani.net |
| Message-ID | <iubk5f$bl0$1@news.albasani.net> (permalink) |
| References | <1021f122-3898-4fc9-93ed-ac1aa9403b82@q15g2000yqk.googlegroups.com> |
On 06/23/2011 02:25 PM, Eric wrote:
> Hi guys: Can any one please help me how to i do the changes in my
> program according to the following 4 changes.
>
> 1) Create a Date type birth data instance field in the Employee class,
> not a String
public class Employee
{
Date birthData;
...
> 2) Enlarge the constructors for the Employee class and subclasses to
> pass the int month, int day, and int year of the birth date as input
> by the user to PayrollSystemTest to the subclass constructor, and then
> to the Employee class constructor
They're asking for a lot, aren't they?
Do you understand the question?
For example, consider a no-arg constructor:
public Employee()
{
}
To "enlarge" the constructor is to add another constructor with additional
arguments. For example, an "enlarged" constructor that takes a 'Date'
argument looks like this:
public Employee( Date aDate )
{
// do something with the argument
}
The term "enlarge a constructor" has no formal meaning in Java. It's an
informal way to ask for additional constructors.
Constructors should not ask the user for input. Constructors exist to
construct the instance, not to perform logic. Note that the problem asks for
a different type, 'PayrollSystemTest', to accept the user input. It will then
place the required data into appropriate variables (or one appropriate
variable) and use those variables (that variable) as arguments to the
constructor of an 'Employee' subtype.
So the 'Employee' constructor will not contain logic to accept input from the
user.
Nor will any other constructor.
Since an 'Employee' subtype constructor accepts the arguments, the subtype
constructor must relay the information to 'Employee' via its call to
'super(someArguments)'.
> 3) Input from the user for the 5 specific employees and then comment
> out the hardcoding for the 4 employees in the original code
This is an academic exercise. In real code you delete code, not comment it out.
> 4) Report monthly salary amounts and include the November birthday
> bonus
>
> import java.util.ArrayList;
> import java.util.Date;
> import java.util.Scanner;
>
> public class Employee {
>
> String socialSecurity;
> String birthDate;
Usually member variables should be 'private', and in this case, 'final'.
> public Employee(String socialSecurity, String birthDate){
> this.birthDate = birthDate;
> this.socialSecurity = socialSecurity;
> }
What if the arguments are 'null'?
> public String getSocialSecurity(){
> return socialSecurity;
> }
>
> public String getBirthDate(){
> return birthDate;
> }
>
> public String toString(){
> return ("Employee: Social security " + socialSecurity
> + " date of birth " + birthDate);
> }
>
> public static void main(String[] args) {
>
> Scanner keyboard = new Scanner(System.in);
> System.out.println("Enter employees one by one");
> ArrayList<Employee> ar = new ArrayList<Employee>();
>
> while(true){
> System.out.println(" Employee types available:");
> System.out.println("");
> System.out.println("1-Salaried Employee");
> System.out.println("2-Hourly Employee");
> System.out.println("3-Commission Employee");
> System.out.println("4-Based Salary Commission
> Employee");
> System.out.println("");
> System.out.println("Enter employee type (1-4) .
> Finish list with type 0: ");
>
> String typeString = keyboard.next();
> // boolean goodInput = true;
> int type = -1;
What's with the "-1" crud? Use the string.
> try{
> type = Integer.parseInt(typeString);
> } catch(Exception ex){
>
Class, what are we supposed to do with exceptions?
> }
>
> if(type<0 || type> 4){
> System.out.println("Invalid type. Please, try
> again. ");
> continue;
> }
>
> if(type == 0)break;
Wow.
> System.out.println("Enter social security: ");
> String social = keyboard.next();
> System.out.println("Enter date of birth: ");
> String birth = keyboard.next();
>
> boolean goodInput = true;
> switch(type){
Giant Switch Statement Alert!
Soon you will learn to write subroutines. That will help.
--
Lew
Honi soit qui mal y pense.
http://upload.wikimedia.org/wikipedia/commons/c/cf/Friz.jpg
Back to comp.lang.java.programmer | Previous | Next — Previous in thread | Find similar
Needs help in editing Eric <ehtisham@gmail.com> - 2011-06-23 11:25 -0700
Re: Needs help in editing Aéris <aeris@imirhil.fr> - 2011-06-24 00:35 +0200
Re: Needs help in editing Aéris <aeris@imirhil.fr> - 2011-06-24 00:39 +0200
Re: Needs help in editing lewbloch <lewbloch@gmail.com> - 2011-06-24 08:42 -0700
Re: Needs help in editing Aéris <aeris@imirhil.fr> - 2011-06-24 21:28 +0200
Re: Needs help in editing Lew <noone@lewscanon.com> - 2011-06-26 13:30 -0400
Re: Needs help in editing Aéris <aeris@imirhil.fr> - 2011-06-26 21:49 +0200
Re: Needs help in editing Lew <noone@lewscanon.com> - 2011-06-26 16:32 -0400
Re: Needs help in editing Lew <noone@lewscanon.com> - 2011-06-26 16:35 -0400
Re: Needs help in editing rossum <rossum48@coldmail.com> - 2011-06-23 23:42 +0100
Re: Needs help in editing William Colls <william.colls@rogers.com> - 2011-06-23 22:40 -0400
Re: Needs help in editing Lew <noone@lewscanon.com> - 2011-06-26 13:40 -0400
Re: Needs help in editing Roedy Green <see_website@mindprod.com.invalid> - 2011-06-27 20:05 -0700
Re: Needs help in editing Lew <noone@lewscanon.com> - 2011-06-28 00:09 -0400
csiph-web