2019.1.6

配置环境变量:win7,右击计算机选择属性中的高级属性,选择高级系统设置,点击环境变量,在系统变量里找到path,复制其中的路径;找到自己java的bin文件复制路径,粘贴到刚才的path路径后面。

public class Test {                     创建类,类名的 第一个字母是大写

    public static void main(String[] args) {   使用的main方法   快捷键为main+Alt+/
    
        Food f1=new Food();       f1是对象       Food f1=new Food();创建一个对象
                                                    格式:        

        f1.setName("土豆丝");        f1.setName是方法
        f1.setPrice(60.55);              
        Food f2=new Food();
        f2.setName("土豆块");
        f2.setPrice(10.55);
        Food f3=new Food();
        f3.setName("土豆片");
        f3.setPrice(30.55);
        Person b=new Person();
        b.setName("小明");
        //System.out.println(b.getName()+"点"+f1.getName()+f2.getName()+f3.getName()+"花了"+(p1.getPrice()+p2.getPrice()+p3.getPrice()));          System.out.println()为打印,快捷键为syso+Alt+/
        b.coat(f1, f2, f3);                                 b.coat(f1, f2, f3);   调用coat方法
    }

public class Food {
     private String name;                  String name为定义
     private double price;                  double price
     

    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;
    }                  快捷方式   右击source   找到Generate  Getters and  Setters

}

public class Person {
        private String name;

        public void setName(String name) {
            this.name = name;
        }
        
        public String getName() {
            return name;
        }
        void coat(Food f1,Food f2,Food f3){                 void前面要是没有修饰符就默认为
            System.out.println(name+"点了"+f1.getName()+f2.getName()+f3.getName()+",一共花了"+(f1.getPrice()+f2.getPrice()+f3.getPrice()));
        }
    }

猜你喜欢

转载自blog.csdn.net/weixin_43289689/article/details/85942965
今日推荐