Results 1 to 4 of 4
Thread: Need some help in an algorithm
- 04-03-2010, 07:13 PM #1
Member
- Join Date
- Apr 2010
- Posts
- 5
- Rep Power
- 0
Need some help in an algorithm
hello I have prepare to codes:
1) a timer that returns every sec the date
2) A simple program that returns some infos
What I want to do (and I cant) is:
every sec that the date is returned from prog 1, to return also the infos of prog 2
Prog 1
----------------------------
import java.awt.*;
import java.awt.event.*;
import java.util.*;
import javax.swing.*;
import javax.swing.Timer;
public class TimerTest
{
public static void main(String[] args)
{
ActionListener listener = new TimePrinter();
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(now);
Toolkit.getDefaultToolkit().beep();
}
}
______________________________
______________________________
prog 2
--------------------------------------------
import static java.lang.Math.*;
import java.awt.*;
import java.awt.event.*;
import java.util.*;
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, 6, 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
{
public void actionPerformed(ActionEvent event)
{
Date now = new Date();
System.out.println("At the tone, the time is " + now);
Toolkit.getDefaultToolkit().beep();
}
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);
}
}
- 04-03-2010, 07:27 PM #2
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,400
- Blog Entries
- 7
- Rep Power
- 17
Don't double post.
kind regards,
Jos
- 04-03-2010, 09:01 PM #3
Member
- Join Date
- Apr 2010
- Posts
- 5
- Rep Power
- 0
Jos hello ! sorry for bother you again (but I am kind of desperate to solve this exercise).
For the same problem, the last task that I have to resolve is:
For every tick of the timer (prog1), I want the value of the quantity basic_salary () to double (prog2). How can I do that ? Ay advice or hints would be valuable to me.
Thank you
Best regards and sorry this
- 04-04-2010, 01:13 PM #4
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,374
- Blog Entries
- 1
- Rep Power
- 18
Please stick with a one thread. Since you found a comment on the other thread from JosAH, I'm closing this thread.
Similar Threads
-
Help with an Algorithm
By Manfizy in forum New To JavaReplies: 22Last Post: 07-03-2009, 07:16 AM -
O(log n) algorithm help !!!!!!
By itseeker87 in forum New To JavaReplies: 8Last Post: 09-09-2008, 05:12 PM -
Help with algorithm
By susan in forum New To JavaReplies: 1Last Post: 07-13-2007, 10:26 PM -
Help me with this algorithm
By Marcus in forum Advanced JavaReplies: 3Last Post: 07-02-2007, 01:30 PM -
Help with Algorithm
By Daniel in forum Advanced JavaReplies: 2Last Post: 07-02-2007, 05:51 AM


LinkBack URL
About LinkBacks

Bookmarks