I need some help with the task | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
- 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

16th Jun 2021, 6:33 AM
Мирбек Исмаилов
Мирбек Исмаилов - avatar
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.
16th Jun 2021, 7:13 AM
The future is now thanks to science
The future is now thanks to science - avatar
+ 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
16th Jun 2021, 7:06 AM
The future is now thanks to science
The future is now thanks to science - avatar
+ 1
Thanks a lot for explaining, I really appreciate it
16th Jun 2021, 7:42 AM
Мирбек Исмаилов
Мирбек Исмаилов - avatar
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"); } }
16th Jun 2021, 6:36 AM
Мирбек Исмаилов
Мирбек Исмаилов - avatar
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!
18th Oct 2021, 1:45 PM
César Díaz Amat