做了接近1天....用的都是最基礎的方法,不知道會不會變成C語言,求幫忙看下這是不是面向對象
package dadazuche;
import java.util.Scanner;
class Car{ ? ? ? //rent 租金
private String name;
private int rent;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getRent() {
return rent;
}
public void setRent(int rent) {
this.rent = rent;
}
}
class Keche extends Car{ ? ? ? ? //people為載人量
public void Keche(String name,int money,int people){
Keche ke=new Keche();
ke.setName(name);
ke.setRent(money);
System.out.println(ke.getName()+ke.getRent()+"元/天.輛 ? ? 載人:"+people+"人");
}
}
class Huoche extends Car{ ? ? ? ?//goods為載貨量
public void Huoche(String name,int money,int goods){
Huoche huo=new Huoche();
huo.setName(name);
huo.setRent(money);
System.out.println(huo.getName()+huo.getRent()+"元/天.輛 ? ? 載貨:"+goods+"噸");
}
}
class Pika extends Car{
public void Pika(String name,int money,int people,int goods){
Pika pi=new Pika();
pi.setName(name);
pi.setRent(money);
System.out.println(pi.getName()+pi.getRent()+"元/天.輛 ? ? 載人:"+people+"人 ? ? 載貨:"+goods+"噸");
}
}
//選車列表
class SelectList{ ? ? ? ? ? ? ??
public void SelectList(int selectNum){
switch(selectNum){
case 1: Keche ao=new Keche();
ao.Keche("奧迪A4 ?", 500, 4);break;
case 2: Keche ma=new Keche();
ma.Keche("馬自達6 ?", 400, 4);break;
case 3: Pika pi=new Pika();
pi.Pika("皮卡雪6 ?", 450, 4, 2);break;
case 4: Keche jin=new Keche();
jin.Keche("金龍 ? ? ? ? ? ?", 800, 20);break;
case 5: Huoche song=new Huoche();
song.Huoche("松花江 ? ? ? ?", 400, 4);break;
case 6: Huoche yi=new Huoche();
yi.Huoche("依維柯 ? ? ? ?", 1000, 20);break;
}
}
}
//存放選車數目
class CarList{
static int ao1=0,ma1=0,pi1=0,jin1=0,song1=0,yi1=0;
public void CarList(int xulie,int num){
switch(xulie){
case 1:ao1+=num;break;
case 2:ma1+=num;break;
case 3:pi1+=num;break;
case 4:jin1+=num;break;
case 5:song1+=num;break;
case 6:yi1+=num;break;
}
}
}
//最后帳單
class FinalList{
static int allPeople=0;
static int allGoods=0;
static int allPrice=0;
public void FinalList(){
int ao2=new CarList().ao1; ? ? ? ? ? //提取選取的各種車的數量
int ma2=new CarList().ma1;
int pi2=new CarList().pi1;
int jin2=new CarList().jin1;
int song2=new CarList().song1;
int yi2=new CarList().yi1;
SelectList last=new SelectList();
if(ao2!=0){
allPeople+=ao2*4;
allPrice+=ao2*500;
System.out.print(ao2+"輛 ?");
last.SelectList(1);
}if(ma2!=0){
allPeople+=ma2*4;
allPrice+=ma2*400;
System.out.print(ma2+"輛 ?");
last.SelectList(2);
}if(pi2!=0){
allPeople+=pi2*4;
allGoods+=pi2*2;
allPrice+=pi2*450;
System.out.print(pi2+"輛 ?");
last.SelectList(3);
}if(jin2!=0){
allPeople+=jin2*20;
allPrice+=jin2*800;
System.out.print(jin2+"輛 ?");
last.SelectList(4);
}if(song2!=0){
allGoods+=jin2*4;
allPrice+=jin2*400;
System.out.print(song2+"輛 ?");
last.SelectList(5);
}if(yi2!=0){
allGoods+=yi2*20;
allPrice+=yi2*1000;
System.out.print(yi2+"輛 ?");
last.SelectList(6);
}
if(allPeople!=0){
System.out.println("共可載人:"+allPeople+"人");
}
if(allGoods!=0){
System.out.println("共可載貨:"+allGoods+"噸");
}
}
}
public class zu {
public static void main(String[] args) {
System.out.println("歡迎使用答答租車系統:");
System.out.println("您是否要租車:1是 ?0否");
Scanner scanner=new Scanner(System.in);
int sf=scanner.nextInt();
if(sf==1){
System.out.println("您可租車的類型及其價目表:");
System.out.println("序號 ?汽車名稱 ?租金 ? ? ? 容量");
SelectList select=new SelectList(); ? ? ? ? ? ??
for(int i=1;i<7;i++){
System.out.print(i+". ?");
select.SelectList(i);
}
xuanChe();
System.out.println("請輸入租車天數:");
int day=scanner.nextInt();
System.out.println("您的賬單:");
new FinalList().FinalList();
System.out.println(FinalList.allPrice*day);
System.out.println();
System.out.println();
System.out.println("請按任意鍵對出");
String tuiChu=scanner.next();
System.out.println("感謝您的使用");
System.out.println("再見!");
}
else{
System.out.println("感謝您的使用");
System.out.println("再見!");
}
}
public static void xuanChe(){
Scanner scanner=new Scanner(System.in);
System.out.println("請輸入您要租汽車的數量:");
int sl=scanner.nextInt();
while(sl>0){
System.out.println("請輸入您要租車序列號:");
int xulie=scanner.nextInt();
while(xulie<1||xulie>6){
System.out.println("請輸入1~6");
System.out.println("請輸入您要租車序列號:");
xulie=scanner.nextInt();
}
System.out.println("請輸入您要租本車的數量:");
int num=scanner.nextInt();
new CarList().CarList(xulie,num);
sl-=num;
if(sl<0){
System.out.println("您總共選的車比您之前輸入的總數量多,請選擇:1繼續 0重選");
int jx=scanner.nextInt();
if(jx==0){
sl=0;
xuanChe();
}
}
}
}
}
2015-03-22
是用的面向對象呀,