求java程序大佬运算import java.util.*;
/**
* @author hardneedl
*/
final class PriceComputer {
private abstract static class Pricer {
float getPrice(float weight, String postalCode, float length, float width, float height){
return (length * height * width + getPriceForWeight(weight)) * (1 + attachedPercent(postalCode));
}
abstract float getPriceForWeight(float weight);
abstract float attachedPercent(String postalCode);
}
private interface PricerFactory{
Pricer getPricer();
}
private static class DefaultPriceFactory implements PricerFactory{
public Pricer getPricer() {
return new Pricer() {
public float getPriceForWeight(float weight) {
if (weight = 0) return 0;
if (weight0weight = 5) return 12;
if (weight5weight = 15) return 14;
if (weight15weight = 34) return 17;
if (weight34weight = 45) return 21;
if (weight45weight = 60) return 33;
return 105;
}
public float attachedPercent(String postalCode) {
if (postalCode == null || postalCode.isEmpty())return .14f;
if (postalCode.charAt(0) == '4')return .05f;
if (postalCode.charAt(0) == '6')return .09f;
return .14f;
}
};
}
}
public static void main(String... args) {
Scanner scanner = new Scanner(System.in);
System.out.println("长度:");
float length = scanner.nextFloat();
System.out.println("宽度:");
float width = scanner.nextFloat();
System.out.println("高度:");
float height = scanner.nextFloat();
System.out.println("重量:");
float weight = scanner.nextFloat();
System.out.println("邮政编码:");
String postal = scanner.next();
PricerFactory pricerFactory = new DefaultPriceFactory();
Pricer pricer = pricerFactory.getPricer();
float price = pricer.getPrice(weight, postal,length,width,height);
System.out.printf("价格是:%f", price);
}
}
JAVA问题import java.util.*;
public class wen {
public static void main(String[] args) {
int c,s,d=0;
float p,w,f;
Scanner input=new Scanner(System.in);
System.out.print("请输入每公里每吨货物的基本运费(元): ");
p=input.nextFloat();
System.out.print("请输入货物的总重量(吨): ");
w=input.nextFloat();
System.out.print("请输入运输的总路程(km): ");
s=input.nextInt();
if(s=3000)
c=12;
else
c=s/250;
switch(c){
case 0:d=0; break;
case 1:d=2; break;
case 2:
case 3:d=5;
case 4:
case 5:
case 6:
case 7:d=8;break;
case 8:
case 9:
case 10:
case 11:d=10;break;
case 12:d=15;break;
}
f=p*w*s*(1-d/100.0f);
System.out.println("你所需付的运费是:"+f);
}
}
java难题 , 请求各位高手帮助我解答一下,大家有难题互帮互助?import java.util.Scanner;
interface Traffic{
double calc(double weight,double distance);//计算运费
}
class Trunk implements Traffic{
@Override
public double calc(double weight,double distance) {
return (distance=1000weight=60)?(weight*distance*120):(-1);
}
}
class Train implements Traffic{
@Override
public double calc(double weight, double distance) {
return (distance=900)?(weight*distance*250):(distance*weight*300);
}
}
class Plane implements Traffic{
@Override
public double calc(double weight, double distance) {
return (distance500)?(weight*distance*750):(-1);
}
}
class ZuChe{
private double distance;//距离
private double weight;//重量
public String useTraffic(Traffic t){
double result = t.calc(weight, distance);
return (result!=-1)?(""+result):(t.getClass().getName().equals(Trunk.class.getName())?"超重或者距离太远不能接单":"拒载");
推荐阅读
- 高明网络直播卖货技巧视频,网络直播卖货的技巧
- ios下载不了的软件下载,怎样设置手机下载不了软件下载
- 阿里云云服务器操作流程,阿里云服务器trojan
- 凌晨直播带货效果好吗,抖音凌晨直播带货
- php数据库模板 php数据库类库
- postgresql不能启动的简单介绍
- 视频号怎么设置公开呢,微信视频号怎么设置成公开
- python爬虫下youtube,python爬虫下载论文
- mysql怎么显示月份 mysql本月