Hi, I'm brand new to Java and I've just been making simple projects to get into the swing of things. So far I've had reasonable success but I can't figure out what the problem is with this code. I know it has something to do with the "System.out.println(puppyObject.setTime" thing but I have no idea what is wrong with it. It's probably something really simple and not important at all but I'd just like to know since I believe this might be important in future projects.
Here is the code:
import java.util.Scanner; class kitten{ public static void main(String args[]){ Scanner input = new Scanner(System.in); puppy puppyObject = new puppy(); System.out.println(puppyObject.setTime(0, 0, 0)); System.out.println(puppyObject.toMilitary()); } } import java.util.Scanner; class puppy{ public int hour; public int minute; public int second; public void setTime(int h, int m, int s){ Scanner input = new Scanner(System.in); hour = h; minute = m; second = s; System.out.println("Set the hour."); h = input.nextInt(); while(m == 0){ if(h >= 0 && h <=24){ System.out.println("Set the minute."); m = input.nextInt(); } else{ System.out.println("Try again, make sure you input a number between 0 and 24."); h = input.nextInt(); } } while(s == 0){ if(m >= 0 && m <= 60){ System.out.println("Set the second."); s = input.nextInt(); } else{ System.out.println("Try again, make sure you input a number between 0 and 60."); m = input.nextInt(); } } if(s >= 0 && s <= 60){ } else{ System.out.println("Try again, make sure you input a number between 0 and 60."); s = input.nextInt(); } } public String toMilitary(){ return String.format("%02d:%02d:%02d", hour, minute, second); } }
Thanks in advance,
Terty
EDIT: I forgot to mention that I'd also just like to ask if I have to import the Scanner util in the main class if it's not really used there but the code that needs it is included.