zoukankan      html  css  js  c++  java
  • 0916作业

      1 public class HomeWork0916 implements HomeWork
      2 {
      3     /*方法调用区*/
      4     //实现接口,获取家庭作业题目
      5     public void getHRMessage()
      6     {
      7         getMs();
      8     }
      9     //实现接口,获取家庭作业答卷    
     10     public void getHR()
     11     {    
     12         home1();        //第一题答卷
     13         home2();        //第二题答卷
     14         home3();        //第三题答卷
     15         home4();        //第四题答卷
     16     }
     17     //实现接口,获取家庭作业        
     18     public void start()
     19     {
     20         getHRMessage();
     21         getHR();
     22     }
     23 
     24     /*方法实现区*/
     25     //试题方法的实现
     26     public void getMs()
     27     {    
     28         System.out.println();
     29         System.out.println("题目一:编写Java应用程序。首先,定义描述学生的类——Student,包括学号(int)、姓名(String)、年龄(int)等属性;二个方法:Student(int stuNo,String name,int age)用于对对象的初始化,outPut()用于输出学生信息。其次,再定义一个主类——TestClass,在主类的main方法中创建多个Student类的对象,使用这些对象来测试Student类的功能。");
     30         System.out.println("编写一个Java应用程序,该应用程序包括2个类:Print类和主类E。Print类里有一个方法output()功能是输出100 ~ 999之间的所有水仙花数(各位数字的立方和等于这个三位数本身,如: 371 = 33 + 73 + 13。)在主类E的main方法中来测试类Print。");
     31         System.out.println("编写Java应用程序。首先,定义一个Print类,它有一个方法void output(intx),如果x的值是1,在控制台打印出大写的英文字母表;如果x的值是2,在控制台打印出小写的英文字母表。其次,再定义一个主类——TestClass,在主类的main方法中创建Print类的对象,使用这个对象调用方法output ()来打印出大小写英文字母表。");
     32         System.out.println("8.按要求编写Java应用程序。(1)建立一个名叫Cat的类:属性:姓名、毛色、年龄 行为:显示姓名、喊叫(2)编写主类:创建一个对象猫,姓名为“妮妮”,毛色为“灰色”,年龄为2岁,在屏幕上输出该对象的毛色和年龄,让该对象调用显示姓名和喊叫两个方法。");
     33         System.out.println("");
     34     }
     35     //题目一的方法实现
     36     public void home1()
     37     {
     38         System.out.println("题目一:");
     39         Student s1=new Student(1,"貂蝉",16);
     40         s1.outPut();
     41         Student s2=new Student(2,"西施",17);
     42         s2.outPut();
     43         Student s3=new Student(3,"刘欢",18);
     44         s3.outPut();
     45     }
     46     //题目二的方法实现
     47     public void home2()
     48     {
     49         System.out.println("题目二:");
     50         SMath s=new SMath();
     51         s.outPut();
     52     }
     53     //题目三的方法实现
     54     public void home3()
     55     {
     56         System.out.println("题目三:");
     57         ABCabc abc=new ABCabc();
     58         abc.forChar();
     59         abc.outPut(1);
     60         abc.outPut(2);
     61     }
     62     //题目四的方法实现
     63     public void home4()
     64     {
     65         System.out.println("题目四:");
     66         Cat cat=new Cat("妮妮","灰色",2);
     67         cat.showName();
     68         cat.showColor();
     69         cat.hello();
     70     }
     71 }
     72 //题目一需要定义的类
     73 class Student
     74 {
     75     private int num;
     76     private String name;
     77     private int age;
     78     Student(int num,String name,int age)
     79     {
     80         this.num=num;
     81         this.name=name;
     82         this.age=age;
     83     }
     84     public void outPut()
     85     {
     86         System.out.println("学号:"+num+"姓名:"+name+"年龄:"+age);
     87     }
     88 }
     89 //题目二需要定义的类
     90 class SMath
     91 {
     92     public void outPut()
     93     {
     94         int a,b,c;
     95         for(int i=100;i<1000;i++)
     96         {
     97             a=i/100;
     98             b=(i%100)/10;
     99             c=i%100%10;
    100             if(i==(Math.pow(a,3)+Math.pow(b,3)+Math.pow(c,3)))
    101             {
    102                 System.out.println(i+"  ");
    103             }    
    104         }
    105     }
    106 }
    107 //题目三需要定义的类
    108 class ABCabc
    109 {
    110     char[] abc=new char[52];
    111     char n='a';
    112     char n2='A';
    113     public void forChar()
    114     {
    115         for(int i=0;i<52;i++)
    116         {
    117             if(i<26)
    118             {
    119                 abc[i]=n;
    120                 n++;
    121             }else
    122             {
    123                 abc[i]=n2;
    124                 n2++;
    125             }
    126         }
    127     }
    128     public void outPut(int num)
    129     {    
    130         if(num==1)
    131         {
    132             for(int i=0;i<26;i++)
    133             {
    134                 System.out.print(abc[i]+" ");
    135             }
    136         }
    137         if(num==2)
    138         {
    139             for(int i=26;i<52;i++)
    140             {
    141                 System.out.print(abc[i]+" ");
    142             }    
    143         }
    144         System.out.println();
    145     }
    146 }
    147 //题目四需要定义的类
    148 class Cat
    149 {
    150     String name;
    151     String color;
    152     int age;
    153     Cat(String name,String color,int age)
    154     {
    155         this.name=name;
    156         this.color=color;
    157         this.age=age;
    158     }
    159     public void showName()
    160     {
    161         System.out.println("我的名字是:"+name);
    162     }
    163     public void showColor()
    164     {
    165         System.out.println("我的毛色是:"+color);
    166     }
    167     public void hello()
    168     {
    169         System.out.println("喵喵喵~~~");
    170     }
    171 }
  • 相关阅读:
    hive使用beeline配置远程连接
    gitlab的搭建和使用(转)
    idea 快捷键
    Linux下用ls和du命令查看文件以及文件夹大小(转)
    crontab每小时运行一次(转)
    spark读写Oracle、hive的艰辛之路(二)-Oracle的date类型
    TCP为什么是三次握手,不是两次握手?
    2.2tensorflow2.3常量定义、类型、使用实例、运算
    2.1 tensorflow2.x数据类型和四种转换方法
    1.1tensorflow2.x简介计算图graph,张量tensor,会话session
  • 原文地址:https://www.cnblogs.com/kaililikai/p/5874708.html
Copyright © 2011-2022 走看看