Need help making this a mutil answer, need all three to be answers and the team
ID: 3579576 • Letter: N
Question
Need help making this a mutil answer, need all three to be answers and the team need to answer all three to move on to the next question
Scanner sc = new Scanner(System.in);
int TeamAScore = 0, TeamBScore = 0;
int currentQuestionTeam = 0;
String[] questions = new String[6];
String[] answers = new String[6];
System.out.println("Welcome Team A and Team B I'm your host Steve Harvey");
System.out.println("I will be asking you some question and you will receive 1 point for each answer ");
System.out.println("you must type your answer in lower case form other wise you won't get the answer");
System.out.println("right. So lets get started!");
questions[0] = "Name types of beverages people drink:";
answers[0] ="Soda","Fruit juice","Tea";
questions[1] ="Name something people eat at breakfeast:";
answers[1] ="eggs","toast","bacon ";
questions[2] ="Place where you see lots of joggers?:";
answers[2] ="park","mountain","neighborhood";
questions[3]="Something people save?:";
answers[3]="money", "photos","coupons";
questions[4]="Why a baby might be cranky?:";
answers[4]="tired","hunger","burp";
questions[5]="Something small that scares childern and adults?:";
answers[5]="spiders","mice","rats";
for(int i=0;i< 6;i++){
for(int k=1;k<=3;k++){
if(currentQuestionTeam == 0){
System.out.println("Attempt "+k+" : Question to Team A: ");
System.out.println(questions[i]);
String ans = sc.nextLine();
if(ans.equals(answers[i])){
System.out.println("correct");
if(currentQuestionTeam == 0){
TeamAScore++;
currentQuestionTeam = 1;
i++;
break;
}else{
TeamBScore++;
currentQuestionTeam = 0;
i++;
break;
}
}
}else{
System.out.println("Attempt "+k+" : Question to Team B: ");
System.out.println(questions[i]);
String ans = sc.nextLine();
if(ans.equals(answers[i])){
System.out.println("correct");
if(currentQuestionTeam == 0){
TeamAScore++;
currentQuestionTeam = 1;
i++;
break;
}else{
TeamBScore++;
currentQuestionTeam = 0;
i++;
break;
}
}
}
}
currentQuestionTeam = 1;
for(int k=1;k<=3;k++){
if(currentQuestionTeam == 0){
System.out.println("Attempt "+k+" : Question to Team A: ");
System.out.println(questions[i]);
String ans = sc.nextLine();
if(ans.equals(answers[i])){
System.out.println("correct");
if(currentQuestionTeam == 0){
TeamAScore++;
currentQuestionTeam = 1;
i++;
break;
}
else
{
TeamBScore++;
currentQuestionTeam = 0;
i++;
break;
}
}
}
else
{
System.out.println("Attempt "+k+" : Question to Team B: ");
System.out.println(questions[i]);
String ans = sc.nextLine();
if(ans.equals(answers[i]))
{
System.out.println("correct");
if(currentQuestionTeam == 0)
{
TeamAScore++;
currentQuestionTeam = 1;
i++;
break;
}
else
{
TeamBScore++;
currentQuestionTeam = 0;
i++;
break;
}
}
}
}
currentQuestionTeam = 0;
}
System.out.println("Team A score: "+TeamAScore);
System.out.println("Team B score: "+TeamBScore);
if(TeamAScore > TeamBScore){
System.out.println("Team A wins");
}else if(TeamAScore < TeamBScore){
System.out.println("Team B wins");
}else{
System.out.println("Both teams same score");
}
}
}
Explanation / Answer
import java.util.Scanner;
public class FamilyFeud3
{
public static void main(String[] args)
{
Scanner sc = new Scanner(System.in);
int TeamAScore = 0, TeamBScore = 0;
int currentQuestionTeam = 0;
String[] questions = new String[6];
String[] answers = new String[6];
System.out.println("Welcome Team A and Team B I'm your host Steve Harvey");
System.out.println("I will be asking you some question and you will receive 1 point for each answer ");
System.out.println("you must type your answer in lower case form other wise you won't get the answer");
System.out.println("right. So lets get started!");
questions[0] = "First president of the United States?:";
answers[0] ="george washington";
questions[1] ="First food people learn to cook?:";
answers[1] ="eggs";
questions[2] ="Place where you see lots of joggers?:";
answers[2] ="park";
questions[3]="Something people save?:";
answers[3]="money";
questions[4]="Why a baby might be cranky?:";
answers[4]="tired";
questions[5]="Something small that scares childern and adults?:";
answers[5]="spiders";
for(int i=0;i< 6;i++)
{
int k=1;
///////////////////////////////////////////////////////////////////////////////////////
for(k=1;k<=3;k++)
{
if(currentQuestionTeam == 0)
{
System.out.println("Attempt "+k+" : Question to Team A: ");
System.out.println(questions[i]);
String ans = sc.nextLine();
if(ans.equals(answers[i]))
{
System.out.println("correct");
if(currentQuestionTeam == 0)
{
TeamAScore++;
currentQuestionTeam = 0;
break;
}
}
}
}
if(k<=3)
currentQuestionTeam = 0;
else
currentQuestionTeam = 1;
for(k=1;k<=3;k++)
{
if(currentQuestionTeam == 1)
{
System.out.println("Attempt "+k+" : Question to Team B: ");
System.out.println(questions[i]);
String ans = sc.nextLine();
if(ans.equals(answers[i]))
{
System.out.println("correct");
if(currentQuestionTeam == 1)
{
TeamBScore++;
currentQuestionTeam = 1;
break;
}
}
}
}
if(k<=3)
currentQuestionTeam = 1;
else
currentQuestionTeam = 0;
}
/////////////////////////////////////////////////////////////////////////////////////////
System.out.println("Team A score: "+TeamAScore);
System.out.println("Team B score: "+TeamBScore);
if(TeamAScore > TeamBScore){
System.out.println("Team A wins");
}
else if(TeamAScore < TeamBScore){
System.out.println("Team B wins");
}
else{
System.out.println("Both teams same score");
}
}
}
Note : For each get 3 chances to answer and if they are answered correctly the team noves to next question.if fails to answer in 3 chances then question pass to next team.
Output :
Welcome Team A and Team B I'm your host Steve Harvey
I will be asking you some question and you will receive 1 point for each answer
you must type your answer in lower case form other wise you won't get the answer
right. So lets get started!
Attempt 1 : Question to Team A:
First president of the United States?:
fgd
Attempt 2 : Question to Team A:
First president of the United States?:
fdg
Attempt 3 : Question to Team A:
First president of the United States?:
fdg
Attempt 1 : Question to Team B:
First president of the United States?:
fdg
Attempt 2 : Question to Team B:
First president of the United States?:
dfg
Attempt 3 : Question to Team B:
First president of the United States?:
dfg
Attempt 1 : Question to Team A:
First food people learn to cook?:
eggs
correct
Attempt 1 : Question to Team A:
Place where you see lots of joggers?:
s
Attempt 2 : Question to Team A:
Place where you see lots of joggers?:
s
Attempt 3 : Question to Team A:
Place where you see lots of joggers?:
s
Attempt 1 : Question to Team B:
Place where you see lots of joggers?:
park
correct
Attempt 1 : Question to Team B:
Something people save?:
money
correct
Attempt 1 : Question to Team B:
Why a baby might be cranky?:
f
Attempt 2 : Question to Team B:
Why a baby might be cranky?:
f
Attempt 3 : Question to Team B:
Why a baby might be cranky?:
f
Attempt 1 : Question to Team A:
Something small that scares childern and adults?:
f
Attempt 2 : Question to Team A:
Something small that scares childern and adults?:
f
Attempt 3 : Question to Team A:
Something small that scares childern and adults?:
f
Attempt 1 : Question to Team B:
Something small that scares childern and adults?:
f
Attempt 2 : Question to Team B:
Something small that scares childern and adults?:
f
Attempt 3 : Question to Team B:
Something small that scares childern and adults?:
f
Team A score: 1
Team B score: 2
Team B wins
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.