Results 1 to 1 of 1
  1. #1
    ea09530 is offline Member
    Join Date
    Apr 2010
    Posts
    5
    Rep Power
    0

    Default Problem to access data when a class calls another class

    Hello everybody,
    I am new to java and I can not finish this exercise.

    I have a timer (Prog1) that calls an Employee Report (Prog2).
    The forum gave me the answer how Prog1 can can call Prog2.
    For every tick of the timer (Prog1), how can I double the value of the field basic_salary (Prog2)????
    Any help/advice/hints to this would be valuable to me becuase I dont know how to fight it. Thanks. Michael

    PROGRAM1
    ----------------------------------------------------------------------------------------
    Java Code:
    import java.awt.*;
    import java.awt.event.*;
    import java.util.*;
    import javax.swing.*;
    import javax.swing.Timer; 
    // to resolve conflict with java.util.Timer
    
    public class TimerTest
    {  
       public static void main(String[] args)
       {  
          ActionListener listener = new TimePrinter();
    
          // construct a timer that calls the listener
          // once every 10 seconds
          Timer t = new Timer(1000, listener);
          t.start();
          JOptionPane.showMessageDialog(null, "Quit program?");
          System.exit(0);
       }
    }
    
    class TimePrinter implements ActionListener
    {  
       public void actionPerformed(ActionEvent event)
       {  
    	Date now = new Date();
    	System.out.println("Title current: " + now);
        Toolkit.getDefaultToolkit().beep();
        EmployeeProject3.main(null);
       }
    }
    -----------------------------------------------------------------------------------------


    PROGRAM2
    ----------------------------------------------------------------------------------------
    Java Code:
    import static java.lang.Math.*;
    public class EmployeeProject3
    {
    	public static void main(String[] args)
       	{   
    	  // construct a Manager object
    	  Executive A = new Executive("Executive", 300, 7, 3);
    	  Manager B = new Manager("Manager", 400, 7, 0);
          Employee[] staff = new Employee[7];
                
    	  // fill the staff array with Manager and Employee objects
          staff[0] = A;
          staff[1] = B;
          staff[2] = new Employee("Employee", 500, 7, 0);
          staff[3] = new Employee("Employee", 500, 7, 0);
          staff[4] = new Employee("Employee", 500, 7, 0);
          staff[5] = new Employee("Employee", 500, 7, 0);
          staff[6] = new Employee("Employee", 500, 7, 0);    
          
          // print out information about all Employee objects 
          
          for (Employee e : staff)
          { 
          System.out.println("Type: " + e.getName() + "\t Basic Salary|" + e.getBasic_Salary()
    	  + "\t Height|" + e.getHeight() + "\t Radius|" + e.getRadius()
    	  + "\t Bonus|" + e.getBonus()+"\t Total|" + e.getTotal());     
          }       	
       }
    }
    
    class Employee
    {	
    	private String name;
    	private double basic_salary, total, radius, height;
    	
    	  public Employee(String n, double s, double r, double h)
    	  {
          name = n;
          basic_salary= s;
          radius = r;
          height = h;
          }
       
       	  public String getName()
       	  {
          return name;
       	  }
    
       	  public double getBasic_Salary()
          {
          return basic_salary;
          }
       
       	  public double getRadius()
       	  {
       	  return radius;
       	  }
      
       	  public double getHeight()
       	  {
       	  return height;
       	  }
      
       	  public double getBonus()
       	  {
    	  double bonus=2*PI*radius;
    	  return Math.floor(bonus);
       	  }
       
       	  public double getTotal()
       	  {
    	  total=basic_salary+this.getBonus();
    	  return total;
       	  }
    }
    
    class Manager extends Employee
    {		
    	   public Manager(String n, double s, double r, double h)
    	   {
           super(n, s, r, h);
    	   }  
       
       	   public double getBonus()
       	   {
    	   double bonus=PI*pow (getRadius(),2);
    	   return Math.floor(bonus);
       	   }	    
    }
       
    class Executive extends Manager
    {	
    	   public Executive (String n, double s, double r, double h)
    	   {	
    	   super(n, s, r, h);
    	   }  
          
    	   public double getBonus()
    	   {
    	   double bonus=PI*pow (getRadius(),2)*getHeight();
    	   return Math.floor(bonus);
    	   }   
    }
    -----------------------------------------------------------------------------------------

    Moderator Edit: Code tags added
    Last edited by Fubarable; 04-04-2010 at 03:24 PM. Reason: Moderator Edit: Code tags added

Similar Threads

  1. Access LinkedList from another class
    By jboy in forum New To Java
    Replies: 20
    Last Post: 09-12-2009, 09:16 AM
  2. Replies: 8
    Last Post: 03-21-2009, 10:34 AM
  3. Replies: 3
    Last Post: 03-14-2009, 08:22 AM
  4. problem calling function from class to class
    By alin_ms in forum New To Java
    Replies: 3
    Last Post: 12-19-2008, 08:35 PM
  5. How to access system calls in java
    By Albert in forum New To Java
    Replies: 1
    Last Post: 07-13-2007, 04:12 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •