第一次寫,用了什么也不懂,只是能實(shí)現(xiàn),感覺懵的有些注釋也懶得刪了,感覺有些可以改進(jìn)的,下次改,這次就這樣先發(fā)出來了
import java.io.InputStream;
public class Car
{
//String?
String str1 = "1\t 奧迪A4\500元/天\t\t載客:4人";
String str2 = "2\t馬自達(dá)6\t400元/天\t\t載客:4人 ";
String str3 = "3\t金龍\t800元/天\t\t載人20";
String str4 = "4\t皮卡雪6\t450元/天\t\t載客4人;載貨4噸 ";
String str5 = "5\t松花江 \t400元/天\t\t載貨:4噸 ";
String str6 = "6\t依維柯\t1000元/天\t\t載貨:20噸";
public void show1()
{
System.out.println(str1);
System.out.println(str2);
System.out.println(str3);
System.out.println(str4);
System.out.println(str5);
System.out.println(str6);
}
}
public class Dada?
{
/**
* @param args
*/
public static void main(String[] args)
{
float money1 = 500;
float money2 = 400;
float money3 = 800;
float money4 = 450;
float money5 = 400;
float money6 = 1000;
String str="";
String ste="";
//String [] car1 ={"奧迪A4","馬自達(dá)6","皮卡雪6","金龍","松花江","依維柯"};
/*String car1 = "奧迪A4";
String car2 = "馬自達(dá)6";
String car3 = "皮卡雪6";
String car4 = "金龍";
String car5 = "松花江";
String car6 = "依維柯";?
*/
// TODO Auto-generated method stub
System.out.println("您好!歡迎來到噠噠租車系統(tǒng)!");
System.out.println("請問您是否需要租車?不是請按0退出,按任意鍵進(jìn)入租車界面。");
Scanner input = new Scanner(System.in);
int i = input.nextInt();? ? ?
if(i==0)
{
System.out.println("再見!歡迎您下次使用噠噠租車系統(tǒng)");
}
else
{
System.out.println("可租車輛型號及價格表:");
System.out.println("序號\t汽車名稱\t租金\t\t容量"? ? ? ? ? ? );
//車輛信息方法調(diào)用,車輛信息表
Car car = new Car();
car.show1();
}
System.out.println("請輸入您要租汽車的數(shù)量");
int num =input.nextInt();
float money = 0;
double weigth =0;
int sum = 0;
? ? ? ? //定義空字符數(shù)組strr,便于下面用來賦值車輛名稱
? ? ? ??
? ? ? ??
? ? ? ??
for (int j=1;j<=num;j++)
{
System.out.println("請輸入第"+j+"量車的序號!");
int k =input.nextInt();
switch (k) {
case 1:money=money+money1; sum=sum+4; weigth=weigth+0; str+= "奧迪A4 ";
? ? break;
case 2:money=money+money2; sum=sum+4; weigth=weigth+0; str+="馬自達(dá)6";
break;?
case 3:money=money+money3; sum=sum+4; weigth=weigth+2; ste+="皮卡雪6";
? ? break;
case 4:money=money+money4; sum=sum+20; weigth=weigth+0; str+="金龍";
? ? break;
case 5:money=money+money5; sum=sum+0; weigth=weigth+4; ste+="松花江";
? ? ? ? ? ? ? ? break;
? ? ? ? ? ? default:money=money+money6; sum=sum+0; weigth=weigth+20; ste+="依維柯";
break;
}
}
System.out.println("請輸入所租天數(shù):");
int day = input.nextInt();
System.out.println("您的賬單為:");
System.out.println("***可載人的車輛有:\t"+str+"可載:"+sum+"人");
System.out.println("");//輸出車輛信息
System.out.println("***載貨的車有:\t"+ste+"可載貨:"+weigth+"噸");
System.out.println("租車總價格為:"+money*day);
}
}
2019-09-17
你這是來炫耀的吧? 我還沒寫過這么大的程序? ? 提點(diǎn)意見吧
? ?我覺得你可以定義一個Car父類或抽象類? ? 然后載客人數(shù)和車型號分別用兩個屬性來表示