package aaa;
public class Person {
private String name;
private String like;
private int score;
public Person(){
}
public Person(String name, String like, int score) {
super();
this.name = name;
this.like = like;
this.score = score;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getLike() {
return like;
}
public void setLike(String like) {
this.like = like;
}
public int getScore() {
return score;
}
public void setScore(int score) {
this.score = score;
}
}
package aaa;
import java.util.Scanner;
public class Index {
Person p1;
Person p2;
Person p3;
Person p4;
public static void main(String[] args) {
Index in = new Index();
in.init();
in.start();
in.print();
}
private void print() {
System.out.println(p1.getName()+"得分"+p1.getScore());
System.out.println(p2.getName()+"得分"+p2.getScore());
System.out.println(p3.getName()+"得分"+p3.getScore());
System.out.println(p4.getName()+"得分"+p4.getScore());
}
private void start() {
System.out.println("开始答题");
int i = 1;
while (i <= 4) {
System.out.println("请选择答题方式:1.水果答人,2,人答水果,3。放弃");
boolean flag = true;
int m = 1;
do {
Scanner keyboardInput = new Scanner(System.in);
try {
m = keyboardInput.nextInt();
flag = false;
} catch (Exception e) {
System.out.println("请重新输入");
flag = true;
}
} while (flag);
switch (m) {
case 1:
switch (i) {
case 1:
System.out.println("谁喜欢" + p1.getLike());
Scanner keyboardInput = new Scanner(System.in);
if(keyboardInput.next().equals(p1.getName())){
p1.setScore(p1.getScore()+2);
}
break;
case 2:
System.out.println("谁喜欢" + p2.getLike());
Scanner keyboardInput2 = new Scanner(System.in);
if(keyboardInput2.next().equals(p2.getName())){
p2.setScore(p2.getScore()+2);
}
break;
case 3:
System.out.println("谁喜欢" + p3.getLike());
Scanner keyboardInput3 = new Scanner(System.in);
if(keyboardInput3.next().equals(p3.getName())){
p3.setScore(p3.getScore()+2);
}
break;
case 4:
System.out.println("谁喜欢" + p4.getLike());
Scanner keyboardInput4 = new Scanner(System.in);
if(keyboardInput4.next().equals(p4.getName())){
p4.setScore(p4.getScore()+2);
}
break;
default:
break;
}
break;
case 2:
switch (i) {
case 1:
System.out.println(p1.getName()+"喜欢什么?");
Scanner keyboardInput = new Scanner(System.in);
if(keyboardInput.next().equals(p1.getLike())){
p1.setScore(p1.getScore()+2);
}
break;
case 2:
System.out.println(p2.getName()+"喜欢什么?");
Scanner keyboardInput2 = new Scanner(System.in);
if(keyboardInput2.next().equals(p2.getLike())){
p2.setScore(p2.getScore()+2);
}
break;
case 3:
System.out.println(p3.getName()+"喜欢什么?");
Scanner keyboardInput3 = new Scanner(System.in);
if(keyboardInput3.next().equals(p3.getLike())){
p3.setScore(p3.getScore()+2);
}
break;
case 4:
System.out.println(p4.getName()+"喜欢什么?");
Scanner keyboardInput4 = new Scanner(System.in);
if(keyboardInput4.next().equals(p4.getLike())){
p4.setScore(p4.getScore()+2);
}
break;
default:
break;
}
break;
case 3:
break;
default:
break;
}
i++;
}
}
private void init() {
p1 = new Person("xiaoming", "apple", 0);
p2 = new Person("xiaoli", "xigua", 0);
p3 = new Person("xiaodong", "banana", 0);
p4 = new Person("xiaohua", "putao", 0);
}
}
package com.test;
import java.util.Scanner;
public class Baiduzhidao {
//总分
public static int sumScore = 0;
public static void main (String [] args){
//定义每题得分
int score = 2;
//三种答题方式
String[][] answerArr = {{"1","说水果答名"},{"2","说人名答水果"},{"3","放弃不答"}};
//四个题目/答案
String[][] questionArr = {{"小明","苹果"},{"小李","西瓜"},{"小东","香蕉"},{"小花","葡萄"}};
//输入器
Scanner scan = new Scanner(System.in);
System.out.println("答题开始……");
for (int i = 0; i < questionArr.length; i++) {
System.out.print("请选择第"+(i+1)+"题的答题方式:\t");
listAnswerMethod(answerArr);
int method = scan.nextInt();
switch (method) {
case 1:
System.out.println("问题:"+questionArr[i][1]);
System.out.print("答案:");
String ans = scan.next();
System.out.println(ans);
if(questionArr[i][0].equals(ans)){
sumScore += score;
System.out.println("回答正确,得两分");
}else{
System.out.println("回答错误,不得分");
}
break;
case 2:
System.out.println("问题:"+questionArr[i][0]);
System.out.print("答案:");
String ans1 = scan.next();
System.out.println(ans1);
if(questionArr[i][1].equals(ans1)){
sumScore += score;
System.out.println("回答正确,得两分");
}else{
System.out.println("回答错误,不得分");
}
break;
//选择其他均当做放弃答题
default:
System.out.println("放弃答题,不得分!");
break;
}
}
scan.close();
System.out.println("答题完成,总分为:"+sumScore);
}
/**
* 列出所有的答题方式
* @param answerArr
*/
public static void listAnswerMethod(String[][] answerArr){
for (String[] answer : answerArr) {
System.out.print(answer[0]+":"+answer[1]+"\t");
}
System.out.println();
}
}
//控制台输出:
答题开始……
请选择第1题的答题方式: 1:说水果答名 2:说人名答水果 3:放弃不答
1
问题:苹果
答案:小明
小明
回答正确,得两分
请选择第2题的答题方式: 1:说水果答名 2:说人名答水果 3:放弃不答
2
问题:小李
答案:狗屎
狗屎
回答错误,不得分
请选择第3题的答题方式: 1:说水果答名 2:说人名答水果 3:放弃不答
1
问题:香蕉
答案:小东
小东
回答正确,得两分
请选择第4题的答题方式: 1:说水果答名 2:说人名答水果 3:放弃不答
3
放弃答题,不得分!
答题完成,总分为:4
是不是要的这效果???
不用数组 用map什么的不好么