import java.util.*;
class Taxi{
float len; //公里
float start_price; //起价
float start_len; //起始里程
float per_price; //每公里价格
float price; //总价
}
public class set_price()
{
int curr_hour=Calendar.getInstance().get(Calendar.HOUR_OF_DAY);
if(curr_hour=7&&curr_hour<=23)
{
start_price=10;
per_price=1.2f; }
else{
start_price=11;
per_perice=1.4f;
}
}
public void calc(float len){
this.len=len;
set_price();
if(len<=start_len)price=start_price;
else
price=start_price+per_price*(len-start_len);
price=Math.round(price);
}
public void show(){
System.out.println("起价:"+start_price);
System.out.println("起始公里:"+start_len);
System.out.println("每公里价格"+per_price);
System.out.println("里程"+len);
System.out.println("==============================");
System.out.println("总价:"+price); }
public class calctaxi{
public static void main(String args[]){
Taxi ta1=new Taxi();
int len=0;
try
{
len=Integer.parseInt(args[0]);
}
catch(NumberFormatException ee){
System.out.println("请输入合法公里数!");
return;
}
ta1.calc(len);
ta1.show();
}
}
class Taxi{
float len; //公里
float start_price; //起价
float start_len; //起始里程
float per_price; //每公里价格
float price; //总价
}
public class set_price()
{
int curr_hour=Calendar.getInstance().get(Calendar.HOUR_OF_DAY);
if(curr_hour=7&&curr_hour<=23)
{
start_price=10;
per_price=1.2f; }
else{
start_price=11;
per_perice=1.4f;
}
}
public void calc(float len){
this.len=len;
set_price();
if(len<=start_len)price=start_price;
else
price=start_price+per_price*(len-start_len);
price=Math.round(price);
}
public void show(){
System.out.println("起价:"+start_price);
System.out.println("起始公里:"+start_len);
System.out.println("每公里价格"+per_price);
System.out.println("里程"+len);
System.out.println("==============================");
System.out.println("总价:"+price); }
public class calctaxi{
public static void main(String args[]){
Taxi ta1=new Taxi();
int len=0;
try
{
len=Integer.parseInt(args[0]);
}
catch(NumberFormatException ee){
System.out.println("请输入合法公里数!");
return;
}
ta1.calc(len);
ta1.show();
}
}
import java.util.*;
class Taxi{
float len; //公里
float start_price; //起价
float start_len; //起始里程
float per_price; //每公里价格
float price; //总价 public void set_price() //<-------这儿你写错了class 改为void试试
{
int curr_hour=Calendar.getInstance().get(Calendar.HOUR_OF_DAY);
if(curr_hour=7&&curr_hour<=23)
{
start_price=10;
per_price=1.2f;
}
else{
start_price=11;
per_perice=1.4f;
}
}
public void calc(float len){
this.len=len;
set_price();
if(len<=start_len)
price=start_price;
else
price=start_price+per_price*(len-start_len);
price=Math.round(price);
}
public void show(){
System.out.println("起价:"+start_price);
System.out.println("起始公里:"+start_len);
System.out.println("每公里价格"+per_price);
System.out.println("里程"+len);
System.out.println("==============================");
System.out.println("总价:"+price);
}
}
public class calctaxi{
public static void main(String args[]){
Taxi ta1=new Taxi();
int len=0;
try
{
len=Integer.parseInt(args[0]);
}
catch(NumberFormatException ee){
System.out.println("请输入合法公里数!");
return;
}
ta1.calc(len);
ta1.show();
}
}没帮你调试,你自己试一下,有错再说吧
class Taxi{
float len; //公里
float start_price; //起价
float start_len; //起始里程
float per_price; //每公里价格
float price; //总价
public void set_price()
{
int curr_hour=Calendar.getInstance().get(Calendar.HOUR_OF_DAY);
if(curr_hour==7&&curr_hour<=23)
{
start_price=10;
per_price=1.2f; }
else{
start_price=11;
per_price=1.4f;
}
}
public void calc(float len){
this.len=len;
set_price();
if(len<=start_len)price=start_price;
else
price=start_price+per_price*(len-start_len);
price=Math.round(price);
}
public void show(){
System.out.println("起价:"+start_price);
System.out.println("起始公里:"+start_len);
System.out.println("每公里价格"+per_price);
System.out.println("里程"+len);
System.out.println("==============================");
System.out.println("总价:"+price); }
}
public class calctaxi{
public static void main(String args[]){
Taxi ta1=new Taxi();
int len=0;
try
{
len=Integer.parseInt(args[0]);
}
catch(NumberFormatException ee){
System.out.println("请输入合法公里数!");
return;
}
ta1.calc(len);
ta1.show();
}
}
结果:
起价:11.0
起始公里:0.0
每公里价格1.4
里程1.0
==============================
总价:12.0