java课程的题目,问题在补充内,求高手。

java课程的题目,问题在补充内,求高手。,第1张

Scanner input=new Scanner(System.in)

   System.out.println("请输罩桥入本月用电量:")

   int num=0

   try {

   num=input.nextInt()

   } catch (Exception e) {

   System.out.println("请输入数字")

   }

   double count=0

   if(num<斗搏200){

   物销猛count=num*0.10

   }else if(num>=200 && num<=500){

   count=num*0.30

   }else{

   count=num*0.50

   }

   System.out.println("你需交电费:"+count)

import java.util.Scanner

public class TestAA {

 

 private static final float ELEC_PRICE = 0.7f    //单价

 private float lastMonth  //上个月的电表读数

 private float currentMonth //当前塌慎月的电表读数

 

 private Scanner scan = null

 

 private float getLastMonth() {

  return lastMonth

 }

 private void setLastMonth() {

  System.out.println("请输入上个月的电表读数:")

  scan = new Scanner(System.in)

  lastMonth = scan.nextFloat()

 }

 private float getCurrentMonth() {

  return currentMonth

 }

 private void setCurrentMonth() {

  System.out.println("请输入这个月的电表读数:")

  scan = new Scanner(System.in)

  currentMonth = scan.nextFloat()

 }

public static void main(String[] args) {

  TestAA aa = new TestAA()

  aa.setRecord()

  aa.showRecord()

  aa.calcUsedFee()

 }

public void setRecord() {

  setLastMonth()

  setCurrentMonth()

 }

 

 public void showRecord() {

  System.out.println("上个月的电表读数为:" + getLastMonth())

 旁镇 System.out.println("本月的电表读数为:" + getCurrentMonth())

 }

 

 public void calcUsedFee() {

  float totalMeasure = getCurrentMonth() - getLastMonth()

  运衫粗System.out.println("电费合计:" + totalMeasure * ELEC_PRICE)

 }

 

}

给你发这里圆首缺了,你先看看,有什么需要补充的告诉我就可以了。

import java.util.ArrayList

import java.util.Iterator

import java.util.List

class Customer{

private int customer_Number

private int electricity_Usage

public Customer(){}

public Customer(int no,int usage){

customer_Number = no

electricity_Usage = usage

}

public int getCustomer_Number() {

return customer_Number

}

public void setCustomer_Number(int customerNumber) {

customer_Number = customerNumber

}

public int getElectricity_Usage() {

return electricity_Usage

}

public void setElectricity_Usage(int electricityUsage) {

electricity_Usage = electricityUsage

}

}

public class ChargeSystem {

private List<Customer>list = new ArrayList<芹让Customer>()

public ChargeSystem(){

Customer c1 = new Customer(111,300)

Customer c2 = new Customer(222,100)

Customer c3 = new Customer(999,123)

list.add(c1)

list.add(c2)

list.add(c3)

}

public int count(int usage){

int money = 0

if(usage<=200){

money = usage * 11

}else{

money = count(200) + (usage-200)*8

}

return money

}

public static void main(String[] args) {

ChargeSystem cs = new ChargeSystem()

int customer_Number = 0

int electricity_Usage = 0

int money = 0

Iterator<Customer>it = cs.list.iterator()

while(it.hasNext()){

Customer sc = it.next()

customer_Number = sc.getCustomer_Number()

electricity_Usage = sc.getElectricity_Usage()

money = cs.count(electricity_Usage)

System.out.println("当前用户为:" + customer_Number + ",您当月的用电量为:" + electricity_Usage + ",需要上交的电费为:橘辩" + money)

if(customer_Number == 999){

System.out.println("Good Bye!")

}

}

}

}


欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/yw/12561323.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-05-26
下一篇 2023-05-26

发表评论

登录后才能评论

评论列表(0条)

保存