package com.codegym.task.task04.task0416;
/*
Crossing the road blindly
*/
import java.io.*;
public class Solution {
public static void main(String[] args){
double minutesTyped = getUserInput();
lightColor(minutesTyped);
}
public static double getUserInput(){
InputStream inputStream = System.in;
Reader inputStreamReader = new InputStreamReader(inputStream);
BufferedReader bufferedReader = new BufferedReader(inputStreamReader);
double inputNumber = Double.valueOf(bufferedReader.readLine()).doubleValue();
return inputNumber;
}
public static String lightColor(double minutes){
double remainder = minutes % 5.0;
String light = "";
if(remainder <= 3.0){
light = "green";
System.out.println(light);
}else if(remainder <= 4.0){
light = "yellow";
System.out.println(light);
}else{
light = "red";
System.out.println(light);
}
return light;
}
}
For some reason, the question will not allow me to attach the code in the normal way (grayed out for this option). What I would like help with is the exception error message I am getting.
hidden #10362262
Level 9
"unreported exception error" - help me understand this
Under discussion
Comments (4)
- Popular
- New
- Old
You must be signed in to leave a comment
KAH KISSINGER
4 November 2018, 20:55
this is because you decided to use too many variables beyond the scope of your study level. see...
public class Solution {
public static void main(String[] args) throws Exception{
BufferedReader x = new BufferedReader(new InputStreamReader(System.in));
String s = x.readLine();
double a = Double.parseDouble(s);
double t = a % 5.0;
if(t>= 0 && t < 3.0){
System.out.println("green");
}else if(t >= 3.0 && t < 4.0){
System.out.println("yellow");
}else{
System.out.println("red");
+1
Alam
4 November 2018, 18:29
Exception will come later. Don't worry for now, Just keep going. Try to change the logic.
+1
Khurram
4 November 2018, 09:56
there is a complete chapter on Exceptions, don't worry, just go with it for now, you will learn about it when the time comes :)
+1
hidden #10362262
4 November 2018, 03:06
I was able to get the code above to pass by repeating the "throws Exception" phrase within the getUserInput method. Also I had to change the if / else conditions in order to get the proper color to display. I still would like to understand the "throws Exception" phrase and the "unreported exception" error message. Thank you!
0