java学习第十一天2020/7/16
Posted 小强哥in
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了java学习第十一天2020/7/16相关的知识,希望对你有一定的参考价值。
一.
今天大多在写c++的程序报告
此外通过一个程序再对继承有一个了解
public class Question { String text; String [] options; public void print() { System.out.println(this.text); for(int i=0;i<this.options.length;i++) { System.out.println(options[i]+" "); } System.out.println(); } public boolean check(char[] answers) { return false; } } public class SingleQuestion extends Question{ char answer; public SingleQuestion(String text,String[] options,char answer) { this.text=text; this.options=options; this.answer=answer; } public boolean check(char[] answer) { if(answer==null||answer.length!=1) return false; return this.answer==answer[0]; } } import java.util.Arrays; public class MultiQuestion extends Question{ char[] answers; public MultiQuestion(String text,String[] options,char[] answers) { this.text=text; this.options=options; this.answers=answers; } public boolean check(char[] answers) { return Arrays.equals(answers, this.answers); } } package main函数; import java.util.Scanner; public class PaperDemo { @SuppressWarnings("resource") public static void main (String[] args) { Question[] paper= {null,null}; paper[0]=new SingleQuestion("谁是司机?",new String[] {"A.小明","B.小李","C.小张","D.小红"},‘B‘); paper[0]=new MultiQuestion("谁是司机(DC)?",new String[] {"A.小明","B.小李","C.小张","D.小红"},new char[] {‘B‘,‘C‘}); Scanner console=new Scanner(System.in); for(int i=0;i<paper.length;i++) { Question q=paper[i]; q.print(); System.out.print("请选择:"); String str=console.nextLine(); char[] answers=str.toCharArray(); if(q.check(answers)) { System.out.println("正确"); } else System.out.println("不正确"); } } }
二.思路还没理清
三.复习.看下一章
以上是关于java学习第十一天2020/7/16的主要内容,如果未能解决你的问题,请参考以下文章