1. 用java定義一個汽車類Automobile,



classAutomobile
{
privateString發動機型號;

privateint座位數;

publicStringget發動機型號()
{
return發動機型號;
}

publicvoidset發動機型號(String發動機型號)
{
this.發動機型號=發動機型號;
}

publicintget座位數()
{
return座位數;
}

publicvoidset座位數(int座位數)
{
this.座位數=座位數;
}

@Override
publicStringtoString()
{
returnString.format("[發動機型號=%s,座位數=%s]",發動機型號,座位數);
}
}

interface收費
{
publicvoid收費方法();
}

interface調速
{
publicvoid調速方法();
}

class公共汽車extendsAutomobileimplements收費,調速
{
@Override
publicvoid調速方法()
{
System.out.println("速度非常慢");
}

@Override
publicvoid收費方法()
{
System.out.println("天價呢");
}
}

class計程車extendsAutomobileimplements收費,調速
{
@Override
publicvoid調速方法()
{
System.out.println("速度是20公里每小時");
}

@Override
publicvoid收費方法()
{
System.out.println("計程車的收費是便宜的");
}
}

publicclassMain
{
publicstaticvoidmain(String[]args)
{
計程車czc=new計程車();
czc.set發動機型號("abc");
czc.set座位數(4);
System.out.println(czc);
czc.調速方法();
czc.收費方法();

公共汽車ggqc=new公共汽車();
ggqc.set發動機型號("ddf");
ggqc.set座位數(30);
System.out.println(ggqc);
ggqc.調速方法();
ggqc.收費方法();
}
}

2. 請問如何用Java編寫一個汽車類Car

public class Car {

private String color;//顏色

private int door;//車門數量

private float speed;//車速

public Car(){

this.color = "紅色";

this.door = 3;

this.speed = 110;

}

public Car(String color, int door, float speed) {

this.color = color;

this.door = door;

this.speed = speed;

}

public void start(){

//汽車啟動。輸出汽車已啟動,並輸出汽車的各個屬性

System.out.println("汽車已啟動,汽車顏色為"+color+",車門數為"+door+",車速為"+speed);

}

public void speedUp(float speed){

//加速

System.out.println("汽車加速到"+speed+"km/h");

}

public void shutDown(float speed){

//減速

System.out.println("汽車減速到"+speed+"km/h");

}

public void brake(){

//剎車

System.out.println("已剎車");

}

}

public class Test {

public static void main(String[] args){

Car car = new Car();

car.start();

car.speedUp(100);

car.shutDown(60);

car.brake();

Car car1 = new Car("白色",4,20.2F);

car1.start();

car1.speedUp(100);

car1.shutDown(60);

car1.brake();

}

}

運行結果

3. Java編寫汽車類car

publicclassCar{

privateintnum;//編號
privateStringname;//型號
privatedoubleprice;//單價

/**
*無參構造
*/
publicCar(){
super();
}

/**
*有參構造
*@paramnum
*@paramname
*@paramprice
*/
publicCar(intnum,Stringname,doubleprice){
super();
this.num=num;
this.name=name;
this.price=price;
}

publicintgetNum(){
returnnum;
}

publicvoidsetNum(intnum){
this.num=num;
}

publicStringgetName(){
returnname;
}

publicvoidsetName(Stringname){
this.name=name;
}

publicdoublegetPrice(){
returnprice;
}

publicvoidsetPrice(doubleprice){
this.price=price;
}

publicStringinforShow(){
return"Car[num="+num+",name="+name+",price="+price+"]";
}



}publicclassPriCarextendsCar{

privateintPersonNum;//最大載客量

publicPriCar(intpersonNum){
super();
PersonNum=personNum;
}

publicPriCar(){
super();
}

publicintgetPersonNum(){
returnPersonNum;
}

publicvoidsetPersonNum(intpersonNum){
PersonNum=personNum;
}

@Override
publicStringinforShow(){
return"PriCar[PersonNum="+PersonNum+"]";
}


}publicclassVanCarextendsCar{

privatedoubleweight;//最大載重

publicVanCar(doubleweight){
super();
this.weight=weight;
}

publicVanCar(){
super();
}

@Override
publicStringinforShow(){
return"PriCar[num="+super.getNum()+",name="+super.getName()+",price="+super.getPrice()+",weight="+weight+"]";
}

}

測試類不想寫了應該可以自己寫出來了吧

4. 大神們 怎麼用java畫汽車

1.最簡單的方法:
publicstaticStringreverse1(Stringstr)
{
returnnewStringBuffer(str).reverse().toString();
}
2.最常用的方法:
publicstaticStringreverse3(Strings)
{
char[]array=s.toCharArray();
Stringreverse="";//注意這是空串,不是null
for(inti=array.length-1;i>=0;i--)
reverse+=array[i];
returnreverse;
}
3.常用方法的變形:
publicstaticStringreverse2(Strings)
{
intlength=s.length();
Stringreverse="";//注意這是空串,不是null
for(inti=0;i<length;i++)
reverse=s.charAt(i)+reverse;//在字元串前面連接,而非常見的後面
returnreverse;
}
4.C語言中常用的方法:
publicstaticStringreverse5(Stringorig)
{
char[]s=orig.toCharArray();
intn=s.length-1;
inthalfLength=n/2;
for(inti=0;i<=halfLength;i++){
chartemp=s[i];
s[i]=s[n-i];
s[n-i]=temp;
}
returnnewString(s);//知道char數組和String相互轉化
}

5. java定義一個汽車類car

你好,很高興回答你的問題。
題目要求的代碼如下:
public class Car{
private String carNumber;
private int speed;
}
如果有幫助到你,請點擊點贊。

6. JAVA 建立一個汽車AutoMobile類......

publicclassAutoMobile{
protectedintnumbersOfWheels;
;
protectedintautoMobileWeight;
protectedintspeed;

publicAutoMobile(){
this(4,"黑色",100);
}

publicAutoMobile(intnumbersOfWheels,StringautoMobileColor,intautoMobileWeight){
this.numbersOfWheels=numbersOfWheels;
this.autoMobileColor=autoMobileColor;
this.autoMobileWeight=autoMobileWeight;
this.speed=0;
}
publicvoidspeedUp(){
speed++;
System.out.println("這是AutoMobile的加速方法,當前速度:"+speed);
}
publicvoidspeedDown(){
speed--;
System.out.println("這是AutoMobile的減速方法,當前速度:"+speed);
}
publicvoidstop(){
speed=0;
System.out.println("這是AutoMobile的停車方法,當前速度:"+speed);
}
publicintgetNumbersOfWheels(){
returnnumbersOfWheels;
}
publicvoidsetNumbersOfWheels(intnumbersOfWheels){
this.numbersOfWheels=numbersOfWheels;
}
(){
returnautoMobileColor;
}
publicvoidsetAutoMobileColor(StringautoMobileColor){
this.autoMobileColor=autoMobileColor;
}
publicintgetAutoMobileWeight(){
returnautoMobileWeight;
}
publicvoidsetAutoMobileWeight(intautoMobileWeight){
this.autoMobileWeight=autoMobileWeight;
}
publicintgetSpeed(){
returnspeed;
}
publicvoidsetSpeed(intspeed){
this.speed=speed;
}
}
{
protectedStringairConditioner;
protectedStringcd;
publicCar(){
super();
this.airConditioner="空調A";
this.cd="sony";
}
publicvoidspeedUp(){
speed+=2;
System.out.println("這是Car的加速方法,當前速度:"+speed);
}
publicvoidspeedDown(){
speed-=2;
System.out.println("這是Car的減速方法,當前速度:"+speed);
}
publicStringgetAirConditioner(){
returnairConditioner;
}
publicvoidsetAirConditioner(StringairConditioner){
this.airConditioner=airConditioner;
}
publicStringgetCd(){
returncd;
}
publicvoidsetCd(Stringcd){
this.cd=cd;
}
}
publicclassTest{

publicstaticvoidmain(String[]args){

Carcar=newCar();

car.speedUp();

car.speedUp();

car.speedDown();

car.stop();

}

}

7. JAVA汽車

import java.awt.Color;

class Car {
Color color; //顏色
double price; //價格
String licensePlate; //車牌

public void start() {}
public void stop() {}
}

class BMW extends Car {
Color color = Color.BLACK;
}

不滿意的話,隨便回改。答

8. 編寫java程序:設計一個汽車類

隨便給你建了個,代碼如下:
package com.ask.test;
public class Car {
//顏色(黑色、白色等)
private String color;
//品牌(賓士、寶馬、東風等)
private String brand;
//類型(越野、普通汽車等)
private String type;

//構造方法
public Car(String color, String brand, String type) {
super();
this.color = color;
this.brand = brand;
this.type = type;
}

public String getColor() {
return color;
}
public void setColor(String color) {
this.color = color;
}
public String getBrand() {
return brand;
}
public void setBrand(String brand) {
this.brand = brand;
}
public String getType() {
return type;
}
public void setType(String type) {
this.type = type;
}

}