谁能帮我做一道JAVA题? 急!急!急!

家庭生活用水每月在15t以下按每吨3元计算,在15-30t之间,则超过15t的部分要按每吨6元计算,如果每月用水超过30t,则一律按每吨8元计算。工业用水一律按每吨7元计... 家庭生活用水每月在15t以下按每吨3元计算,在15-30t之间,则超过15t的部分要按每吨6元计算,如果每月用水超过30t,则一律按每吨8元计算。工业用水一律按每吨7元计算。
现要求设计一个程序,输入用水吨数,并按用水类型计算出水费。

做出来的悬赏,感激不尽~!
展开
 我来答
山中小馆
2011-12-05 · 干一行,爱一行,专注零售近十载
山中小馆
采纳数:1082 获赞数:6811

向TA提问 私信TA
展开全部
给你个比较完整的吧...
import java.util.Scanner;

public class test {

public static void main(String[] args) {
Scanner sca = new Scanner(System.in);
while (true) {

System.out.println("请输入用水类型:1 生活用水 ;2 工业用水;3退出");
int b = sca.nextInt();
if(b==3){
break;
}
System.out.println("请输入用水量(吨数,不足一吨按一吨计算):");
int a = sca.nextInt();
if (b == 1 && a < 15) {
System.out.println("水费是" + a * 3);
} else if (b == 1 && a >= 15 && a < 30) {
System.out.println("水费是" + (30 * 3 + (a - 30) * 6));
} else if (b == 1 && a >= 30) {
System.out.println("水费是" + a * 8);
} else if (b == 2) {
System.out.println("水费是" + a * 7);
}
}
}

}
flyingFish211
2011-12-05 · TA获得超过2.1万个赞
知道大有可为答主
回答量:1.5万
采纳率:50%
帮助的人:1.1亿
展开全部
import java.util.Scanner;

public class WaterCalculator {

private static final int LIFE_WATER = 1;
private static final int INDUSTRY_WATER = 2;

public static void main(String[] args) {

Scanner scanner = new Scanner(System.in);
System.out.print("Please input the water type(1代表生活用水,2代表工业用水:");
int type = scanner.nextInt();

if(type != LIFE_WATER && type != INDUSTRY_WATER){
System.out.println("Error input type for water type. Only 1 and 2 allowed!");
System.exit(0);
}

System.out.print("Please input the quantity for the water this month:");
double quantity = scanner.nextDouble();

double fees = calcFees(type, quantity);
System.out.println("Waters fees is: " + fees);

}

private static double calcFees(int type, double quantity) {
if(type == LIFE_WATER){
if(quantity < 15){
return 3 * quantity;
}else if(quantity < 30){
return 3 * 15 + (quantity - 15) * 6;
}else{
return 7 * quantity;
}
}else{
return 8 * quantity;
}

}

}
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
hbb239
2011-12-05 · 超过10用户采纳过TA的回答
知道答主
回答量:24
采纳率:0%
帮助的人:24.7万
展开全部
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;

public class TestC {
public static void main(String[] args){
TestC t =new TestC();
Map map = t.getResult(15);
Iterator<String> it = map.keySet().iterator();
while(it.hasNext()){
String key = it.next();
System.out.println("类型:"+key+";水费:"+map.get(key));
}
}

private Map<String,Long> getResult(long t){
if(t<0){
return null;
}
Map map = new HashMap<String, Long>();
map.put("工业", t*7);
long family = 0;
if(t<=15){
family = 3*t;
}else if(t>15 && t<=30){
family = 15*3 +(t-15)*6;
}else if(t>30){
family = t * 8;
}
map.put("家庭", family);
return map;
}
}
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
忙碌的勺子
2011-12-05
知道答主
回答量:38
采纳率:0%
帮助的人:21万
展开全部
package com.xh.common;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class MathEx {

/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
System.out.println("请输入用水吨数(t):");
BufferedReader reader = new BufferedReader(new InputStreamReader(
System.in));
String userId = null;
try {
userId = reader.readLine();

} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}

int num = Integer.parseInt(userId);
int count = 0;
if(num<=15){
count = num*3;
}else if(num>15&&num<=30){
count = 3*15+(num-15)*6;
}else{
count = num*8;
}
System.out.println("生活用水钱数:"+count);
System.out.println("工业用水钱数:"+num*7);

}

}
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
波昭懿28
2011-12-05 · TA获得超过1537个赞
知道答主
回答量:58
采纳率:0%
帮助的人:41.9万
展开全部
public class Test {

/**
* @param args
*/

private static final int FEE_3 = 3; //每吨3块钱
private static final int FEE_6 = 6; //每吨6块钱
private static final int FEE_8 = 8; //每吨8块钱
private static final int FEE_7 = 7; //每吨7块钱

/**
* @author bianrx
* @param type
* @param t
* @return
*/
public static float calculateFee(String type, float t) {
float result = 0;

if(type.equals("01")) {

if(t <= 15) {
result = t *FEE_3;
} else if(t > 15 && t < 30) {
result = 15 *FEE_3 + (t-15) *FEE_6;
} else if(t > 30) {
result = t *FEE_8;
}

} else {
result = t *FEE_7;
}
return result;
}

public static void main(String[] args) {
float t = 45f;
String type = "02";//用01代表家庭用水类型 02代表家庭工业类型
System.out.println(calculateFee(type, t));

}

}

别忘了给分奥 呵呵
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
百度网友60c0594194
2011-12-05 · 超过21用户采纳过TA的回答
知道答主
回答量:56
采纳率:0%
帮助的人:62.9万
展开全部
import java.util.Scanner;

public class shuifei
{

public static double homepay(double water)
{
if(water<0)
{
System.out.println("输入错误!");
return -1;
}
else if(water>=0&&water<=15)
{
return water*3;
}
else if(water>15&&water<=30)
{
return (45+(water-15)*6);
}
else
{
return water*8;
}

}
public static double factorypay(double water)
{
if(water<0)
{
System.out.println("输入错误!");
return -1;
}
else
return water*7;

}
public static void main(String[] args)
{
Scanner in = new Scanner(System.in);
int n=1;
while(n==1)
{
System.out.println("输入用水类型 1.家庭用水 2.工业用水");
int type=in.nextInt();
if(type==1)
{
System.out.println("输入用水数量");
double mon=in.nextDouble();
double money=homepay(mon);
if(mon>=0)
{System.out.println("本月水费:"+money);}
}
else if(type==2)
{
System.out.println("输入用水数量");
double mon=in.nextDouble();
double money=factorypay(mon);
if(mon>=0)
{System.out.println("本月水费:"+money);}
}
else
{
System.out.println("输入错误");
}
System.out.println("按1继续,其他退出");
n=in.nextInt();
}
}
}
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
收起 更多回答(6)
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式