只要自己的電腦安裝了jdk環(huán)境,任何地方都可以進行java代碼的編寫的,記事本也可以。
多端合一成都響應(yīng)式網(wǎng)站建設(shè)公司:PC+平板+手機,同一后臺修改數(shù)據(jù)多端同步更新提交您的需求,獲取網(wǎng)站建設(shè)與營銷策劃方案報價,我們會在1小時內(nèi)與您聯(lián)系!
畫之前加上g.clearRect(0, 0, getWidth(), getHeight());
不然你上一次畫的還灶搭會呈現(xiàn)出來
這樣呢,就會閃爍,需要使用雙緩沖來解決了。廳亮
需要扮辯寬請追問。
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(){
//汽車啟動。輸出汽車已啟動,并輸出汽車的各個屬性
System.out.println("汽車已啟動,汽車顏色為"+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();
}
}
運行橡游結(jié)果
實現(xiàn)代碼如下:
Student類:
public class Student {
private String name;
private String sex;
private int age;
private double chinese;
private double math;
private double english;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getSex() {
return sex;
}
public void setSex(String sex) {
this.sex = sex;
}
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
public double getChinese() {
return chinese;
}
public void setChinese(double chinese) {
this.chinese = chinese;
}
public double getMath() {
return math;
}
public void setMath(double math) {
this.math = math;
}
public double getEnglish() {
return english;
}
public void setEnglish(double english) {
this.english = english;
}
}
-----------------------------------------------------------------
StudentTest類:臘譽(測試類)
import java.util.Scanner;
public class StudentTest {
public static void main(String[] args) {
Student student = new Student();
Scanner sc = new Scanner(System.in);
System.out.println("請輸入姓名:");
student.setName(sc.next());
System.out.println("請輸入性別:");
student.setSex(sc.next());
System.out.println("請輸入年齡:");
student.setAge(sc.nextInt());
System.out.println("請滾衫輸入語文成績、數(shù)學(xué)成績、英語成績:");
student.setChinese(sc.nextDouble());
student.setMath(sc.nextDouble());
student.setEnglish(sc.nextDouble());
Double count = student.getChinese()+ student.getMath()+student.getEnglish();
System.out.println("姓名:"+student.getName()+" 性別:"+student.getSex()+" 年齡:"+student.getAge());
System.out.println("總分:"+count+" 平均分:"+count/3);
}
}
運行結(jié)果為大局腔: