这是我的程序:
import java.io.*;
import java.util.*;
abstract class Employee{
float n,m,t;
Scanner in =new Scanner(System.in);
abstract float earning();
}
final class Boss extends Employee{
public float earning(){
System.out.print("请输入Boss的每周工资:");
float a=in.nextFloat();
return a;
}
}
final class CommissionWorker extends Employee{
public float earning(){
System.out.print("请输入CommissionWorker的每周基本工资:");
float n=in.nextFloat();
System.out.print("请输入CommissionWorker的销售额:");
float m=in.nextFloat();
System.out.print("请输入CommissionWorker的销售额的权数:");
float c=in.nextFloat();
t=n+m*c;
return t;
}
}
final class PieceWorker extends Employee{
public float earning(){
System.out.print("请输入PieceWorker的生产产品数目:");
float n=in.nextFloat();
System.out.print("请输入PieceWorker每件产品的权数:");
float m=in.nextFloat();
t=n*m;
return t;
}
}
final class HourlyWorker extends Employee{
public float earning(){
System.out.print("请输入HourlyWorker的工作时间:");
float n=in.nextFloat();
System.out.print("请输入HourlyWorker的工作时间相关权数:");
float m=in.nextFloat();
return t=n*m;
}
}
public class Pay1{
public static void main(String[] args)throws IOException{
int a,b;
Boss ba=new Boss();
CommissionWorker bb=new CommissionWorker();
PieceWorker bc=new PieceWorker();
HourlyWorker bd=new HourlyWorker();
System.out.println("请输入您要进行的操作:1.Boss 2.CommissionWorker 3.PieceWorker 4.HourlyWorker");
Scanner in =new Scanner(System.in);
int i =in.nextInt();
switch(i){
case 1:System.out.println("Boss的每周工资为:"+ba.earning()+"元。");
break;
case 2:System.out.println("CommissionWorker的工资为每周"+(bb.earning())+"元。");
break;
case 3:System.out.println("PieceWorker的工资为每周"+(bc.earning())+"元。");
break;
case 4:System.out.println("HourlyWorker的工资为每周"+(bd.earning())+"元。");
break;
default:System.exit(1);
}
}
}
我想问的是,如果我想在switch(i)这里输入不是1到4的话,假如是5,可以显示输入错误,请重新输入,然后又回到刚开始的画面,应该怎样修改我的程序呢???