package com.zf.s0;
import java.util.Scanner;
public class Charge {
public double CalculateCost(double rate,String season){ //计算电费
double sum=0;
if(season.equals("Sumer")){
sum= rate*0.49;
}else if(season.equals("Winter")){
sum = (rate-20)*0.49;
}
return sum;
}
public double PowerRate(){ //输入用电数
double powerrate;
Scanner sc = new Scanner(System.in);
powerrate = sc.nextDouble();
return powerrate;
}
public String Season(){ //输入季节
String season;
Scanner sc1 = new Scanner(System.in);
season=sc1.next();
return season;
}
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
double rate;
String season;
Charge a= new Charge();
System.out.println("请输入用电数:");
rate=a.PowerRate();
System.out.println("请输入季节(Summer/Winter)");
season=a.Season();
System.out.println("电费为: "+a.CalculateCost(rate, season));
}
}
不知道这个符合你的要求不