62,625
社区成员
发帖
与我相关
我的任务
分享
public class Person {
private String name;
private double salary;
private int achieve;
public Person(String name, double salary, int achieve) {
super();
this.name = name;
this.salary = salary;
this.achieve = achieve;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public double getSalary() {
return salary;
}
public void setSalary(double salary) {
this.salary = salary;
}
public int getAchieve() {
return achieve;
}
public void setAchieve(int achieve) {
this.achieve = achieve;
}
}
public class Adjust implements Runnable {
Person p = null;
public Adjust(Person p) {
super();
this.p = p;
}
public synchronized void run() {
while (p.getAchieve()>0) {
p.setSalary(p.getSalary() + 1000);
System.out.println("主管"+Thread.currentThread().getName()+"给"+p.getName()+"加薪"+1000+p.getName()+"现在工资"+p.getSalary());
p.setAchieve(p.getAchieve()-100);
}
}
}
public static void main(String[] args) {
// TODO Auto-generated method stub
Person p=new Person("zhangsan", 10000, 1500);
Adjust A=new Adjust(p);
Adjust B=new Adjust(p);
Thread tA=new Thread(A, "A");
Thread tB=new Thread(B,"B");
tA.start();
tB.start();
}
public class Person {
public String name;
public double salary;
public int achieve;
public Person(String name, double salary,int achieve) {
super();
this.name = name;
this.salary = salary;
this.achieve=achieve;
}
public double getSalary() {
return salary;
}
public void setSalary(double salary) {
this.salary = salary;
}
public int getAchieve() {
return achieve;
}
public void setAchieve(int achieve) {
this.achieve = achieve;
}
public boolean achievement() {
if(achieve>100) return true;
else return false;
}
}
public class Adjust implements Runnable {
Person p = null;
public Adjust(Person p) {
super();
this.p = p;
}
public synchronized void run() {
while (true) {
if (p.achievement()) {
p.setSalary(p.getSalary() + 1000);
p.setAchieve(0);
}
}
}
}
public class test {
public static void main(String[] args) {
// TODO Auto-generated method stub
Person p=new Person("zhangsan", 10000, 150);
Adjust A=new Adjust(p);
Adjust B=new Adjust(p);
Thread tA=new Thread(A);
Thread tB=new Thread(B);
tA.start();
tB.start();
}
}