0
点赞
收藏
分享

微信扫一扫

IDEA工具快捷键的使用

徐一村 2022-06-30 阅读 122

目录

🏀关于IDEA工具的快捷键以及一些简单的设置

🥅project---Module---class三板斧

🥅IDEA常用快捷键

🥅小试牛刀


🏀关于IDEA工具的快捷键以及一些简单的设置

🥅project---Module---class三板斧

❤️(1)创建新的项目工程:

 

 

❤️(2)在空的工程创建一个Module(模块)

 

❤️(3)编写代码,在src目录下(右击鼠标)新建类(例如:Helloworld),写代码运行

 ​

 自动生成类!

 🥅IDEA常用快捷键

❤️一般设置

❤️常用快捷键设置

🥅小试牛刀

public class HomeWork01 {
    public static void main(String[] args) {
        //方法1:调用无参构造方法
        Vehicle v = new Vehicle();
        v.setSpeed(110);
        v.setSize(10);
        //打印
        System.out.println("speed:"+v.getSpeed());
        System.out.println("size:"+v.getSize());

        //加速speedUp()
        v.speedUp(20);
        System.out.println("speed:"+v.getSpeed());
        //减速speedDown()
        v.speedDown(30);
        System.out.println("speed:"+v.getSpeed());
    }
}

class Vehicle{
    private int speed;
    private int size;

    //构造方法
    public Vehicle() {
    }

    public Vehicle(int speed, int size) {
        this.speed = speed;
        this.size = size;
    }

    //getter 和 setter方法

    public int getSpeed() {
        return speed;
    }
    //设置速度(setSpeed(int speed))
    public void setSpeed(int speed) {
        this.speed = speed;
    }

    public int getSize() {
        return size;
    }

    public void setSize(int size) {
        this.size = size;
    }

    // 方法移动(move())
    public void move(){

    }
    // 加速speedUp()
    public void speedUp(int addSpeed){
        this.setSpeed(addSpeed+this.getSpeed());
    }
    // 减速speedDown()
    public void speedDown(int addSpeed){
        if(this.getSpeed() > addSpeed)
        {
            this.setSpeed(this.getSpeed()-addSpeed);
        }else{
            this.setSpeed(0);
        }

    }
}

public class HomeWork02 {
    public static void main(String[] args) {
        Number num = new Number(10,2);
        num.add();
        num.sub();
        num.mul();
        num.div();
    }
}
class Number{
    private int n1;
    private int n2;

    //构造方法
    public Number() {
    }

    public Number(int n1, int n2) {
        this.n1 = n1;
        this.n2 = n2;
    }

    //getter和setter方法
    public int getN1() {
        return n1;
    }

    public void setN1(int n1) {
        this.n1 = n1;
    }

    public int getN2() {
        return n2;
    }

    public void setN2(int n2) {
        this.n2 = n2;
    }

    //定义加add()、减sub()、乘mul()、除div()等公有实例方法
    public void add(){
        System.out.println(this.getN1()+"+"+this.getN2()+"="+(this.getN1()+this.getN2()));
    }
    public void sub(){
        System.out.println(this.getN1()+"-"+this.getN2()+"="+(this.getN1()-this.getN2()));
    }
    public void mul(){
        System.out.println(this.getN1()+"*"+this.getN2()+"="+(this.getN1()*this.getN2()));
    }
    public void div(){
        if(n2 == 0){
            System.out.println("除数不能为0");
            return;
        }
        System.out.println(this.getN1()+"/"+this.getN2()+"="+(this.getN1()/this.getN2()));
    }
}

public class HomeWork03 {
    public static void main(String[] args) {
        //调用有参的
        Person p = new Person("张三",18);
        p.display();
        //调用无参的
        Person p1 = new Person();
        p1.setName("李四");
        p1.setAge(22);
        p1.display();
    }
}

class Person{
    private String name;
    private int age;
    //构造方法
    public Person() {
    }

    public Person(String name, int age) {
        this.name = name;
        this.age = age;
    }
    //getter和setter方法
    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;
    }

    //定义显示display方法将姓名和年龄打印出来。
    public void display(){
        //三种方法都可以
        System.out.println("姓名:"+this.getName()+","+"年龄:"+this.getAge());
        System.out.println("姓名:"+this.name+","+"年龄:"+this.age);
        System.out.println("姓名:"+name+","+"年龄:"+age);
    }

}
public class HomeWork04 {
    public static void main(String[] args) {
        MyTime m = new MyTime(6,30,30); //6 30 30
        m.display(); //6时30分30秒

        //增加:hour、minute、second
        m.addHour(1);
        m.display();//7时30分30秒
        m.addMinute(40);
        m.display();//8时10分30秒
        m.addSecond(40);
        m.display();//8时11分10秒
        System.out.println("--------------------------");
        m.addHour(22);
        m.display();//6时11分10秒
        m.addMinute(140);
        m.display();//8时31分10秒
        m.addSecond(140);
        m.display();//8时33分30秒
        System.out.println("--------------------------");
        //减少:hour、minute、second
        m.subHour(1);
        m.display();//7时33分30秒
        m.subMinute(21);
        m.display();//7时12分30秒
        m.subSecond(30);
        m.display(); //7时12分0秒
        System.out.println("--------------------------");
        m.subHour(8);
        m.display();//23时12分0秒
        m.subMinute(151);
        m.display();//21时19分0秒
        m.subSecond(150);
        m.display(); //21时17分30秒
    }
}
class MyTime{
    private int hour;
    private int minute;
    private int second;

    //构造方法
    public MyTime() {
    }

    public MyTime(int hour, int minute, int second) {
        this.hour = hour;
        this.minute = minute;
        this.second = second;
    }

    //getter和setter方法
    public int getHour() {
        return hour;
    }

    public void setHour(int hour) {
        this.hour = hour;
    }

    public int getMinute() {
        return minute;
    }

    public void setMinute(int minute) {
        this.minute = minute;
    }

    public int getSecond() {
        return second;
    }

    public void setSecond(int second) {
        this.second = second;
    }

    //增加小时 addHour(int hou)
    public void addHour(int hou){
        if((this.getHour()+hou)<24) {
             this.setHour(this.getHour() + hou);
        }else{
            int newHour = this.getHour() + hou;
            this.setHour(newHour % 24);
        }
    }
    //减少小时 subHour(int hou)
    public void subHour(int hou){
        if(hou > this.getHour()){
            this.setHour(this.getHour() - hou+24);
        }else{
            this.setHour(this.getHour() - hou);
        }

    }

    //增加分钟 addMinute(int min)
    public void addMinute(int min){
        if((this.getMinute()+min) < 60){
            this.setMinute(this.getMinute()+min);
        }else {
            int newMin = this.getMinute()+min;
            this.setMinute(newMin%60);
            this.setHour(this.getHour()+newMin/60);
        }

    }
    //减少分钟 subMinute(int min)
    public void subMinute(int min){
        if(min > this.getMinute())
        {
            int newMin = min-this.getMinute();
            this.setMinute(newMin%60);
            this.setHour(this.getHour() - newMin/60);
        }else{
            this.setMinute(this.getMinute()-min);
        }
    }

    //增加秒 addSecond(int sec)
    public void addSecond(int sec){
        if((this.getSecond()+sec) <60) {
            this.setSecond(this.getSecond() + sec);
        }else{
            int newSec = this.getSecond() + sec;
            this.setSecond(newSec%60);
            this.setMinute(this.getMinute() + newSec/60);
        }
    }
    //减少秒  subSecond(int sec)
    public void subSecond(int sec){
        if(sec > this.getSecond()){
            int newSec = sec - this.getSecond();
            this.setSecond(newSec%60);
            this.setMinute(this.getMinute()-newSec/60);
        }else{
            this.setSecond(this.getSecond()-sec);
        }
    }


    //定义diaplay方法用于将时间信息打印出来。
    public void display(){
        System.out.println(this.getHour()+"时"+this.getMinute()+"分"+this.getSecond()+"秒");
    }
}
举报

相关推荐

0 条评论