
正文
java汽车接口类代码 java接口编写教程
提示:扫一扫查出行【扫一扫了解最新限行尾号】
复制提示
Java定义一个汽车类,要求在底下,谢谢各位了
import java.io.Serializable;public class Main {public static void main(String[] args) {System.out.println(setCar(120, true, 1.5, "black"))。
以待语言开发成功后java汽车接口类代码,能有半导体芯片生产商开发和生产这种硬件平台。对于新语言java汽车接口类代码的设计,Sun公司研发人员并没有开发一种全新的语言,而是根据嵌入式软件的要求。
对C++进行java汽车接口类代码了改造,去除了留在C++的一些不太实用及影响安全的成分,并结合嵌入式系统的实时性要求,开发了一种称为Oak的面向对象语言。
由于C++所具有的优势,该项目组的研究人员首先考虑采用C++来编写程序。但对于硬件资源极其匮乏的单片式系统来说,C++程序过于复杂和庞大。另外由于消费电子产品所采用的嵌入式处理器芯片的种类繁杂,如何让编写的程序跨平台运行也是个难题。
为了解决困难,他们首先着眼于语言的开发,假设了一种结构简单、符合嵌入式应用需要的硬件平台体系结构并为其制定了相应的规范,其中就定义了这种硬件平台的二进制机器码指令系统(即后来成为“字节码”的指令系统)。
相关问答
Q1: Java建立一个汽车(Car)类,包括品牌(String car_brand)、速度(double car_speed)两个成员变量具体看图
这个代码还是比较简单,下面的代码可以参考
class Car{
private String car_brand;
private double car_speed;
public Car(){ }
public Car(String brand, double speed){
this.car_brand = brand;
this.car_speed = speed;
System.out.println(this.car_brand + "汽车正以时速"
+ this.car_speed + "公里的速度行驶");
}
public void speedUp(String brand){
System.out.println(brand + "汽车正在加速行驶");
}
public void speedUp(String brand, double speed){
System.out.println(brand + "汽车正以时速"
+ speed + "公里的速度加速行驶");
}
public void speedDown(String brand){
System.out.println(brand + "汽车正在减速行驶");
}
public void speedDown(String brand, double speed){
System.out.println(brand + "汽车正以时速"
+ speed + "公里的速度减速行驶");
}
}
class Test{
public static void main(String[] args){
Car car = new Car("宝马", 100.5);
car.speedUp("法拉利");
car.speedUp("法拉利", 280.5);
car.speedDown("法拉利");
car.speedDown("法拉利", 120.9);
}
}
Q2: 请问如何用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();
}
}
运行结果
Q3: 用Java程序创建一个汽车接口,接口中要定义汽车应有的属性和行为,然后编写多个汽车接口的实现类,
package No014.Final;
//写出汽车的总接口java汽车接口类代码:获得汽车名称和价格利用get方法java汽车接口类代码;
interface Car{
String getName();
int getPrince();
String getColor();
}
//相应的写出实例来继承接口;
class BMW implements Car{
public String getName() {
return "BMW";
}
public int getPrince() {
return 200000;
}
public String getColor() {
return "黑色";
}
}
class CheryQQ implements Car{
public String getName(){
return "CheryQQ";
}
public int getPrince(){
return 10000;
}
public String getColor() {
return "白色";
}
}
//利用主函数记录和算出车型java汽车接口类代码,颜色java汽车接口类代码,单价和总价;
public class CarShop
{
private int money=0;
public void sellCar(Car car){
System.out.println("车型"+car.getName()+"颜色是"+car.getColor()+"价格"+car.getPrince());
//增加卖车的价格;
money+=car.getPrince();
}
public int getMoney(){
return money;
}
public static void main(String[] args){
CarShop ashop=new CarShop();
ashop.sellCar(new BMW());
ashop.sellCar(new CheryQQ());
System.out.println("到现在为止卖出的车的总价为"+ashop.getMoney());
}
}
记得把包名和类名改一下就可以了。。。
Q4: java中怎么具体使用抽象类和接口???
//继承抽象类Car并实现接口Gasoline
class MyCar extends Car implements Gasoline{
//定义一个变量模拟当前档位,如1,2,3,4,5,
public int nowShift;
//无参构造方法,默认设置相关属性
public MyCar(){
this.color=Color.red;
this.gearNum=5;
this.tiretype="BridgeStone185ST";
this.engine=(float)1598.5;
}
//自己创建车时指定相关属性
public MyCar(Color c,int gearNum,String tiretype,float engine){
this.gearNum=gearNum;
this.color=c;
this.tiretype=tiretype;
this.engine=engine;
}
public void shiftgear(){
//简单模拟循环档,每次调用时档位加1,加满后归零
nowShift++;
if(nowShift=5)
nowShift=0;
}
public void brake(){
nowShift=0;
System.out.println("正在刹车...");
}
public void aircon(){
System.out.println("冷气已经打开");
}
public void headlight(){
System.out.println("大灯打开...");
}
public void refuel(){
System.out.println("轿车燃料为:"+FUEL);
}
public void equipment(){
System.out.println("轿车颜色:"+color+" "+"排挡数:"+gearNum+"\n"+"轮胎型号:"+tiretype+" "+"尾气排量:"+engine+" "+"轿车燃料:"+FUEL);
}
public static void main(String[]a){
new MyCar().equipment();
}
}
main()方法里只测试了自定义的equitment()方法,其他的和他一样调用,如果你需要的话、希望对你有帮助
Q5: Java编写汽车类car
public class Car {
private int num;//编号
private String name;//型号
private double price;//单价
/**
* 无参构造
*/
public Car(){
super();
}
/**
* 有参构造
* @param num
* @param name
* @param price
*/
public Car(int num, String name, double price) {
super();
this.num = num;
this.name = name;
this.price = price;
}
public int getNum() {
return num;
}
public void setNum(int num) {
this.num = num;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public double getPrice() {
return price;
}
public void setPrice(double price) {
this.price = price;
}
public String inforShow() {
return "Car [num=" + num + ", name=" + name + ", price=" + price + "]";
}
}
public class PriCar extends Car{
private int PersonNum;//最大载客量
public PriCar(int personNum) {
super();
PersonNum = personNum;
}
public PriCar() {
super();
}
public int getPersonNum() {
return PersonNum;
}
public void setPersonNum(int personNum) {
PersonNum = personNum;
}
@Override
public String inforShow() {
return "PriCar [PersonNum=" + PersonNum + "]";
}
}
public class VanCar extends Car {
private double weight;//最大载重
public VanCar(double weight) {
super();
this.weight = weight;
}
public VanCar() {
super();
}
@Override
public String inforShow() {
return "PriCar [num=" + super.getNum() + ", name=" + super.getName() + ", price=" + super.getPrice() +",weight=" + weight + "]";
}
}
测试类不想写了 应该可以自己写出来了吧
关于java汽车接口类代码和java接口编写教程的介绍到此就结束了,不知道你从中找到你需要的信息了吗 ?如果你还想了解更多这方面的信息,记得收藏关注本站。








