zoukankan      html  css  js  c++  java
  • 【每日日报】第二十三天

    1 今天看了学习手册第五章的内容

     1 package XuanZeTi;
     2 
     3 public class Question {
     4     String text;
     5     String[] options;
     6     public void print(){
     7         System.out.println(this.text);
     8         for(int i=0;i<this.options.length;i++){
     9             System.out.print(options[i]+"	");
    10         }
    11         System.out.println();
    12     }
    13     public boolean check(char[] answers){
    14         return false;
    15     }
    16 
    17 }
     1 package XuanZeTi;
     2 
     3 public class SingleQuestion extends Question{
     4     char answer;
     5     public SingleQuestion (String text,String[] options,char answer){
     6         this.text=text;
     7         this.options=options;
     8         this.answer=answer;
     9     }
    10     public boolean check(char[] answers){
    11         if(answers==null||answers.length!=1){return false;}
    12         return this.answer==answers[0];
    13     }
    14 }
     1 package XuanZeTi;
     2 import java.util.Arrays;
     3 
     4 public class MultiQuestion extends Question{
     5     char[] answers;
     6     public MultiQuestion(String text,String[] options,char[] answers){
     7         this.text=text;
     8         this.options=options;
     9         this.answers=answers;
    10     }
    11     public boolean check(char[] answers){
    12         return Arrays.equals(answers, this.answers);
    13     }
    14 
    15 }
     1 package XuanZeTi;
     2 import java.util.*;
     3 public class PaperDemo {
     4     public static void main(String args[]){
     5         Question[] paper={null,null};
     6         paper[0]=new SingleQuestion("Q:谁最美?",
     7                 new String[]{"A.范冰冰","B.刘诗诗","C.常金悦","D.杨幂"},
     8                 'C');
     9         paper[1]=new MultiQuestion("Q:常金悦都玩哪些英雄?",
    10                 new String[]{"A.孙悟空","B.庄周","C.蔡文姬","D.小乔"},
    11                 new char[]{'B','C'});
    12         Scanner console=new Scanner(System.in);
    13         for(int i=0;i<paper.length;i++){
    14             Question q=paper[i];
    15             q.print();
    16             System.out.print("请选择:");
    17             String str = console.nextLine();
    18             char[] answers=str.toCharArray();
    19             if(q.check(answers)){
    20                 System.out.println("真聪明!");
    21             }
    22             else{
    23                 System.out.println("笨,这都答不上来!?");
    24             }
    25         }
    26         
    27     }
    28 
    29 }

    2 没什么问题

    3 明天继续看手册

  • 相关阅读:
    【Solr】copy字段的应用
    【Solr】Solr的安装部署
    【UEditor】 UEditor整合项目上传资源到阿里云服务器
    【Bootstrap】Bootstrap和Java分页-第二篇
    【Bootstrap】Bootstrap和Java分页-第一篇
    工作那点小事
    ubuntu安装mongodb
    mybatis插入返回主键
    linux查看端口占用命令
    ubuntu安装ssh
  • 原文地址:https://www.cnblogs.com/linmob/p/13418034.html
Copyright © 2011-2022 走看看