- 2
I need some help with the task
You are an administrator at a football club who must categorize already played games on the team's website. The given program takes 3 inputs: 1. match status - which checks if the match is suspended ("true") or not suspended ("false") 2. your team's score 3. opposing team's score. Complete the program so that if the match is suspended (the 1st input is "true"), it will output "Suspended". If the match is not suspended ( the1st output is false), the following statuses should be set depending on the match result: "Won", "Lost" and "Draw". Sample Input false 3 2 Sample Output Won
5 Answers
+ 4
Now let me explain what mistakes you have done:
1.First you haven't closed a curly bracket at the end. So that's why you get the first error
.You should add an extra } bracket.
2.Next you have written:
int ourScore = x;
int theirScore = y;
what in the world you were trying to achieve?
If you want to give the value inside x and y your line should be :
int x=ourScore;
int y=theirScore;
3.Next you have written:
if (x==y) {
if (x>y) {
System.out.println("Won");
}
else {
System.out.println("Lost");
}
System.out.println("Draw");
}
In your condition first, it will check if x==y, if yes then, it will check if x>y which doesn't make sense. Because if x==y then it will never become x>y, So it will always give output Lost.
4.In the question, they said,
Complete the program so that if the match is suspended (the 1st input is "true"), it will output "Suspended".
There is no code to check if the match has been suspended or not.
+ 2
You have done a lot of mistakes.
After solving your mistakes the code will be like this (maybe because I don't know java):
https://code.sololearn.com/c4A18a2A852a
+ 1
Thanks a lot for explaining, I really appreciate it
0
This is my code, can't find what is wrong
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner read = new Scanner(System.in);
boolean isSuspended = read.nextBoolean();
int ourScore = read.nextInt();
int theirScore = read.nextInt();
int ourScore = x;
int theirScore = y;
if (x==y) {
if (x>y) {
System.out.println("Won");
}
else {
System.out.println("Lost");
}
System.out.println("Draw");
}
}
0
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner read = new Scanner(System.in);
boolean isSuspended = read.nextBoolean();
int ourScore = read.nextInt();
int theirScore = read.nextInt();
// tu código va aquí
if(isSuspended == true){
System.out.println("Suspended");
} else{
if (ourScore > theirScore ){
System.out.println("Won");
}
if (ourScore == theirScore ) {
System.out.println("Draw");}
if (ourScore < theirScore ){
System.out.println("Lost");
}
}
}
}
Very important to take care of the" } "symbol. In my case I couldn't get all the cases right just with "if" staments, so I wrote "else" after the first "if" and it worked for me. The order was Won, Draw, Lost, before that it didn't work also, maybe because I had the wrong number of " }". Hope it helps someone!