Need help assigning range for an integer for subtracting time.

Ok, so I'm having a little trouble getting this program to work. :x Maybe somebody could give me some help on what to do next. I'm new to Java, and I'm trying to write a program using NetBeans 6.9.1, and I ran into a problem. I'm trying to write a program for a time traveler Marty, who is going back in time. The time is set on a 24 hour clock, so am and pm is not an issue.
I have the program written, but I'm having trouble with the subtraction of the time. Whenever I do the subtract, and the time traveled back (either in hours, minutes or seconds), is bigger than the current time, I just end up with negative numbers. I don't know how to set the value so it will just recycle through the 24 hours, the 60 minutes, or 60 seconds, instead of giving me negative numbers. Any help would be greatly appreciated. Also, I'm not sure how to make the users input italic. Here is what I got so far.
package timetravel;
* @author Jeff
import java.io.*;
import java.util.*;
public class Main {
* @param args the command line arguments
public static void main(String[] args) {
int hours, minutes, seconds, hoursback, minutesback, secondsback;
Scanner keyboard = new Scanner (System.in);
System.out.println("Hi Marty!");
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("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();
System.out.println("When you arrive, the local time will be " + (hours - hoursback)
+ " hours, " + (minutes - minutesback) + " minutes, and " + (seconds - secondsback)
+ " seconds.");

Well, basically, here's how I want the program to run
Example program run:
Hi Marty!
Enter current hour: 8
Enter current minute: 12
Enter current second: 11
Enter how many hours you want to travel back: 9
Enter how many minutes you want to travel back: 36
Enter how many seconds you want to travel back: 39
When you arrive, the local time will be: 22 hours, 35 minutes, and 32 seconds
(program input is written in italic)
instead of how it runs now
Hi Marty!
Enter current hour: 8
Enter current minute: 12
Enter current second: 11
Enter how many hours you want to travel back: 9
Enter how many minutes you want to travel back: 36
Enter how many seconds you want to travel back: 39
When you arrive, the local time will be: -1 hours, -24 minutes, and -28 seconds
I want it to cycle through the 24 hour clock, so if I travel back in time from 18 (1800 or 6pm) and i want to travel back in time 20 hours, I should get 22 (2200 or 10 pm) instead of -2.
Same with minutes and seconds, except for it to cycle through 60 instead of 24, since there are 60 minutes in an hour, and 60 seconds in a minute. Also, if the minutes end up being negative, I need it to take away one from the hour spot, and so on for the other ones. Hopefully I explained it well enough... Sorry, I'm new to Java.
Edited by: halo2jak on Sep 7, 2010 12:24 AM

Similar Messages

  • Need help loggin in for first time

    The registration question they wanted was a URL word to use. Now matter what I put in the blank, it was rejected. What are you looking for?

    Hi patmladic-
    Can you give me more information please? Which site were you trying to register on? Why do you believe this is an issue with the browser Firefox- instead of the website you were trying to use?

  • Need unique number ranges for self billing, retro billing, and manual credi

    Need unique number ranges for self billing, retro billing, and manual credit/debit memos.

    Hi,
    I guess you are using different document types for normal billing, self billing and retro.  So maintain different numbers for these document types in VN01 and assign the number range in VFOA (document type)
    ~Thanks!
    Rajesh

  • I need help choosing RAM for MSI PM8PM-V 7222 VER. 2.0 MB

    hey everyone as you know my MB is in the subject and i need help buying ram for it. on the MSI website it says it can surpport max. 2GB so 1GB in each slot? it only has 2 slots also what DDR and MHZ clock, DRAM fequency etc does the ram have to be and both single sided or double sided or 1 single and 1 double?
    thanks

    Quote
    also what DDR and MHZ clock, DRAM fequency etc does the ram have to be
    http://global.msi.eu/index.php?func=proddesc&maincat_no=1&prod_no=1039
    Quote
    • Supports DDR2 533/400 memory interface.
    Check the memory support list for best compatibility:
    http://global.msi.eu/uploads/test_report/TR10_1039.pdf

  • I need help finding cases for the ipod touch thrid gen help.

    i need help finding case for ipod touch thrid gen help.

    - Try another cable.
    - Try another USB port
    - Inspect the dock connector on the iPod for bent or missing contacts, foreign material, corroded contacts, broken, missing or cracked plastic.
    - Try on another computer. Just backup a couple of times. Do not sync.

  • What is the range for the Time Capsule

    Good day for you all,
    Can anyone help me on the following:
    1. What is effective the range for the Time Capsule if there are 2 walls 6" thick each obstacle the way?
    2. Can I backup my data to my Time Capsule anywhere in the world using the Internet?
    3. Can I use the Time Capsule to backup data on my iphone, ipad and ipod?
    Regards

    waleedfromabu-dhabi wrote:
    Good day for you all,
    Can anyone help me on the following:
    1. What is effective the range for the Time Capsule if there are 2 walls 6" thick each obstacle the way?
    It is not that simple.. are the walls hollow or solid concrete..?? it is not the thickness of the walls.. but the thickness of material and angle of penetration.. remember wierless is a dead straight line.. Tx to Rx.. so a 30deg angle through concrete is a lot more material than just 6" steel reinforcing is really bad.. at an angle it maybe hard for the wireless to see a gap.
    Through standard plasterboard.. rockboard in US I think. walls, with no insulation.. about 15% signal drop on each.. the TC should work ok in standard size house over single floor at least at 2.4ghz .. but the speed will drop as you get further away. Difficult to say more.. that is why apple make the extreme and express and TC can all extend wireless from each other. But all this is only 2.4ghz. 
    5ghz you will be lucky to get signal through two walls.
    2. Can I backup my data to my Time Capsule anywhere in the world using the Internet?
    You can access the TC by using BTMM via iCloud in certain circumstances.. we would not recommend backups over internet.. the possiblity of corrupting the whole backup is too high. Just use a 2.5" portable drive.. ML can backup TM to different targets..
    3. Can I use the Time Capsule to backup data on my iphone, ipad and ipod?
    Not directly.. they do not work with TC.. they work with iTunes.. and you automatically backup to itunes locally or cloud.. then Time Machine backs up the iTunes.
    You can access the file and store files on the TC if you use a file browser app. But this is not the intended method of operation of any of those devices.

  • I have quicktime pro and it does NOT have the screen record mode that Quicktime is suppose to have.  Can I uninstall it and go back to an older version that would have screen recording?  If so, how?  Step by step needed.  Thank you for your time.

    I have quicktime pro and it does NOT have the screen record mode that Quicktime is suppose to have.  Can I uninstall it and go back to an older version that would have screen recording?  If so, how?  Step by step needed.  Thank you for your time.

    Did you remove Quicktime X?
    On a normal install Quicktime 7 is installed in the Utilities folder and Quicktime Pro in the main Applications folder.
    You will need to reinstall OS X to get Quicktime X back if you have deleted it.
    I notice yor profile says 10.5.8. Quicktime X is only available on 10.6 and above.

  • I need help with my for loop in this array

    Ok well, I can't get my code to work. Also, please remember that this is just my draft so it isnt pretty. I will fix it up later so please look at it. The thing I want to do is look into the array for a time that matches what the user entered and return the toString() of that one. I know there is something wrong with my for loop but I cant figure how to fix it. please help. here is what i have so far:
    import javax.swing.JOptionPane;
    public class Runner
        public static void main (String[] args)
            String timeStr;
            int time, again, optiStr;
            Inbound[] in = new Inbound[25];
             in[0]=new Inbound ("",0,"On Time num0");
             in[1]=new Inbound ("",2,"On Time num1");
             in[2]=new Inbound ("",3,"Delayed num2");
             in[3]=new Inbound ("",4,"On Time");
             in[4]=new Inbound ("",5,"On Time");
             in[5]=new Inbound ("",6,"Canceled");
             in[6]=new Inbound ("",1,"Canceled num6");
             in[7]=new Inbound ("",8,"On Time");
             in[8]=new Inbound ("",9,"Delayed");
             in[9]=new Inbound ("",10,"On Time");
             in[10]=new Inbound ("",11,"Delayed");
             in[11]=new Inbound ("",12,"On Time");
             in[12]=new Inbound ("",13,"Delayed");
             in[13]=new Inbound ("",14,"On Time");
             in[14]=new Inbound ("",15,"On Time");
             in[15]=new Inbound ("",16,"On Time");
             in[16]=new Inbound ("",17,"Canceled");
             in[17]=new Inbound ("",18,"On Time");
             in[18]=new Inbound ("",19,"On Time");
             in[19]=new Inbound ("",20,"Canceled");
             in[20]=new Inbound ("",21,"On Time");
             in[21]=new Inbound ("",22,"Delayed");
             in[22]=new Inbound ("",23,"On Time");
             in[23]=new Inbound ("",24,"Cancled");
             in[24]=new Inbound ("",7,"On Time num24");
            do{
                timeStr = JOptionPane.showInputDialog ("In military time, what hour do you want?");
                time = Integer.parseInt(timeStr);
                if (time<=0 || time>24)
                 JOptionPane.showMessageDialog (null, "Error");
                 optiStr = JOptionPane.showConfirmDialog (null, "If you want Incoming flights click Yes, but if not click No");
                if (optiStr==JOptionPane.YES_OPTION)
    //(ok this is the for loop i am talking about )
                    for (int index = 0; index < in.length; index++)
                      if ( time == Inbound.getTime())
                   JOptionPane.showMessageDialog (null, Inbound.tostring());  //return the time asked for
    //               else JOptionPane.showMessageDialog (null, "else");
                }//temp return else if failed to find time asked for
    //             else
    //               if (optiStr==JOptionPane.CANCEL_OPTION)
    //                 JOptionPane.showMessageDialog(null,"Canceled");
    //              else
    //                {Outbound.run();
    //                JOptionPane.showMessageDialog (null, "outbound");}//temp
                  again=JOptionPane.showConfirmDialog(null, "Try again?");
            while (again==JOptionPane.YES_OPTION);
    }any help would be greatly appriciated.

    rumble14 wrote:
    Ok well, I can't get my code to work. Also, please remember that this is just my draft so it isnt pretty. I will fix it up later so please look at it. The thing I want to do is look into the array for a time that matches what the user entered and return the toString() of that one. I know there is something wrong with my for loop but I cant figure how to fix it. please help. here is what i have so far:
    >//(ok this is the for loop i am talking about )
    for (int index = 0; index < in.length; index++)
    if ( time == Inbound.getTime())
    JOptionPane.showMessageDialog (null, Inbound.tostring());  //return the time asked for
    Inbound.getTime() is a static method of your Inbound class, that always returns the same value, I presume? As opposed to each of the 25 members of your array in, which have individual values?
    Edited by: darb on Mar 26, 2008 11:12 AM

  • HOW DO YOU GUYS DEAL WITH APPLE.. SO CONFUSING...NEED HELP WITH SPECS FOR PURCHASE OF IMAC 21.5

    Hi guys, been reading your forums, blogposts, etc and am getting more confused.  I'm just a video girl trying to produce meaningful content through web videos for small to mid sized businesses and want to come over from the dark side. 
    Good news,, I dont need a super giant system,  I do simple editing for web videos, minimal graphics, no motion graphics, no animation etc. currently using CS4, will probably end up with 5.5.
    I want to get imac 21.5 or 27 if i have to..  So here's the question we all have,,, what do I really need besides an Apple fairy godmother to figure this crazy stuff out?????
    I want to be able to have firewire add on, but the rest is what I need help with.   So i've been looking at cs6 specs, even though im not there yet, eventually will be,, so just need to run cs4 now and build from there.  I also want to eventually move to final cut down the road so I want imac able to upgrade to final cut.
    WHAT DO I REALLY NEED MINIMALLY FOR NOW?  WHAT CAN I GET LATER IF i CHOOSE TO DO MORE AND NEED MORE POWER?
    cs6:
    Multicore Intel processor with 64-bit support
    Mac OS X v10.6.8, v10.7, or v10.8**
    4GB of RAM (8GB recommended)
    4GB of available hard-disk space for installation; additional free space required during installation (cannot install on a volume that uses a case-sensitive file system or on removable flash storage devices)
    Additional disk space required for preview files and other working files (10GB recommended)
    1280x900 display
    7200 RPM hard drive (multiple fast disk drives, preferably RAID 0 configured, recommended)
    OpenGL 2.0–capable system
    DVD-ROM drive compatible with dual-layer DVDs (SuperDrive for burning DVDs; Blu-ray burner for creating Blu-ray Disc media)
    QuickTime 7.6.6 software required for QuickTime features
    Optional: Adobe-certified GPU card for GPU-accelerated performance
    Any responses would be great.  I know you guys are busy answering the really high end tech questions

    All the current iMac models (both 21.5" and 27" with OS X Mt. Lion 10.8) will run CS4, 5.5 and 6 just fine.  They will also run Final Cut Pro X just fine.  Ditto for most any application you may want to use.
    Below are some notes (specific to your apparent requirements) that may help you with your purchase decision:
    Notes on purchasing a 21.5" iMac
    All 21.5" iMacs come with 8GB RAM but you cannot add more later.  I strongly suggest getting the maximum RAM (16GB) when you order the iMac.
    The basic hard drive is a 1TB 5400rpm drive.  It will work fine with Adobe CS but you will probably want the added speed of the optional 1TB Fusion drive for better performance. Some people will recommend/argue for one of the optional SSD drives instead, but they are very expensive and still only come in relatively small capacities - I don't recommend the SSD drives.  Get the Fusion drive and spend any extra money on a good external hard drive for backup and/or extra storage instead of an SSD.
    Notes on purchasing a 27" iMac
    All 27" iMacs come with 8GB RAM and you can add more later, up to 32GB
    The basic hard drive is a 1TB 7200rpm drive - it will be fine with Adobe CS.  There are upgrade options to a 3TB 7200rpm drive or a 1TB or 3TB fusion drive - these will be fine also.  There are also SSD drive options, but I do not recommend them. (Same comments as above.)
    Notes on all the current iMacs
    iMacs no longer come with built-in CD/DVD drives.  If you need one, you will need to purchase the Apple Superdrive accessory drive ($79)
    All of the iMac graphic processors (GPU's) are compatible with Adobe CS 4, 5.5, 6
    It is very difficult to impossible to change or upgrade the hard drive later on, so don't buy low-end thinking you can add a better internal hard drive later.
    Be aware that Macs always come with the latest (most recent) version of OS X.  And OS X Mavericks (10.9) is due to be released soon (in the next month or two).  There is no guarantee that the older Adobe CS 4 or 5.5 versions will run on OS X Mavericks.  If you cannot upgrade to CS 6 in the near future, you may want to purchase now rather than after OS X Mavericks is released.
    For what it's worth, I'd recommend the 27" iMac if your budget can afford it.  You will appreciate the larger screen size and added capabilities over the years you will use the computer.

  • Need Help with spry for uploading to a website

    Sorry if there is already a thread about this but i cant seem to get this to work. So I have looked around an dfound that you need to have the spry files uploaded to the server and i have done that, but the page still looks wrong. Here is a link so you guys can see what it looks like and i'm sorry about the page being in norwegian.
    http://miljopose.net/kjop.html
    I really need help because this is for a project i am doing at school.

    None of these files can be found
    <script src="SpryAssets/SpryValidationTextField.js" type="text/javascript"></script>
    <script src="SpryAssets/SpryValidationConfirm.js" type="text/javascript"></script>
    <link href="SpryAssets/SpryValidationTextField.css" rel="stylesheet" type="text/css" />
    <link href="SpryAssets/SpryValidationConfirm.css" rel="stylesheet" type="text/css" />
    Please upload the files in the correct directory
    Gramps

  • Need help with a For loop that uses a Break statement

    I need to create a for loop which counts down from 100-50 and divides the number being counted down by a counter. Can anyone help me?
    public class Break
    public static void main ( String args []) (;
         int total = 0
         int counter = 0
         for { (int number = 100; total >=50; total --)
         if (counter == 0)
         break;
         } // end of for loop
         int output = number/counter
         system.out.printf("The number is" %d output/n)
         }// end of method main
    }// end of class Break

    Im sorry I didnt explain myself very well i do not need the break statement at all.
    I now have this code:
    public class BreakTest
       public static void main( String args[] )
          int count; // control variable also used after loop terminates
         for (int i = 100; i >= 50; i = ++count)
       if (i >= 50) {
        continue;
          System.out.printf( "\nBroke out of loop at count = %d\n", count );
       } // end main
    } // end class BreakTest
    /code]
    and i get these error messages:
    F:\csc148>javac BreakTest.java
    BreakTest.java:9: variable count might not have been initialized
         for (int i = 100; i >= 50; i = ++count)
                                          ^
    BreakTest.java:15: variable count might not have been initialized
          System.out.printf( "\nBroke out of loop at count = %d\n", count );
                                                                    ^
    2 errors                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           

  • Need help with driver for Canon Selphy CP810 osx 10.8.3

    I need help to get my Canon Selphy CP810 running .
    Could not find a driver that works on the WEB.

    Here's a driver from Canon for 10.8.x.
    Clinton

  • Need help with animation, for my XAML game

    Hello friends,
    I need help in creating animation for my snake and ladder game(C#,XAML). I have completed the game logic, but can't understand how to animate my UI.
    1. I want to animate 6 dice images so that when the player clicks on the Roll Dice Button a shuffle animation will play, and while the animation is playing the user can't click any thing.
    2. I want the player disc to move one step at a time (animation) on the game board.
    Please help me I am new to animation. Kindly give a reply

    Hello,
    I would recommend using
    Storyboards and / or the
    XAML animation library.
    Other resources:
    Storyboarded animations (XAML)
    XAML animation library sample
    I hope this helps,
    James
    Windows SDK Technologies - Microsoft Developer Services - http://blogs.msdn.com/mediasdkstuff/

  • Need Help With Download For Airport Express

    Ok, computer dummy here needing help with airport express. We were given airport express last night from a friend who recently purchased a newer gadget. He told us we would need to come here to download the operating system. I see lots of links to updates but no links for someone like me who has never had anything like this on my computer before. Does anyone know what link I would need to use? We have a pc with windows XP. Thanks so much for your help!

    Hello jesschambers. Welcome to the Apple Discussions!
    The AirPort Express Base Station (AX) doesn't have an "operating system" per se, but it does have built-in firmware which pretty much is the same thing. In addition, in order to administer the AX, you will need the AirPort Admin Utility for your Windows PC.
    Here are the links for the latest versions of both:
    o AirPort Express Firmware Update 6.3 for Windows
    o AirPort 4.2 for Windows

  • Need help with pagination for book

    I am working on a book and need help with the pagination. I was able to make the TOC and front matter show the numbers as Roman numerals, and the body of the text as Arabic numerals, but I can't figure out how to restart the numbering sequence for the body of the text. So the front matter is numbered i-xvi, and the text is 17-681. I need the text to start with the number 1. Each subsequent chapter is a section break as well, if that makes a difference.
    Many thanks,
    J

    Click on the page that shall start on number one. Open Inspector palette > Layout inspector (2nd tab) >
    Section > Start at: > 1

Maybe you are looking for

  • Error in SC Creation

    Hi All, One of our user is getting the following error " Error in System;Shopping Cart cannot be processed further". I have checked the roles assigned to this user and it looks perfect.The user is creating a SC for the first time in SRM.The user is a

  • VERY strange lag on a Dell Optiplex 760

    I thought it would be a good idea to keep a 16GB flash drive on my keychain that booted Arch so I could work on HW for college in a consistent OS!  Everything is working great so far, but I ran into a very strange problem with a Dell Optiplex 760.  D

  • Error in Database monitoring in Solution Manager Diagnostic

    Hello All, I'm facing issue in configuring Database monitoring for Java system (EP/PI) from Solution manager . It could be configured from sol man diagnostic>Diagnostic System>Managed system>Database monitoring, iei'm unable to have java system in DB

  • Calling a abstract portal component from portal service

    Hi Can i access a abstract portal component from portal service? My requirement is i have a method called getsessionID in portal service. My portal service is enabled as a webservice. Who ever consumes my webservice they will call this method. This m

  • OS Yosemite Slowed My MAC DOWN!

    I am new to Mac and a brand new user with Apple products.  Since I upgraded to this OS Yosemite, it slowed my computer even slower than my previous windows pc.  As a new user, I am very disappointed and of course I can't return my Mac now since its o