I am having problems to change the value of a variable. I found This older question, but I am still having problems to apply it to my code. If someone can review my code and give some guidance I will really appreciate it. This is my code:
public class GMTime {
private static String time;
private static int hour;
private static int minutes;
private static int colon;
private static String error = null;
// **********************************************************
// constructor passing time as a string
public GMTime(String temp) {
time = temp;
}
// end constructor
// **********************************************************
// method checking the colon presence and place between 1-2 index
public String colonCheck(String error) {
while (time.contains(":")) {
colon = time.indexOf(":");
} // end of while
if (colon != 1 || colon != 2) {
error = "Invalid separator entered";
}
System.out.println(error);
return error;
} // end colon check
public static String getError(){
return error;
}
}
Driver:
import java.util.Scanner;
public class GMUnit6Ch15{
public static void main(String[] args){
Scanner stdIn = new Scanner(System.in);
String time;
System.out.print("Enter time in the form mm:dd (\"q\" to quit) :");
time = stdIn.next();
while (!time.equalsIgnoreCase("q")){
GMTime userTime = new GMTime(time);
System.out.print("Enter time in the form mm:dd (\"q\" to quit) :");
time = stdIn.next();
}
I added this just to test if the modified error works.
System.out.println(GMTime.getError());
}//end of main
}// end of class
What I want to do is if "colon" is not present in "time" change the value of "error" so that I can print it later from the driver.