package?car_rental;
import?java.util.Arrays;
import?java.util.Scanner;
public?class?CarRental?{
public?static?Scanner?select=new?Scanner(System.in);
public?static?void?main(String[]?args)?{
System.out.println("歡迎使用答答租車系統(tǒng)\n請問您是否要租車:1是\t0否");
int?choice=input1();
switch(choice)?{
case?1:
System.out.println("您可租車的類型及其價目表:\r\n"?+?
"序號?????\t汽車名稱??????\t租金??????????????容量\r\n"?+?
"1?????????奧迪A4?????500元/天??????載人:4人\r\n"?+?
"2?????????馬自達(dá)6????400元/天??????載人:4人\r\n"?+?
"3?????????皮卡雪6?????450元/天?????載人:4人\r\n"?+?
"4?????????金龍???????????????800元/天??????載人:20人\r\n"?+?
"5?????????松花江????????????400元/天??????載貨:4t\r\n"?+?
"6?????????依維柯???????????1000元/天?????載貨:20t\r\n"?);
System.out.println("請輸入要租的數(shù)量:");
int?num?=input1();
int?array[]=?new?int?[num];
int?no1?=?0;
int?i=1;
while(true)?{
for(i=1;i<=num;i++)?{
System.out.println("請輸入你選擇車輛的序號:");
no1=input1();
System.out.println("請輸入第"+i+"輛車的序號:");
if(no1<=100)?{
array[i-1]=no1;
System.out.println("往數(shù)組里存的是"+array[i-1]);
}else?{
System.out.println("您所輸入的序號有誤,請重新輸入!");
break;
}
????}
????break;
????????}??
System.out.println("請輸入要租的天數(shù):");
int?day=input1();
System.out.println("\n\n\n");
System.out.println("***選車清單***:"+?Arrays.toString(array));
for(int?j=0;j<=num;j++)?{
for(int?n=0;n<j;n++)?{
System.out.println("******:"+?array[j]*day*500);
//后面這里我不知道該怎么統(tǒng)計選中的車,
//怎么把選中的車和其他的聯(lián)系起來統(tǒng)計金額
}
}
System.out.println("***租車天數(shù)***:"+day+"天");
break;
case?0:
System.out.println("謝謝您的光臨!");
break;
case?-1:
System.out.println("-1您的輸入有誤,請重新輸入\ntips:只能輸入1或0");
break;
default:
System.out.println("default您的輸入有誤,請重新輸入\ntips:只能輸入1或0");
break;
}
}
private?static?int?input1()?{
int?command1;
try?{
command1=select.nextInt();
return?command1;
}catch(Exception?e?)?{
select=new?Scanner(System.in);
return?-1;
}
}
}
2018-05-18
package com.project1;
import java.util.Scanner;
//import java.util.Arrays;
public class Initial extends Car {
?? ?/**
?? ? * @param args
?? ? */
?? ?
public static?? ?Scanner select=new Scanner(System.in);
?? ?public static void main(String[] args) {
?? ??? ?// TODO Auto-generated method stub
?? ??? ?
?? ??? ?System.out.println("welcome to 答答租車系統(tǒng)");
?? ??? ?System.out.println("按1進(jìn)入主菜單");
?? ??? ?//Scanner select=new Scanner(System.in);
?? ??? ?int n=select.nextInt();
?? ??? ?while(n==1)
?? ??? ?{
?? ??? ?System.out.println("您可租車的類型及其價目表:\r\n" +
?? ??? ??? ??? ?
??????????????????? "序號???? \t汽車名稱????? \t租金????????????? 容量\r\n" +
??????????????????? "1???????? 奧迪A4???? 500元/天????? 載人:4人\r\n" +
??????????????????? "2???????? 馬自達(dá)6??? 400元/天????? 載人:4人\r\n" +
??????????????????? "3???????? 皮卡雪6???? 450元/天???? 載人:4人\r\n" +
??????????????????? "4???????? 金龍?????????????? 800元/天????? 載人:20人\r\n" +
??????????????????? "5???????? 松花江??????????? 400元/天????? 載貨:4t\r\n" +
??????????????????? "6???????? 依維柯?????????? 1000元/天???? 載貨:20t\r\n" );
?? ?
?? ??? ?
?? ?System.out.println("請輸入所需租車的數(shù)量");
?? ?int num=select.nextInt();
?? ?int [] arrays1=new int[num];
?? ?int [] arrays2=new int[num];
?? ?for(int i=0;i<num;i++)
?? ?{
?? ?System.out.println("請輸入所要租車類型");
?? ?int price1=0;
?? ?int m=select.nextInt();
?? ?if(m>6||m<1){System.out.println("你輸入的有誤,請重新輸入!");break;}
?? ?switch(m)
?? ?{
?? ?case 1:?? price1=500;break;
?? ?case 2:? price1=400;break;
?? ?case 3:? price1=450;break;
?? ?case 4:? price1=800;break;
?? ?case 5:?? price1=400;break;
?? ?case 6:?? price1=1000;break;
?? ?
?? ?
?? ?}
?? ?arrays1[i]=price1;
?? ?System.out.println("請輸入所要租車時間");
?? ?int w=select.nextInt();
?? ?if(w<0){System.out.println("你輸入的有誤,請重新輸入!");break;}
?? ?arrays2[i]=w;
?? ?
?? ?}
?? ?long? price=0;
?? ?for(int i = 0;i<num;i++)
?? ??? ? price=price+arrays1[i]*arrays2[i];
?? ?System.out.println("你所需要繳納的費(fèi)用是:"+ price);
?? ?System.out.println("謝謝你的使用,歡迎下次再來!");?? ?
?? ?break;
?? ?}
?? ?
?? ?}
?? ?public void outprice() {
?? ??? ?// TODO Auto-generated method stub
?? ??? ?
?? ?}
?? ?public void outname() {
?? ??? ?// TODO Auto-generated method stub
?? ??? ?
?? ?}
?? ?
}
新手上路,望前輩指點(diǎn)
2017-12-20
package packages;
import java.util.Arrays;
import java.util.Scanner;
? ?public class CarRental {
? ? ? ?public static Scanner select=new Scanner(System.in);
? ? ? ?public class car{
? ? ? ? ? ?String carName;
? ? ? ? ? ?int money;
? ? ? ? ? ?int personNum;
? ? ? ? ? ?int thingsNum;
? ? ? ? ? ?public car( String carName,int money,int personNum,int thingsNum){
? ? ? ? ? ? ? ?this.carName=carName;
? ? ? ? ? ? ? ?this.money=money;
? ? ? ? ? ? ? ?this.personNum=personNum;
? ? ? ? ? ? ? ?this.thingsNum=thingsNum;
? ? ? ? ? ?}
? ? ? ? ? ?public int getMoney() {
? ? ? ? ? ? ? ?return money;
? ? ? ? ? ?}
? ? ? ? ? ?public int getPersonNum() {
? ? ? ? ? ? ? ?return personNum;
? ? ? ? ? ?}
? ? ? ? ? ?public int getThingsNum() {
? ? ? ? ? ? ? ?return thingsNum;
? ? ? ? ? ?}
? ? ? ? ? ?public String getCarName() {
? ? ? ? ? ? ? ?return carName;
? ? ? ? ? ?}
? ? ? ?}
? ? ? ?public static void main(String[] args) {
? ? ? ? ? ?CarRental text=new CarRental();
? ? ? ? ? ?car[] btw={text.new car("奧迪A4",500,4,0),
? ? ? ? ? ? ? ? ? ?text.new car("馬自達(dá)6",400,4,0),
? ? ? ? ? ? ? ? ? ?text.new car("皮卡雪6",450,4,0),
? ? ? ? ? ? ? ? ? ?text.new car("金龍",800,20,0),
? ? ? ? ? ? ? ? ? ?text.new car("松花江",400,0,4),
? ? ? ? ? ? ? ? ? ?text.new car("依維柯",1000,0,20)};
? ? ? ? ? ?System.out.println("歡迎使用答答租車系統(tǒng)\n請問您是否要租車:1是\t0否");
? ? ? ? ? ?int choice=input1();
? ? ? ? ? ?switch(choice) {
? ? ? ? ? ? ? ?case 1:
? ? ? ? ? ? ? ? ? ?System.out.println("您可租車的類型及其價目表:\r\n" +
? ? ? ? ? ? ? ? ? ? ? ? ? ?"序號 ? ? \t汽車名稱 ? ? ?\t租金 ? ? ? ? ? ? ?容量\r\n" +
? ? ? ? ? ? ? ? ? ? ? ? ? ?"1 ? ? ? ? 奧迪A4 ? ? 500元/天 ? ? ?載人:4人\r\n" +
? ? ? ? ? ? ? ? ? ? ? ? ? ?"2 ? ? ? ? 馬自達(dá)6 ? ?400元/天 ? ? ?載人:4人\r\n" +
? ? ? ? ? ? ? ? ? ? ? ? ? ?"3 ? ? ? ? 皮卡雪6 ? ? 450元/天 ? ? 載人:4人\r\n" +
? ? ? ? ? ? ? ? ? ? ? ? ? ?"4 ? ? ? ? 金龍 ? ? ? ? ? ? ? 800元/天 ? ? ?載人:20人\r\n" +
? ? ? ? ? ? ? ? ? ? ? ? ? ?"5 ? ? ? ? 松花江 ? ? ? ? ? ?400元/天 ? ? ?載貨:4t\r\n" +
? ? ? ? ? ? ? ? ? ? ? ? ? ?"6 ? ? ? ? 依維柯 ? ? ? ? ? 1000元/天 ? ? 載貨:20t\r\n" );
? ? ? ? ? ? ? ? ? ?System.out.println("請輸入要租的數(shù)量:");
? ? ? ? ? ? ? ? ? ?int num =input1();
? ? ? ? ? ? ? ? ? ?int array[]= new int [num];
? ? ? ? ? ? ? ? ? ?int no1 = 0;
? ? ? ? ? ? ? ? ? ?int i=1;
? ? ? ? ? ? ? ? ? ?while(true) {
? ? ? ? ? ? ? ? ? ? ? ?for(i=1;i<=num;i++) {
? ? ? ? ? ? ? ? ? ? ? ? ? ?System.out.println("請輸入你選擇車輛的序號:");
? ? ? ? ? ? ? ? ? ? ? ? ? ?no1=input1();
? ? ? ? ? ? ? ? ? ? ? ? ? ?System.out.println("請輸入第"+i+"輛車的序號:");
? ? ? ? ? ? ? ? ? ? ? ? ? ?if(no1<=100) {
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?array[i-1]=no1;
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?System.out.println("往數(shù)組里存的是"+array[i-1]);
? ? ? ? ? ? ? ? ? ? ? ? ? ?}else {
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?System.out.println("您所輸入的序號有誤,請重新輸入!");
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?break;
? ? ? ? ? ? ? ? ? ? ? ? ? ?}
? ? ? ? ? ? ? ? ? ? ? ?}
? ? ? ? ? ? ? ? ? ? ? ?break;
? ? ? ? ? ? ? ? ? ?}
? ? ? ? ? ? ? ? ? ?System.out.println("請輸入要租的天數(shù):");
? ? ? ? ? ? ? ? ? ?int day=input1();
? ? ? ? ? ? ? ? ? ?System.out.println("\n\n\n");
? ? ? ? ? ? ? ? ? ?System.out.println("***選車清單***:"+ Arrays.toString(array));
? ? ? ? ? ? ? ? ? ?int sum=0;
? ? ? ? ? ? ? ? ? ?for(int j=1;j<=num;j++) {
? ? ? ? ? ? ? ? ? ? ? ?System.out.println("第"+j+"輛車:\t\t\t"+"序號:"+array[j-1]+"\t\t\t"+"車名:"+btw[array[j-1]].getCarName()+"\t\t\t"+"每天的租金:"+btw[array[j-1]].getMoney());
? ? ? ? ? ? ? ? ? ? ? ?sum+=btw[array[j-1]].getMoney()*day;
? ? ? ? ? ? ? ? ? ? ? ? ? ?//后面這里我不知道該怎么統(tǒng)計選中的車,
? ? ? ? ? ? ? ? ? ? ? ? ? ?//怎么把選中的車和其他的聯(lián)系起來統(tǒng)計金額
? ? ? ? ? ? ? ? ? ?}
? ? ? ? ? ? ? ? ? ?System.out.println("***租車天數(shù)***:"+day+"天");
? ? ? ? ? ? ? ? ? ?System.out.println("共需要租金:"+sum);
? ? ? ? ? ? ? ? ? ?break;
? ? ? ? ? ? ? ?case 0:
? ? ? ? ? ? ? ? ? ?System.out.println("謝謝您的光臨!");
? ? ? ? ? ? ? ? ? ?break;
? ? ? ? ? ? ? ?case -1:
? ? ? ? ? ? ? ? ? ?System.out.println("-1您的輸入有誤,請重新輸入\ntips:只能輸入1或0");
? ? ? ? ? ? ? ? ? ?break;
? ? ? ? ? ? ? ?default:
? ? ? ? ? ? ? ? ? ?System.out.println("default您的輸入有誤,請重新輸入\ntips:只能輸入1或0");
? ? ? ? ? ? ? ? ? ?break;
? ? ? ? ? ?}
? ? ? ?}
? ? ? ?private static int input1() {
? ? ? ? ? ?int command1;
? ? ? ? ? ?try {
? ? ? ? ? ? ? ?command1=select.nextInt();
? ? ? ? ? ? ? ?return command1;
? ? ? ? ? ?}catch(Exception e ) {
? ? ? ? ? ? ? ?select=new Scanner(System.in);
? ? ? ? ? ? ? ?return -1;
? ? ? ? ? ?}
? ? ? ?}
? ?}