标题:JAVA程序小问题
取消只看楼主
josephzzq
Rank: 1
等 级:新手上路
帖 子:89
专家分:0
注 册:2007-3-18
 问题点数:0 回复次数:1 
JAVA程序小问题

这是我的程序:
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,可以显示输入错误,请重新输入,然后又回到刚开始的画面,应该怎样修改我的程序呢???

搜索更多相关主题的帖子: JAVA 
2007-05-09 21:11
josephzzq
Rank: 1
等 级:新手上路
帖 子:89
专家分:0
注 册:2007-3-18
得分:0 
谢谢你!!!!!!!!
2007-05-09 21:44



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-138028-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.128076 second(s), 8 queries.
Copyright©2004-2025, BCCN.NET, All Rights Reserved