第一題:
萬(wàn)州網(wǎng)站建設(shè)公司成都創(chuàng)新互聯(lián)公司,萬(wàn)州網(wǎng)站設(shè)計(jì)制作,有大型網(wǎng)站制作公司豐富經(jīng)驗(yàn)。已為萬(wàn)州上1000+提供企業(yè)網(wǎng)站建設(shè)服務(wù)。企業(yè)網(wǎng)站搭建\外貿(mào)網(wǎng)站制作要多少錢,請(qǐng)找那個(gè)售后服務(wù)好的萬(wàn)州做網(wǎng)站的公司定做!
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("車牌號(hào)為:"+num+",價(jià)格為:"+price);
}
}
測(cè)試類:
public?class?CarTest?{
public?static?void?main(String[]?args)?{
Car?car?=?new?Car("京P34E68",?100000.23f);
}
}
輸出為:車牌號(hào)為:京P34E68,價(jià)格為: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=男]
希望能幫到你,望采納
public?class?Car?{
private?int?num;//編號(hào)
private?String?name;//型號(hào)
private?double?price;//單價(jià)
/**
?*?無(wú)參構(gòu)造
?*/
public?Car(){
super();
}
/**
?*?有參構(gòu)造
?*?@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?+?"]";
}
}
測(cè)試類不想寫了??應(yīng)該可以自己寫出來(lái)了吧
public class Car {
private String color;//顏色
private int door;//車門數(shù)量
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(){
//汽車啟動(dòng)。輸出汽車已啟動(dòng),并輸出汽車的各個(gè)屬性
System.out.println("汽車已啟動(dòng),汽車顏色為"+color+",車門數(shù)為"+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();
}
}
運(yùn)行結(jié)果