编写一个简单java通用程序
发布网友
发布时间:2022-04-29 03:40
我来回答
共4个回答
热心网友
时间:2023-10-09 13:37
public interface EmploySalary(){
public int getSalayy(int a,int b);
}
public class OfficeWorker implements employSalary(){
public int getSalayy(int a,int b){
return 12*(a+b*2);
}
}
public class Manager implements employSalary(){
public int getSalayy(int a,int b){
return 12*(a*2+b);
}
}
public class GetSalary(){
private EmploySalary employSalary;
public GetSalary(EmploySalary employSalary){
this.employSalary=employSalary;
}
public void setEmploySalary(EmploySalary employSalary){
this.employSalary=employSalary;
}
public int getYearSalary(int A,int B){
return employSalary.getSalayy(A,B);
}
}
public class Test(){
public static void main(String[] args){
int A=10;
int B=20;
OfficeWorker officeWorker=new OfficeWorker();
Manager manager =new Manager();
GetSalary getSalary=new GetSalary(officeWorker);
getSalary.getYearSalary(A,B);
getSalary.setEmploySalary(manager);
getSalary.getYearSalary(A,B);
}
}
热心网友
时间:2023-10-09 13:38
abstract class ComputeWage{
public abstract int getSalayy(int a,int b);
}
class Employee extends ComputeWage{
public int getSalayy(int a,int b){
return 12*(a+2*b);
}
}
class Manager extends ComputeWage{
public int getSalayy(int a,int b){
return 12*(2*a+b);
}
}
public class Test{
public static void main(String args[]){
int a=2000;
int b=1000;
ComputeWage com=new Employee();
System.out.println(com.getSalayy(a,b));
com=new Manager();
System.out.println(com.getSalayy(a,b));
}
}
热心网友
时间:2023-10-09 13:38
一楼是用接口实现的
二楼正解
非测试的类前也可加public
热心网友
时间:2023-10-09 13:39
mark
热心网友
时间:2023-10-09 13:37
public interface EmploySalary(){
public int getSalayy(int a,int b);
}
public class OfficeWorker implements employSalary(){
public int getSalayy(int a,int b){
return 12*(a+b*2);
}
}
public class Manager implements employSalary(){
public int getSalayy(int a,int b){
return 12*(a*2+b);
}
}
public class GetSalary(){
private EmploySalary employSalary;
public GetSalary(EmploySalary employSalary){
this.employSalary=employSalary;
}
public void setEmploySalary(EmploySalary employSalary){
this.employSalary=employSalary;
}
public int getYearSalary(int A,int B){
return employSalary.getSalayy(A,B);
}
}
public class Test(){
public static void main(String[] args){
int A=10;
int B=20;
OfficeWorker officeWorker=new OfficeWorker();
Manager manager =new Manager();
GetSalary getSalary=new GetSalary(officeWorker);
getSalary.getYearSalary(A,B);
getSalary.setEmploySalary(manager);
getSalary.getYearSalary(A,B);
}
}
热心网友
时间:2023-10-09 13:38
abstract class ComputeWage{
public abstract int getSalayy(int a,int b);
}
class Employee extends ComputeWage{
public int getSalayy(int a,int b){
return 12*(a+2*b);
}
}
class Manager extends ComputeWage{
public int getSalayy(int a,int b){
return 12*(2*a+b);
}
}
public class Test{
public static void main(String args[]){
int a=2000;
int b=1000;
ComputeWage com=new Employee();
System.out.println(com.getSalayy(a,b));
com=new Manager();
System.out.println(com.getSalayy(a,b));
}
}
热心网友
时间:2023-10-09 13:38
一楼是用接口实现的
二楼正解
非测试的类前也可加public
热心网友
时间:2023-10-09 13:39
mark
热心网友
时间:2023-10-09 13:37
public interface EmploySalary(){
public int getSalayy(int a,int b);
}
public class OfficeWorker implements employSalary(){
public int getSalayy(int a,int b){
return 12*(a+b*2);
}
}
public class Manager implements employSalary(){
public int getSalayy(int a,int b){
return 12*(a*2+b);
}
}
public class GetSalary(){
private EmploySalary employSalary;
public GetSalary(EmploySalary employSalary){
this.employSalary=employSalary;
}
public void setEmploySalary(EmploySalary employSalary){
this.employSalary=employSalary;
}
public int getYearSalary(int A,int B){
return employSalary.getSalayy(A,B);
}
}
public class Test(){
public static void main(String[] args){
int A=10;
int B=20;
OfficeWorker officeWorker=new OfficeWorker();
Manager manager =new Manager();
GetSalary getSalary=new GetSalary(officeWorker);
getSalary.getYearSalary(A,B);
getSalary.setEmploySalary(manager);
getSalary.getYearSalary(A,B);
}
}
热心网友
时间:2023-10-09 13:38
abstract class ComputeWage{
public abstract int getSalayy(int a,int b);
}
class Employee extends ComputeWage{
public int getSalayy(int a,int b){
return 12*(a+2*b);
}
}
class Manager extends ComputeWage{
public int getSalayy(int a,int b){
return 12*(2*a+b);
}
}
public class Test{
public static void main(String args[]){
int a=2000;
int b=1000;
ComputeWage com=new Employee();
System.out.println(com.getSalayy(a,b));
com=new Manager();
System.out.println(com.getSalayy(a,b));
}
}
热心网友
时间:2023-10-09 13:38
一楼是用接口实现的
二楼正解
非测试的类前也可加public
热心网友
时间:2023-10-09 13:39
mark