課程
/后端開發
/Java
/Java入門第二季 升級版
沒有頭緒!各位同學快來探討
2015-12-01
源自:Java入門第二季 升級版 12-2
正在回答
package 達達租車;
import java.util.*;
public class Carrental {
public static void main(String[] args) {
// TODO Auto-generated method stub
? ? ? ? Vehicle v=new Vehicle();
? ? ? ??
? ? ? ? Scanner reader=new Scanner(System.in);
? ? ? ? System.out.println("歡迎使用達達租車系統:");
? ? ? ? System.out.println("你是否要租車:1是 ? 0否");
? ? ? ? int s=reader.nextInt();
? ? ? ? if(s==1){
? ? ? ? ? ?v.information();
? ? ? ? ? ?System.out.println("請輸入您要租汽車的數量:");
? ? ? ? ? ?int a=reader.nextInt();
? ? ? ? ? ?int b[]=new int[a];
? ? ? ? ? ?for(int i=0;i<a;i++){
? ? ? ? ? System.out.println("請輸入第"+(i+1)+"輛車的序號:");
? ? ? ? ? b[i]=reader.nextInt();
? ? ? ? ? ?}
? ? ? ? ? ?System.out.println("請輸入租車天數:");
? ? ? ? ? ?int d=reader.nextInt();
? ? ? ? ? ?System.out.println("您的賬單:");
? ? ? ? ? ?v.showcar1(a,b);
? ? ? ? ? ?v.showcar2(a,b); ??
? ? ? ? ? ?v.bill(a,d,b);
? ? ? ? }
? ? ? ? else
? ? ? ? System.exit(0);
}
public class Vehicle {
?String []str={"奧迪A4","馬自達6","皮卡雪6","金龍 ","松花江","依維柯 ?"};
?int []p={500,400,450,800,400,1000};
?
? ? ?void information(){
? ? System.out.println("你可租車的類型及其價格表:");
? ? System.out.println("序號 ? ? ? ? ? ?汽車名稱 ? ? ? ? ? ? ? ?租金 ? ? ? ? ? ? ? ? ? ? ? ?容量 ? ");
? ? System.out.println("1. ? ?奧迪A4 ? ? 500元/天 ? ? ? ? ? 載人:4人 ? ? ?");
? ? System.out.println("2. ? ?馬自達6 ? ? 400元/天 ? ? ? ? ? 載人:4人 ? ? ?");
? ? System.out.println("3. ? ?皮卡雪6 ? ? 450元/天 ? ? ? ? ? 載人:4人 ? 載貨:2噸 ? ");
? ? System.out.println("4. ? ?金龍 ? ? ? ? ? ? ? ? ? ? ? ? 800元/天 ? ? ? ? ? 載人:20人 ? ? ?");
? ? System.out.println("5. ? ?松花江 ? ? ? ? ? ? ? ? ? ? 400元/天 ? ? ? ? ? 載貨:4噸 ? ? ");
? ? System.out.println("6. ? ?依維柯 ? ? ? ? ? ? ? ? ? ? 1000元/天 ? ? ? ?載貨:20噸 ? ? ?");
? ? ?}
? ? ?
? ? ?void showcar1(int a,int b[]){
? ? System.out.println("***可載人的車有:");
? ? for(int i=0;i<a;i++){
? ? if(b[i]<5)
? ? System.out.print(str[b[i]-1]+" ? "); ? ? ?
? ? }
? ? ?void showcar2(int a,int b[]){
? ? System.out.println("\n***可載人的車有:");
? ? if(b[i]>5||b[i]==3)
? ? System.out.print(str[b[i]-1]+" ? ");
? ?
? ? ? ? ?
? ? ?void bill(int a,int d,int b[]){ ? ?
? ? int m=0;
? ? ? ? m=m+(p[b[i]-1]*d);
? ? System.out.println("\n***租車總價格:"+m);
? ??
不明覺厲!
舉報
課程升級!以終為始告別枯燥,在開發和重構中體會Java面向對象編程的奧妙
2 回答該程序最后的步驟沒頭緒?
2 回答搞了半天 感覺沒一點兒頭緒
2 回答想了好幾個小時沒有頭緒,看了下問答,有了點靈感~如有雷同,沒錯,我抄的!
6 回答交作業,有沒有哪位同學評價一下我的代碼,相互學習。
3 回答終于寫完了,達達租車系統,歡迎各位討論!
Copyright ? 2025 imooc.com All Rights Reserved | 京ICP備12003892號-11 京公網安備11010802030151號
購課補貼聯系客服咨詢優惠詳情
慕課網APP您的移動學習伙伴
掃描二維碼關注慕課網微信公眾號
2015-12-16
package 達達租車;
import java.util.*;
public class Carrental {
public static void main(String[] args) {
// TODO Auto-generated method stub
? ? ? ? Vehicle v=new Vehicle();
? ? ? ??
? ? ? ? Scanner reader=new Scanner(System.in);
? ? ? ? System.out.println("歡迎使用達達租車系統:");
? ? ? ? System.out.println("你是否要租車:1是 ? 0否");
? ? ? ??
? ? ? ? int s=reader.nextInt();
? ? ? ? if(s==1){
? ? ? ? ? ?v.information();
? ? ? ? ? ?System.out.println("請輸入您要租汽車的數量:");
? ? ? ? ? ?int a=reader.nextInt();
? ? ? ? ? ?int b[]=new int[a];
? ? ? ? ? ?for(int i=0;i<a;i++){
? ? ? ? ? System.out.println("請輸入第"+(i+1)+"輛車的序號:");
? ? ? ? ? b[i]=reader.nextInt();
? ? ? ? ? ?}
? ? ? ? ? ?System.out.println("請輸入租車天數:");
? ? ? ? ? ?int d=reader.nextInt();
? ? ? ? ? ?System.out.println("您的賬單:");
? ? ? ? ? ?v.showcar1(a,b);
? ? ? ? ? ?v.showcar2(a,b); ??
? ? ? ? ? ?v.bill(a,d,b);
? ? ? ? }
? ? ? ? else
? ? ? ? System.exit(0);
}
}
package 達達租車;
public class Vehicle {
?String []str={"奧迪A4","馬自達6","皮卡雪6","金龍 ","松花江","依維柯 ?"};
?int []p={500,400,450,800,400,1000};
?
? ? ?void information(){
? ? System.out.println("你可租車的類型及其價格表:");
? ? System.out.println("序號 ? ? ? ? ? ?汽車名稱 ? ? ? ? ? ? ? ?租金 ? ? ? ? ? ? ? ? ? ? ? ?容量 ? ");
? ? System.out.println("1. ? ?奧迪A4 ? ? 500元/天 ? ? ? ? ? 載人:4人 ? ? ?");
? ? System.out.println("2. ? ?馬自達6 ? ? 400元/天 ? ? ? ? ? 載人:4人 ? ? ?");
? ? System.out.println("3. ? ?皮卡雪6 ? ? 450元/天 ? ? ? ? ? 載人:4人 ? 載貨:2噸 ? ");
? ? System.out.println("4. ? ?金龍 ? ? ? ? ? ? ? ? ? ? ? ? 800元/天 ? ? ? ? ? 載人:20人 ? ? ?");
? ? System.out.println("5. ? ?松花江 ? ? ? ? ? ? ? ? ? ? 400元/天 ? ? ? ? ? 載貨:4噸 ? ? ");
? ? System.out.println("6. ? ?依維柯 ? ? ? ? ? ? ? ? ? ? 1000元/天 ? ? ? ?載貨:20噸 ? ? ?");
? ? ?}
? ? ?
? ? ?void showcar1(int a,int b[]){
? ? System.out.println("***可載人的車有:");
? ? ?
? ? for(int i=0;i<a;i++){
? ? if(b[i]<5)
? ? System.out.print(str[b[i]-1]+" ? "); ? ? ?
? ? }
? ? ?
? ? ?}
? ? ?
? ? ?void showcar2(int a,int b[]){
? ? System.out.println("\n***可載人的車有:");
? ? for(int i=0;i<a;i++){
? ? if(b[i]>5||b[i]==3)
? ? System.out.print(str[b[i]-1]+" ? ");
? ?
? ? }
? ? ?}
? ? ? ? ?
? ? ?
? ? ?
? ? ?void bill(int a,int d,int b[]){ ? ?
? ? int m=0;
? ? for(int i=0;i<a;i++){
? ? ? ? m=m+(p[b[i]-1]*d);
? ? }
? ? System.out.println("\n***租車總價格:"+m);
? ? ?
? ??
? ? ?}
}
2015-12-01
不明覺厲!