package com.codegym.task.task04.task0416;
/*
Crossing the road blindly
*/
import java.io.*;
import java.nio.Buffer;
public class Solution {
public static void main(String[] args) throws Exception {
//write your code here
/*
The pedestrian traffic light is programmed as follows:
at the beginning of each hour, the green signal is on for three minutes,
then the signal is yellow for one minute,
and then it is red for one minute.
Then the light is green again for three minutes, etc.
Use the keyboard to enter a real number t that represents the number of minutes that have elapsed since the beginning of the hour.
Determine what color the traffic light is at the specified time.
Display the result as follows:
"green" if the light is green,
"yellow" if the light is yellow, and
"red" if the light is red.
Example for 2.5:
green
Example for 3:
yellow
Example for 4:
red
Example for 5:
green
*/
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
double t = (int) Double.parseDouble(reader.readLine());
String name = null;
for(int i=1;i<=t;i++)
{
if(4*i-3==t || 4*i-2==t)
{
name = "green";
}
else if(4*i-1==t)
{
name = "yellow";
}
else if(4*i==t)
{
name = "red";
}
}
String light;
light = name;
if(light == "green")
{
System.out.println("green");
}
else if(light == "yellow")
{
System.out.println("yellow");
}
else if(light == "red")
{
System.out.println("red");
}
}
}
package com.codegym.task.task04.task0416;
/*
Crossing the road blindly
*/
import java.io.*;
import java.nio.Buffer;
public class Solution {
public static void main(String[] args) throws Exception {
//write your code here
/*
The pedestrian traffic light is programmed as follows:
at the beginning of each hour, the green signal is on for three minutes,
then the signal is yellow for one minute,
and then it is red for one minute.
Then the light is green again for three minutes, etc.
Use the keyboard to enter a real number t that represents the number of minutes that have elapsed since the beginning of the hour.
Determine what color the traffic light is at the specified time.
Display the result as follows:
"green" if the light is green,
"yellow" if the light is yellow, and
"red" if the light is red.
Example for 2.5:
green
Example for 3:
yellow
Example for 4:
red
Example for 5:
green
*/
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
double t = (int) Double.parseDouble(reader.readLine());
String name = null;
for(int i=1;i<=t;i++)
{
if(4*i-3==t || 4*i-2==t)
{
name = "green";
}
else if(4*i-1==t)
{
name = "yellow";
}
else if(4*i==t)
{
name = "red";
}
}
String light;
light = name;
if(light == "green")
{
System.out.println("green");
}
else if(light == "yellow")
{
System.out.println("yellow");
}
else if(light == "red")
{
System.out.println("red");
}
}
}