package com.codegym.task.task04.task0416;
/*
Crossing the road blindly
*/
import java.io.*;
public class Solution {
public static void main(String[] args) throws Exception {
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
double t = Double.parseDouble(reader.readLine());
if (t>4) t=t%4;
if (t>60) t = t%60;
if (t>0 && t<3)
System.out.print("green");
else if (t>=3 && t <4)
System.out.print("yellow");
else System.out.print("red");
}
}
Task requirements are not met
Resolved
Comments (2)
- Popular
- New
- Old
You must be signed in to leave a comment
Gellert Varga
18 April 2020, 20:08
Hi!:)
1.) Line 15: if t>4 t=t%4;
I think you think the cycle of the lights is four minutes.
But!
Green 3 minutes, yellow 1 minute, red 1 minute. It's 5 minutes total.
Then the same thing starts all over again, which is 5 minutes again and again.
2.) Line 15: if t>4 t=t%4;
So from now, the value of "t" will be ALWAYS between 0 and 4. It can be never more than 4!
So, the Line 16 test (if t>60) loses its meaning.
It's not needed.
3.) Line 18: If t>0...
But what if t=0.0?
Then it should be green...
4.) An advice:
If you test your program a lot, with different input values, it will always help a lot to detect what the problem is.
0
Andrew Nguyen
18 April 2020, 23:27
Thank you. That helps a lot
0