Java Help Plz:Employee Payroll

Discussion in 'OT Technology' started by DaVega366, Apr 26, 2006.

  1. DaVega366

    DaVega366 Guest

    I have an assignment due on Thurs and I'm lost. (Should have never taken the class.)

    I have to randomly generate numbers for each employee which includes height, 3 different salaries, employee number...

    I don't know how to put the random variables into the other classes. Truthfully, I have no idea what's going on. Six different classes. Scary.

    Random Class:

    import java.util.*;

    public class random_number{



    Random r = new Random();

    int n =r.nextInt(20);

    int h =60+r.nextInt(15);

    int t =r.nextInt(3);

    int hours =30+r.nextInt(31);

    double rate =Math.round(500+r.nextInt(1001)/100);

    int yr =25000+r.nextInt(125001);

    int comm =500+r.nextInt(1001);

    int sales =r.nextInt(10000);

    double rt =0.9-r.nextDouble();

    }


    Main Class:

    public class MainClass {

    //create employee name array

    String[] nameList=
    {"Andrew","Erin","Mariatu","Brooke","Hugh",
    "Carmen","Alexandria","Effiong","Benjamin","Sean-Michael",
    "Margaret","Rafeal","Nicholas","Stephanie","Diana","Justin",
    "Catherine","Jaffrey","Aras","Ji","Gretchen","Keith","John",
    "Matthew","Emma","Wesley","Sarah","Christopher","Ryan","Phuong",
    "Sharath","David","Kerin","Paul","Kevin","Charles","Robert","Jon"
    ,"Tom","Steve","Craig","Justin","Larry","Curly","Moe"};


    public static void main(String[] args)
    {


    Hourly Salary Class:

    public class HourlyEmployee extends Employee {

    private double hours, hourly_rate;

    //Constructors
    HourlyEmployee() {
    super();
    hours=0.0;
    hourly_rate=0.0;
    }
    HourlyEmployee(int id, String name, double height, double hrs, double hr_rate) {
    super(id, name, height);
    hours = hrs;
    hourly_rate = hr_rate;
    }

    public String toString(){
    }
    public double getSalary(){
    }
    }


    Parent Employee Class:

    public abstract class Employee {

    private int id;
    private String name;
    private double height;

    //Constructors
    Employee(){
    id = -1;
    name = "";
    height=-1.0;

    }

    Employee(int idVal, String nameVal, double heightVal){
    id=idVal;
    name=nameVal;
    height=heightVal;

    }

    // Readers
    public static String getName(){
    }
    public static double getHtInch(){
    }
    public static double getHtCm(){
    }
    public String toString(){
    }
    public abstract double getSalary(
    );

    //Writers
    public static void setName(String s){
    }
    public static void setHtInch(double h){
    }
    public static void setHtCm(double h){
    }


    }



    That's all I got, and that's all I know. PLEASE HELP, PLEEEEASE!!!!
     
  2. sprite

    sprite Active Member

    Joined:
    May 20, 2003
    Messages:
    2,967
    Likes Received:
    0
    Location:
    MI, USA
    Yeah, I'd say you're pretty lost. I re-wrote your "random_number" class using your calculations and commented what it is doing, and put in an example of creating & calling that class from MainClass. That should get you a start. You might want to look at a resource on Java class/method/variable naming conventions too.

    Code:
    package code;
    
    import java.util.*;
    
    public class MainClass {
    
    	
    	public static void main(String[]args)
    	{
    		//Creates a new instance of the "random_number" class
    		random_number rdmnum = new random_number();
    
    		//Simple example of using the "get" methods of
    		//the random_number class.
    		System.out.println(rdmnum.getN());
    		System.out.println(rdmnum.getH());
    		//etc...
    	}
    	
    }
    
    class random_number
    {
    	//This is a class level variable. It gets initialized in the constructor,
    	//and is used by all the public "get" calls. By having this be a class level
    	//variable you avoid the processing overhead of creating a new "Random" object for
    	//each calculation. This variable is visible only to methods inside the "random_number"
    	//class
    	private Random r;
    	
    	
    	//This is the class constructor, and is automatically run when you create an instance
    	//of this class. All it does is instantiate the class level variable "r" (above) to a
    	//new instance of the Random object;
    	public random_number()
    	{
    		r = new Random();
    	}
    	
    
    	//All of these methods do is simply return the results of the calculation
     
    	public int getN()
    	{
    		return r.nextInt(20);
    	}
    
    	public int getH()
    	{
    		return 60+r.nextInt(15);		
    	}
    
    	public int getT()
    	{
    		return r.nextInt(3);
    	}
    
    	public int getHours()
    	{
    		return 30+r.nextInt(31);
    	}
    
    	public double getRate()
    	{
    		return Math.round(500+r.nextInt(1001)/100);
    	}
    
    	public int getYr()
    	{
    		return 25000+r.nextInt(125001);
    	}
    
    	public int getComm()
    	{
    		return 500+r.nextInt(1001);
    	}
    
    	public int getSales()
    	{
    		return r.nextInt(10000);
    	}
    
    	public double getRt()
    	{
    		return 0.9-r.nextDouble();
    	}
    	
    }
    
     
  3. DaVega366

    DaVega366 Guest

    Wait, my prof told us we need different files for each class.

    Main Class

    Employee Class (parent)

    Salary Class
    Commision Class
    Hourly Class

    Random Class.
     
  4. DaVega366

    DaVega366 Guest

    Objectives Create an abstract class.
    Create several classes that inherit from that class
    Create multiple objects of different classes
    Use random numbers
    Experience polymorphism

    This program will do a payroll for a company with three kinds of employees. First, salaried employees who have a fixed annual salary. Each week they receive exactly 1/52 of their annual salary. Second, hourly employees whose weekly pay is the number of hours they work times their hourly rate, with time and a half for any hours over 40. And third, commissions employees whose weekly salary is a fixed base plus a percentage of their sales that week. So we will want three classes, each with its own set of data and each with its own way of computing salary.

    Salary employee
    Data: annual salary
    Salary computation: annual salary/52

    Hourly employee
    Data: hours worked, hourly rate
    Salary computation: hours*rate for the first 40 hours and
    1.5*hours*rate for hours over 40.

    Commission employee
    Data: weekly base pay, sales, commission rate
    Salary computation: base + sales*rate

    All employees will have an employee id number (integer), a name (String), and a height (double). You should create your class so that height can be read or written in either inches or in centimeters, but make sure that these two values are consistent.


    Program

    Step 1. Create an array capable of holding 20 employees. Then fill in the array with randomly generated employees

    id number: same as array index (0…19).
    name: randomly chosen from the name array (below).
    height: random number of inches chosen in the range 60-84.
    employee type: randomly chosen among salary, hourly, and commission

    For salary employees:
    annual salary: random integer in the range 25000-150000

    For hourly employees:
    hours: random integer in the range 30-60
    hourly rate: random number with 2 decimal places in the range 5.00-15.00

    For commission employees:
    commission base: random integer 500-1500
    sales: random integer in the range 0-10000
    commission rate: random number in the range 0.0-0.1[FONT=&quot] [/FONT]
    [FONT=&quot] [/FONT]
    [FONT=&quot]Step 2. Go through the array you created above and generate the payroll information consisting of the information about each employee (from [/FONT]toString()[FONT=&quot]), and the salary (from [/FONT]getSalary()[FONT=&quot]). If you set things up properly, the body of the loop to generate the payroll should have only one line of code![/FONT]
    [FONT=&quot] [/FONT]
    [FONT=&quot]Your program should require no user interaction.[/FONT]
    [FONT=&quot] [/FONT]
    [FONT=&quot]Using the Random class[/FONT]
    [FONT=&quot] [/FONT]
    [FONT=&quot]First, you have to import [/FONT]java.util.*[FONT=&quot] to make the random number generator available. Then you create a random number generator by[/FONT]
    [FONT=&quot] [/FONT]
    [FONT=&quot] [/FONT]Random r = new Random();

    [FONT=&quot]After that, you can generate (pseudo) random integers with [/FONT]
    [FONT=&quot] [/FONT]
    [FONT=&quot] [/FONT]r.nextInt()[FONT=&quot] or [/FONT]r.nextInt(n)[FONT=&quot] where n is an integer.[/FONT]
    [FONT=&quot] [/FONT]
    [FONT=&quot]Note that the first form will generate integers in the full integer range -231…+231, so you would have to take the absolute value and then use mod to get the desired range. The second form generates random integers in the range 0…n-1. So, for example, if you needed random integers in the range 100-200, you could use[/FONT]
    [FONT=&quot] [/FONT]
    [FONT=&quot] [/FONT]r.nextInt(101)+100
     
  5. sprite

    sprite Active Member

    Joined:
    May 20, 2003
    Messages:
    2,967
    Likes Received:
    0
    Location:
    MI, USA
    :uh: Then declare random_number as public and put it in its own file. Nobody's going to write your assignment for you, I'm just trying to give you a push start.
     
  6. DaVega366

    DaVega366 Guest

    If you're going to be an asshole about it, don't fucking post anything. I'd rather not get help at all.

    I didn't understand what you were doing, that's why I posted PART of what the assignment is, because I thought you didn't understand what I was asking in the first place. I never asked anybody to write it for me.
     
  7. Peyomp

    Peyomp New Member

    Joined:
    Jan 11, 2002
    Messages:
    14,017
    Likes Received:
    0
    Dude he COMMENTED HIS CODE. Did you even read it? He explained what he is doing. Thats a lesson to you: comment, or nobody else can understand your code.
     
  8. Kingfisher

    Kingfisher Keepin L's lit

    Joined:
    Mar 29, 2003
    Messages:
    4,736
    Likes Received:
    0
    Location:
    Southern California
    BTW, does anyone recommend a good JAVA book/compiler? Links please I have to learn/familiarize myself with it before I transfer out to the UC. Thanks.
     
  9. DaVega366

    DaVega366 Guest

    I'm not a dude.

    This class to me is like taking Chinese.
    I'm sorry I don't understand comp programming, I was just asking for help and got attacked for not understanding.
     
  10. Peyomp

    Peyomp New Member

    Joined:
    Jan 11, 2002
    Messages:
    14,017
    Likes Received:
    0
    It sounds like you have alot of reading to do. Go back, and carefully study your book and the examples there, and then come back to this problem. Ask the professor/TA for help. You're in over your head.
     

Share This Page