zoukankan      html  css  js  c++  java
  • 第八周上机练习

    3、定义一个笔记本类,该类有颜色(char)和cpu型号(int)两个属性。 [必做题]
    • 3.1 无参和有参的两个构造方法;有参构造方法可以在创建对象的同时为每个属性赋值;
    • 3.2 输出笔记本信息的方法
    • 3.3 然后编写一个测试类,测试笔记本类的各个方法

    public class D {
            String color;
            int cpu;
            public void showColor(){
                System.out.println("笔记本电脑的颜色:"+color);
            }
            public void showCpu(){
                System.out.println("笔记本CPU的型号:"+cpu);
            }
        }
    public class B {
        public static void main(String[] args) {
            D N=new D();
            N.color="红色";
            N.cpu=7900;
            
            N.showColor();
            N.showCpu();                        
        }
    }

    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()方法。

    public class D {
    public static void main(String[]args){
            R i=new R("zhangsan",173,33);
            R j=new R("lishi",174,44);
     
        i.sayHello();
        j.sayHello();
        }
    }
    public class R{
        String name;
        double height;
        int age;
        R(String name, double height, int age) {
            this.name = name;
            this.height = height;
            this.age = age;
        }
        void sayHello() {
            System.out.println("hello " + name+" "+height+"cm"+" "+age+"岁");
        }
    }
  • 相关阅读:
    Apache Airavata 0.6 发布
    Erebus 0.5 发布,2D 实时角色扮演游戏
    Pcompress 1.3.0 发布,性能大幅提升
    JasperStarter 1.0.1 发布
    Newscoop 4.1 发布,适合记者的 CMS 系统
    Wireshark 1.8.5 发布,网络协议检测程序
    Open Search Server 1.4 Beta2 发布
    Erlang/OTP R16A 发布
    Apache Derby 10.8.3.0 发布
    reading notes for solr source code
  • 原文地址:https://www.cnblogs.com/baigei/p/12759719.html
Copyright © 2011-2022 走看看