halo2jak
2010-10-10 10:43:27 UTC
Also, I want to try and figure out how to check the validity of the user input, and you can see that I tried, but I think it's wrong, because even if the user inputs something wrong, it goes onto the next line for the user to input something. I want it to keep repeating the line until the user inputs the right input. I'm new to java, so any help would be appreciated!
import java.io.*;
import java.util.*;
public class Main {
public static void main(String[] args) {
String month;
int days, months, hours, minutes, seconds, monthsback, daysback, hoursback, minutesback, secondsback;
int timecurrent, timeback, timediff, resultseconds, resultminutes, resulthours;
Scanner keyboard = new Scanner (System.in);
System.out.println("Hi Marty!");
System.out.println("What month is it:");
month = keyboard.next();
if (!month.equalsIgnoreCase("January"))
if (!month.equalsIgnoreCase("February"))
if (!month.equalsIgnoreCase("March"))
if (!month.equalsIgnoreCase("April"))
if (!month.equalsIgnoreCase("May"))
if (!month.equalsIgnoreCase("June"))
if (!month.equalsIgnoreCase("July"))
if (!month.equalsIgnoreCase("August"))
if (!month.equalsIgnoreCase("September"))
if (!month.equalsIgnoreCase("October"))
if (!month.equalsIgnoreCase("November"))
if (!month.equalsIgnoreCase("December"))
if (month.equalsIgnoreCase("January"))
months = 1;
if (month.equalsIgnoreCase("February"))
months = 2678400;
if (month.equalsIgnoreCase("March"))
months = 5097600;
if (month.equalsIgnoreCase("April"))
months = 7776000;
if (month.equalsIgnoreCase("May"))
months = 10368000;
if (month.equalsIgnoreCase("June"))
months = 13046400;
if (month.equalsIgnoreCase("July"))
months = 15638400;
if (month.equalsIgnoreCase("August"))
months = 18316800;
if (month.equalsIgnoreCase("September"))
months = 20995200;
if (month.equalsIgnoreCase("October"))
months = 23587200;
if (month.equalsIgnoreCase("November"))
months = 26265600;
if (month.equalsIgnoreCase("December"))
months = 28857600;
System.out.println("That isn't a month Marty!");
System.out.println("What day in " + month + ":");
days = keyboard.nextInt();
System.out.println("Enter current hour:");
hours = keyboard.nextInt();
System.out.println("Enter current minute:");
minutes = keyboard.nextInt();
System.out.println("Enter current second:");
seconds = keyboard.nextInt();
System.out.println("How many days do you want to travel back:");
daysback = keyboard.nextInt();
System.out.println("Enter how many hours you want to travel back:");
hoursback = keyboard.nextInt();
System.out.println("Enter how many minutes you want to travel back:");
minutesback = keyboard.nextInt();
System.out.println("Enter how many seconds you want to travel back:");
secondsback = keyboard.nextInt();
It's right here where the months and monthsback have a red line underneath them, saying they are not initialized.
timecurrent = (months + (days*60*60*24) + (hours)*60*60) + ((minutes)*60) + seconds;
timeback = monthsback + (daysback*60*60*24) + (hoursback*60*60) + (minutesback*60) + secondsback;
timediff = (86400 + (timecurrent - timeback)) % 86400;
resultseconds = timediff % 60;
timediff = timediff / 60;
resultminutes = timediff % 60;
timediff = timediff / 60;
resulthours = timediff;
System.out.println("When you arrive, it will be: " ); //This is how far i've gotten so far.