Groups | Search | Server Info | Keyboard shortcuts | Login | Register


Groups > comp.lang.java.programmer > #5622

Re: Needs help in editing

From William Colls <william.colls@rogers.com>
Newsgroups comp.lang.java.programmer
Subject Re: Needs help in editing
Date 2011-06-23 22:40 -0400
Organization National Capital Freenet, Ottawa, Ontario, Canada
Message-ID <iu0tcb$eod$1@theodyn.ncf.ca> (permalink)
References <1021f122-3898-4fc9-93ed-ac1aa9403b82@q15g2000yqk.googlegroups.com>

Show all headers | View raw


I think we are being asked to someone's school assignment. Better he 
does it himself.

On 11-06-23 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
>
> 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
>
> 3) Input from the user for the 5 specific employees and then comment
> out the hardcoding for the 4 employees in the original code
>
> 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;
>
>      public Employee(String socialSecurity, String birthDate){
>          this.birthDate = birthDate;
>          this.socialSecurity = socialSecurity;
>      }
>
>      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;
>                try{
>                    type = Integer.parseInt(typeString);
>                } catch(Exception ex){
>
>                }
>
>              if(type<0 || type>  4){
>                  System.out.println("Invalid type. Please, try
> again. ");
>                  continue;
>              }
>
>             if(type == 0)break;
>
>              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){
>                  case 1:
>                      System.out.println("Enter salary: ");
>                       String salString = keyboard.next();
>                      double salary = -1.0;
>                      try{
>                          salary =
> Double.parseDouble(salString);
>                      } catch(Exception ex){
>
>                      }
>                      if(salary<  0){
>                          System.out.println("Invalid input. Try
> again");
>                          goodInput = false;
>                          break;
>                      }
>                      SalariedEmployee emp = new
> SalariedEmployee(social, birth, salary);
>                      ar.add(emp);
>                      break;
>
>                  case 2:
>                         System.out.println("Enter hourly wage:
> ");
>                          String hourlyString = keyboard.next();
>                      System.out.println("Enter hours worked:
> ");
>                                    String hoursString =
> keyboard.next();
>                               double hourlyWage = -1.0;
>                              double hoursWorked = -1.0;
>                             try{
>                          hourlyWage =
> Double.parseDouble(hourlyString );
>                           hoursWorked =
> Double.parseDouble(hoursString );
>                      } catch(Exception ex){
>
>                      }
>
>                      if(hourlyWage<  0.0 || hoursWorked<  0.0){
>                          System.out.println("Invalid input. Try
> again");
>                          goodInput = false;
>                          break;
>                      }
>                       HourlyEmployee emp1 = new
> HourlyEmployee(social, birth, hourlyWage, hoursWorked);
>                      ar.add(emp1);
>                      break;
>
>                  case 3:
>                                      System.out.println("Enter
> commission rate: ");
>                          String commissionString =
> keyboard.next();
>                      System.out.println("Enter gross sales: ");
>                                    String salesString =
> keyboard.next();
>                               double commissionRate = -1.0;
>                              double grossSales = -1.0;
>                             try{
>                          commissionRate =
> Double.parseDouble(commissionString );
>                           grossSales =
> Double.parseDouble(salesString );
>                      } catch(Exception ex){
>
>                      }
>
>                      if(commissionRate<  0.0 || grossSales<
> 0.0){
>                          System.out.println("Invalid input. Try
> again");
>                          goodInput = false;
>                          break;
>                      }
>                       CommissionEmployee emp2 = new
> CommissionEmployee(social, birth, commissionRate, grossSales);
>                      ar.add(emp2);
>                      break;
>
>                  case 4:
>                                     System.out.println("Enter
> commission rate: ");
>                          commissionString = keyboard.next();
>                      System.out.println("Enter gross sales: ");
>                                     salesString =
> keyboard.next();
>                          System.out.println("Enter salary: ");
>                        salString = keyboard.next();
>                          commissionRate = -1.0;
>                               grossSales = -1.0;
>                        salary = -1.0;
>                                  try{
>                          commissionRate =
> Double.parseDouble(commissionString );
>                           grossSales =
> Double.parseDouble(salesString );
>                                        salary =
> Double.parseDouble(salString );
>                      } catch(Exception ex){
>
>                      }
>                           if(commissionRate<  0.0 || grossSales
> <  0.0 || salary<  0){
>                          System.out.println("Invalid input. Try
> again");
>                          goodInput = false;
>                          break;
>                      }
>
>                    SalaryBasedCommissionEmployee emp3 = new
> SalaryBasedCommissionEmployee(social, birth, commissionRate,
> grossSales, salary);
>                               ar.add(emp3);
>              }
>
>
>
>
>
>          }
>
>          for (int i = 0; i<  ar.size(); i++) {
>              Employee employee =  ar.get(i);
>                  System.out.println(employee);
>          }
>
>
>      }
>
>
> }
>
> class  SalariedEmployee extends Employee{
>      double salary;
>
>      public SalariedEmployee(String socialSecurity, String
> birthDate, double salary){
>          super(socialSecurity, birthDate);
>          this.salary = salary;
>
>      }
>
>      public double getSalary(){
>          return salary;
>      }
>
>
>     public String toString(){
>          return ("Salaried Employee:  Social security " +
> socialSecurity + " date of birth " + birthDate + " salary " +
> salary);
>      }
>
> }
>
> class HourlyEmployee extends Employee {
>      double hourlyWage;
>      double hoursWorked;
>
>       public HourlyEmployee(String socialSecurity, String
> birthDate, double hourlyWage, double hoursWorked){
>           super(socialSecurity, birthDate);
>           this.hourlyWage = hourlyWage;
>           this.hoursWorked = hoursWorked;
>
>       }
>
>    public String toString(){
>          return ("Hourly Employee:  Social security " +
> socialSecurity + " date of birth " + birthDate + " hourlyWage
> " + hourlyWage + " hoursWorked " + hoursWorked);
>      }
>
>
> }
>
> class CommissionEmployee extends Employee {
>      double grossSales;
>      double commissionRate;
>
>
>       public CommissionEmployee(String socialSecurity, String
> birthDate, double grossSales, double commissionRate){
>           super(socialSecurity, birthDate);
>           this.grossSales = grossSales;
>           this.commissionRate = commissionRate;
>
>       }
>
>    public String toString(){
>        return ("Commission Employee:  Social security " +
> socialSecurity + " date of birth " + birthDate + " Commission
> Rate " + commissionRate + " Gross Sales " + grossSales);
>      }
>
>
> }
>
> class SalaryBasedCommissionEmployee extends CommissionEmployee
> {
>      double salary;
>
>
>
>       public  SalaryBasedCommissionEmployee(String
> socialSecurity, String birthDate, double grossSales, double
> commissionRate, double salary){
>           super(socialSecurity, birthDate, grossSales,
> commissionRate);
>           this.salary = salary;
>
>
>       }
>
>    public String toString(){
>        return ("Salary Based Commission Employee:  Social
> security " + socialSecurity + " date of birth " + birthDate +
> " Commission Rate " + commissionRate
>                + " Gross Sales " + grossSales + " Salary " +
> salary);
>      }
>
>
> }

Back to comp.lang.java.programmer | Previous | NextPrevious in thread | Next in thread | Find similar


Thread

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