program challenge

From: Clara (claradona_at_hotmail.com)
Date: 03/22/05


Date: 22 Mar 2005 03:20:15 -0800

was doing a program for fun to brush up my java skills (under my dad's
advice) but i got stuck at the arrays for classes. (object oriented)

public abstract class Employee {

  public String name;
  public int idno;

/**Construct an employee object with specified properties*/
public Employee(String name){
this.name = name;
}

/**default id*/
public Employee(){
        idno = 0;
}

/** construct id*/
public Employee(int idno){
        this.idno = idno;
}

/** Return name */
public String getName(){
return name;
}

/** Set a new name */
public void setName(String name){
this.name = name;
}

/** Return idno */
public int getIdno(){
return idno;
}

/** Set a new idno */
public void setIdno(int idno){
this.idno = idno;
}

/** Abstract method findWeeklySalary */
public abstract double findWeeklySalary();
}

// Salaried.java: the salaried class that extends Employee

public class Salaried extends Employee
{
public double annualsalary;

/** Default constructor*/
public Salaried() {
        this(1.0);

}

//Construct annual salary
public Salaried (double annualsalary)
{
        this.annualsalary = annualsalary;
}

/** Construct annual salary with specified attributes */
public Salaried (int idno, double annualsalary){
        super(idno);
        /**annualsalary = 1.0;*/
}

/** Return annual salary */
public double getAnnualsalary(){
return annualsalary;
}

/** Set a new annual salary */
public void setAnnualsalary(double annualsalary){
this.annualsalary = annualsalary;
}

/** Implement the findWeeklySalary method defined in Employee*/
public double findWeeklySalary(){
        return annualsalary/52;
}
}

// Hourly.java: the Hourly class that extends Employee

public class Hourly extends Employee {
 private double hours;
 private double rates;

 /** Default constructor*/
 public Hourly() {
  this(1.0, 1.0);
  }

 /** Construct a Hourly example with hours and rates */
 public Hourly(double hours, double rates){
 this.hours = hours;
 this.rates = rates;
 }

 /** Construct Hourly example with specified attributes */
 public Hourly ( int idno, double hours, double rates) {
 super(idno);
 }

 /** Return hours and rates */
 public double getHours(){
 return hours;
 }

 public double getRates() {
 return rates;
 }

 /** Set a new hours and rates */
 public void setHours(double hours){
 this.hours = hours;
}

 public void setRates(double rates){
 this.rates = rates;
 }

 /** Implement the findWeeklySalary method defined in Employee */
 public double findWeeklySalary(){
 if (hours <= 40)
  return hours * rates;

  else
   return (rates * 40) + (rates*1.5*(hours-40));
}
}

// Manager.java: The new manager class that extends the salaried class

public class Manager extends Salaried {
public String division;

/** Default constructor */
public Manager(){
        super();
}

/** Construct a new Manager with specified attributes */
public Manager (double annualsalary, String division){
        super(annualsalary);
        this.division = division;
        }

/** Return division */
public String getDivision(){
return division;
}

/** Set a new division */
public void setDivision(String division){
this.division = division;
}
}

// Consultant.java: The new consultant class that extends the salaried
class

public class Consultant extends Salaried {
public int numofproject;

/** Default constructor */
public Consultant() {
super();
}

/** Construct a new Consultant with specified attributes */
public Consultant (double annualsalary, int numofproject){
        super(annualsalary);
        this.numofproject = numofproject;
        }

/** Return number of project */
public int getNumofproject(){
return numofproject;
}

/** Set a new division */
public void setNumofproject(int numofproject){
this.numofproject = numofproject;
}
}

// Programmer.java: the programmer class that extends from Hourly

public class Programmer extends Hourly {
public String projectname;

/** Default constructor */
public Programmer() {
super();
}

/** Construct a new Programmer with specified attributes */
public Programmer (double hours, double rates, String projectname){
        super(hours, rates);
        this.projectname = projectname;
        }

/** Return project name */
public String getProjectname(){
return projectname;
}

/** Set a new project name */
public void setProjectname(String projectname){
this.projectname = projectname;
}
}

public class TestEmployee{

/** Main Method */

public static void main(String[] args){

//Declare and initialize three employee types

Right now i'm wonderin how to insert arrays and test the program i.e
error messages, loops, etc
I know I need to use loops to calculate totals of the 3 categories of
employees too but i'm like so clueless as to where to place these
statements.
Thanks for any replies.



Relevant Pages

  • Re: Efficiently sequencing a stream of objects
    ... public class MergingIterator<E extends Comparable<? ... public void add(Iterator<? ... Carrier carrier = new Carrier; ...
    (comp.lang.java.programmer)
  • Re: Constructor methods from extended classes
    ... public class B extends A { ... inherited by B from A always accessible to the programmer? ... it is prevented as constructors are not inherited. ...
    (comp.lang.java.programmer)
  • Re: When writing applet do you start out as an application or applet?
    ... to an applet or just creating it as an applet, ... See the simple example below of test.java which extends Canvas and draws a blue oval in a yellow background. ... public void paint{ ... public class test1 extends Applet { ...
    (comp.lang.java.programmer)
  • Re: How to use generics?
    ... getting rid of the ACollection and BCollection and just having Collectionwould be a good start towards using generics to the full extent. ... public void AddCollection() ... public bool ContainsKey ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Tricky form problem
    ... > ShowDialog method) different modal child forms. ... when using ShowDialog() there's no ... > public class MainForm: Form ... > public void ShowForm() ...
    (microsoft.public.dotnet.framework.compactframework)