Java输出车辆信息代码 java输出车辆信息代码是多少
JAVA代码编写!求帮忙!求教
第一题:
万州网站建设公司成都创新互联公司,万州网站设计制作,有大型网站制作公司丰富经验。已为万州上1000+提供企业网站建设服务。企业网站搭建\外贸网站制作要多少钱,请找那个售后服务好的万州做网站的公司定做!
Car.java
public class Car {
public String num;
public float price;
public Car(String num,float price){
this.num = num;
this.price=price;
System.out.println("车牌号为:"+num+",价格为:"+price);
}
}
测试类:
public class CarTest {
public static void main(String[] args) {
Car car = new Car("京P34E68", 100000.23f);
}
}
输出为:车牌号为:京P34E68,价格为:100000.23
第二题:
Student.java
public class Student {
private String num;
private String name;
private int age;
private String sex;
public String getNum() {
return num;
}
public void setNum(String num) {
this.num = num;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
public String getSex() {
return sex;
}
public void setSex(String sex) {
this.sex = sex;
}
public String tell() {
return "Student [num=" + num + ", name=" + name + ", age=" + age+ ", sex=" + sex + "]";
}
public static void main(String[] args) {
Student student = new Student();
student.setAge(18);
student.setNum("001");
student.setName("COLD");
student.setSex("男");
System.out.println(student.tell());
}
}
输出:Student [num=001, name=COLD, age=18, sex=男]
希望能帮到你,望采纳
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编写一个汽车类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();
}
}
运行结果
网站题目:Java输出车辆信息代码 java输出车辆信息代码是多少
文章位置:http://scyanting.com/article/doopsoh.html