问题是: -
为Majan电力设计计费系统。 Majan电力有两种类型的客户:国内和商业。不同的费率适用于国内连接和业务。
识别所需数据并实施所需操作。 程序应显示以下菜单:
欢迎来到Majan电费账单
1.国内客户
2.商业客户
输入您的选择:
如果选择为1,请阅读必要的信息,查找账单,打印账单明细 如果选择为2,请阅读必要的信息,查找账单,打印账单明细。
我解决了以下问题 - :
public void Domestic( String Dname, String Did,int current , int last , int cost )
{
int Dactual= current - last;
if(Dactual<=500)
{
cost = (int) (0.15 * Dactual);
System.out.println("The cost is "+cost );
}
else if(Dactual>501 && Dactual<1000)
{
cost = (int) (0.20 * Dactual);
System.out.println("The cost is "+cost );
}
else
{
cost = (int) (0.25 * Dactual);
System.out.println("The cost is "+cost );
}
}
public void Business(String Bid, String Bname, int Bcurrent , int Blast , int cost)
{
int Bactual= Bcurrent - Blast;
if(Bactual<=600)
{
cost = (int) (0.15 * Bactual);
System.out.println("The actual reading is "+Bactual);
System.out.println("The cost is "+cost );
}
else if(Bactual>601 && Bactual<1000)
{
cost = (int) (0.20 * Bactual);
System.out.println("The actual reading is "+Bactual);
System.out.println("The cost is "+cost );
}
else
{
cost = (int) (0.35 * Bactual);
System.out.println("The actual reading is "+Bactual);
System.out.println("The cost is "+cost );
}
}
public static void main(String[] args) {
Scanner sc = new Scanner (System.in);
Majan obj = new Majan() ;
System.out.println("Welcome to Majan Electricity Billing");
System.out.println("1. Domestic Customer ");
System.out.println("2. Business Customer ");
System.out.println("Select your choice");
int ch = sc.nextInt();
switch(ch)
{
case 1 :
System.out.println("Enter your name");
String Dname= sc.next();
System.out.println("Enter your Account No.");
String Did= sc.next();
System.out.println("Enter your current month reading");
int current= sc.nextInt();
System.out.println("Enter your previous month reading ");
int Dlast= sc.nextInt();
obj.Domestic(Dname, Did, current, Dlast, Dlast);
break;
case 2 :
System.out.println("Enter your name");
String Bname= sc.next();
System.out.println("Enter your Account No. ");
String Bid= sc.next();
System.out.println("Enter your current month reading");
int Bcurrent= sc.nextInt();
System.out.println("Enter your previous month reading ");
int Blast= sc.nextInt();
obj.Business(Bid, Bname, Bcurrent, Blast, Blast);
break;
default :
System.out.println("Wrong choice ! ");
}
}
}
问题是 - :
当我计算时,我无法看到最后的细节“名称,帐号等”。 和---这句话
System.out.println("The actual reading is "+Bactual);
dosnt出现了!
输出结果为: -
Welcome to Majan Electricity Billing
1. Domestic Customer
2. Business Customer
Select your choice
1
Enter your name
juju
Enter your Account No.
345
Enter your current month reading
300
Enter your previous month reading
100
The cost is 30**
谢谢你
答案 0 :(得分:0)
如果您选择1(国内客户),则调用Domestic
方法,实际上该方法不会执行System.out.println("The actual reading is "+Bactual);
。该行代码仅由您的类的Bussiness
方法执行(选项2)。
答案 1 :(得分:0)
伙计你传递的值是1 Domestic
,而你的家庭功能是
public void Domestic( String Dname, String Did,int current , int last , int cost )
{
int Dactual= current - last;
if(Dactual<=500)
{
cost = (int) (0.15 * Dactual);
System.out.println("The cost is "+cost );
}
else if(Dactual>501 && Dactual<1000)
{
cost = (int) (0.20 * Dactual);
System.out.println("The cost is "+cost );
}
else
{
cost = (int) (0.25 * Dactual);
System.out.println("The cost is "+cost );
}
}
你没有任何
的行System.out.println("The actual reading is "+Bactual);
这就是你没有在输出中得到The actual reading is
的原因。