① 1. 編寫一個Java應用程序,設計一個汽車類Vehicle,包含的成員屬性有:車輪個數wheels和車重weight。
classVehicle{privateintwheels;privatefloatweight;protectedVehicle(intwheels,floatweight){this。wheels=wheels;this。weight=weight。是普通的除號,即10/2=5。
編寫java程序的注意事項:
大小寫敏感:Java是大小寫敏感的,這就意味著標識符Hello與hello是不同的。
類名:對於所有的類來說,類名的首字母應該大寫。如果類名由若干單片語成,那麼每個單詞的首字母應該大寫,例如 MyFirstJavaClass。
方法名:所有的方法名都應該以小寫字母開頭。如果方法名含有若干單詞,則後面的每個單詞首字母大寫,例如myFirstJavaClass。
② Java建立一個汽車(Car)類,包括品牌(String car_brand)、速度(double car_speed)兩個成員變數具體看圖
這個代碼還是比較簡單,下面的代碼可以參考
classCar{
privateStringcar_brand;
privatedoublecar_speed;
publicCar(){}
publicCar(Stringbrand,doublespeed){
this.car_brand=brand;
this.car_speed=speed;
System.out.println(this.car_brand+"汽車正以時速"
+this.car_speed+"公里的速度行駛");
}
publicvoidspeedUp(Stringbrand){
System.out.println(brand+"汽車正在加速行駛");
}
publicvoidspeedUp(Stringbrand,doublespeed){
System.out.println(brand+"汽車正以時速"
+speed+"公里的速度加速行駛");
}
publicvoidspeedDown(Stringbrand){
System.out.println(brand+"汽車正在減速行駛");
}
publicvoidspeedDown(Stringbrand,doublespeed){
System.out.println(brand+"汽車正以時速"
+speed+"公里的速度減速行駛");
}
}
classTest{
publicstaticvoidmain(String[]args){
Carcar=newCar("寶馬",100.5);
car.speedUp("法拉利");
car.speedUp("法拉利",280.5);
car.speedDown("法拉利");
car.speedDown("法拉利",120.9);
}
}
③ Java定義一個汽車類,要求在底下,謝謝各位了
import java.io.Serializable;public class Main {public static void main(String[] args) {System.out.println(setCar(120, true, 1.5, "black"))。
以待語言開發成功後,能有半導體晶元生產商開發和生產這種硬體平台。對於新語言的設計,Sun公司研發人員並沒有開發一種全新的語言,而是根據嵌入式軟體的要求。
對C++進行了改造,去除了留在C++的一些不太實用及影響安全的成分,並結合嵌入式系統的實時性要求,開發了一種稱為Oak的面向對象語言。
由於C++所具有的優勢,該項目組的研究人員首先考慮採用C++來編寫程序。但對於硬體資源極其匱乏的單片式系統來說,C++程序過於復雜和龐大。另外由於消費電子產品所採用的嵌入式處理器晶元的種類繁雜,如何讓編寫的程序跨平台運行也是個難題。
為了解決困難,他們首先著眼於語言的開發,假設了一種結構簡單、符合嵌入式應用需要的硬體平台體系結構並為其制定了相應的規范,其中就定義了這種硬體平台的二進制機器碼指令系統(即後來成為「位元組碼」的指令系統)。
④ java定義一個汽車類car
你好,很高興回答你的問題。
題目要求的代碼如下:
public class Car{
private String carNumber;
private int speed;
}
如果有幫助到你,請點擊採納。
⑤ 編寫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;
}
}
⑥ 請問如何用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();
}
}
運行結果