• 第六次上机练习


    /*3、定义一个笔记本类,该类有颜色(char)和cpu型号(int)两个属性。 [必做题]
     • 3.1 无参和有参的两个构造方法;有参构造方法可以在创建对象的同时为每个属性赋值;
     • 3.2 输出笔记本信息的方法
     • 3.3 然后编写一个测试类,测试笔记本类的各个方法。*/
    package practice6.computer;
    
    public class Computer {
    
    	String color;
        int cpu;
        
        public void getColor(){
            System.out.println("color:"+color);
        }
        public void getCpu(){
            System.out.println("cup:"+cpu);
        }
    }
    

      

    package practice6.computer;
    
    public class test1 {
    
    	public static void main(String[] args) {
    		// TODO Auto-generated method stub
    
    		Computer C=new Computer();
            C.color = "pink";
            C.cpu = 250;
            C.getColor();
            C.getCpu(); 
    	}
    
    }
    

      

    /*5、定义两个类,描述如下: [必做题]
     • 5.1定义一个人类Person:
     • 5.1.1定义一个方法sayHello(),可以向对方发出问候语“hello,my name is XXX”
     • 5.1.2有三个属性:名字、身高、体重
     • 5.2定义一个PersonCreate类:
     • 5.2.1创建两个对象,分别是zhangsan,33岁,1.73;lishi,44,1.74
     • 5.2.2分别调用对象的sayHello()方法。*/
    package practice6.person;
    
    public class Person {
    
    	String name;
        double height;
        int age;
    
        public void sayHello() {
            System.out.println("hello,my name is " + name);
            System.out.println("my height is " + height);
            System.out.println("my age is " + age);
    
        }
    }
    

      

    package practice6.person;
    
    public class PersonCreate {
    
    	public static void main(String[] args) {
    		// TODO Auto-generated method stub
    
    		Person p1 = new Person();
            p1.name = "zhangsan";
            p1.age = 33;
            p1.height = 1.73;
            p1.sayHello();
            
            Person p2 = new Person();
            p2.name = "lisi";
            p2.age = 44;
            p2.height = 1.74;
            p2.sayHello();
    	}
    
    }
    

      

  • 相关阅读:
    deleted
    deleted
    HDU
    FZU 1901 Period II(KMP中的next)题解
    HDU 3374 String Problem(最大最小表示+KMP)题解
    HDU 4300 Clairewd’s message(扩展KMP)题解
    POJ 2923 Relocation(状压DP+01背包)题解
    HDU 4272 LianLianKan (状压DP+DFS)题解
    POJ 1185 炮兵阵地(状压DP)题解
    POJ
  • 原文地址:https://www.cnblogs.com/wu-di-821-821/p/12759994.html
Copyright © 2020-2023  润新知