每吨货物每公里运费P与运输距离S有关,路途越远,每公里运价越低。公式如下:
p=10 s<100
8 100<=s<150
7 150<=s<200
6 200<=s<300
5.5 300<=s<500
5 s>=500
如果所付的总运费超过5000元时,再给予九五折优惠,
从键盘输入货物吨数、运输公里数,求应付的运费,要求精确到角、分。
//不用方法
import java.util.Scanner;
class Dome6
{
public static void main(String[] args){
Scanner sc=new Sacnner(System.in);
System.out.println("请输入你要运输的吨数:");
double x=sc.nextInt();
System.out.println("请输入你要运输的距离:");
double s=sc.nextInt();
if(s<100){
int p=10;
if(x*p<5000){
System.out.println("需要的运费为:"+(x*p));
}else{ System.out.println("需要的运费为:"+(x*p)*0.95); }
}else if(s>=100&&s<150){
int p=8;
if(x*p<5000){
System.out.println("需要的运费为:"+(x*p));
}else{ System.out.println("需要的运费为:"+(x*p)*0.95); }
}else if(s>=150&&s<200){
int p=7;
if(x*p<5000){
System.out.println("需要的运费为:"+(x*p));
}else{ System.out.println("需要的运费为:"+(x*p)*0.95); }
}else if(s>=200&&s<300){
int p=6;
if(x*p<5000){
System.out.println("需要的运费为:"+(x*p));
}else{ System.out.println("需要的运费为:"+(x*p)*0.95); }
}else if(s>=300&&s<500){
int p=5.5;
if(x*p<5000){
System.out.println("需要的运费为:"+(x*p));
}else{ System.out.println("需要的运费为:"+(x*p)*0.95); }
}else if(s>=500){
int p=5;
if(x*p<5000){
System.out.println("需要的运费为:"+(x*p));
}else{ System.out.println("需要的运费为:"+(x*p)*0.95); }
}
}
}
}
//使用方法后
import java.util.Scanner;
class Dome6
{
public static void main(String[] args){
Scanner sc=new Scanner(System.in);
System.out.println("请输入你要运输的吨数:");
double x=sc.nextInt();
System.out.println("请输入你要运输的距离:");
double s=sc.nextInt();
if(s<100){
double p=10;
Freight(x,p);
}else if(s>=100&&s<150){
double p=8;
Freight(x,p);
}else if(s>=150&&s<200){
double p=7;
Freight(x,p);
}else if(s>=200&&s<300){
double p=6;
Freight(x,p);
}else if(s>=300&&s<500){
double p=5.5;
Freight(x,p);
}else if(s>=500){
double p=5;
Freight(x,p);
}
}
public static void Freight(double x,double p){
if (x*p>5000)
{
System.out.println("需要的运费为:"+(x*p)*0.95);
} else{
System.out.println("需要的运费为:"+(x*p));
}
}
}
p=10 s<100
8 100<=s<150
7 150<=s<200
6 200<=s<300
5.5 300<=s<500
5 s>=500
如果所付的总运费超过5000元时,再给予九五折优惠,
从键盘输入货物吨数、运输公里数,求应付的运费,要求精确到角、分。
//不用方法
import java.util.Scanner;
class Dome6
{
public static void main(String[] args){
Scanner sc=new Sacnner(System.in);
System.out.println("请输入你要运输的吨数:");
double x=sc.nextInt();
System.out.println("请输入你要运输的距离:");
double s=sc.nextInt();
if(s<100){
int p=10;
if(x*p<5000){
System.out.println("需要的运费为:"+(x*p));
}else{ System.out.println("需要的运费为:"+(x*p)*0.95); }
}else if(s>=100&&s<150){
int p=8;
if(x*p<5000){
System.out.println("需要的运费为:"+(x*p));
}else{ System.out.println("需要的运费为:"+(x*p)*0.95); }
}else if(s>=150&&s<200){
int p=7;
if(x*p<5000){
System.out.println("需要的运费为:"+(x*p));
}else{ System.out.println("需要的运费为:"+(x*p)*0.95); }
}else if(s>=200&&s<300){
int p=6;
if(x*p<5000){
System.out.println("需要的运费为:"+(x*p));
}else{ System.out.println("需要的运费为:"+(x*p)*0.95); }
}else if(s>=300&&s<500){
int p=5.5;
if(x*p<5000){
System.out.println("需要的运费为:"+(x*p));
}else{ System.out.println("需要的运费为:"+(x*p)*0.95); }
}else if(s>=500){
int p=5;
if(x*p<5000){
System.out.println("需要的运费为:"+(x*p));
}else{ System.out.println("需要的运费为:"+(x*p)*0.95); }
}
}
}
}
//使用方法后
import java.util.Scanner;
class Dome6
{
public static void main(String[] args){
Scanner sc=new Scanner(System.in);
System.out.println("请输入你要运输的吨数:");
double x=sc.nextInt();
System.out.println("请输入你要运输的距离:");
double s=sc.nextInt();
if(s<100){
double p=10;
Freight(x,p);
}else if(s>=100&&s<150){
double p=8;
Freight(x,p);
}else if(s>=150&&s<200){
double p=7;
Freight(x,p);
}else if(s>=200&&s<300){
double p=6;
Freight(x,p);
}else if(s>=300&&s<500){
double p=5.5;
Freight(x,p);
}else if(s>=500){
double p=5;
Freight(x,p);
}
}
public static void Freight(double x,double p){
if (x*p>5000)
{
System.out.println("需要的运费为:"+(x*p)*0.95);
} else{
System.out.println("需要的运费为:"+(x*p));
}
}
}