Results 1 to 11 of 11
  1. #1
    HPcompaq256 is offline Member
    Join Date
    Feb 2010
    Posts
    12
    Rep Power
    0

    Default Write a Program that reads two times in military format

    sasaaaaaaaaaaaaaaaaaa
    Last edited by HPcompaq256; 02-26-2010 at 05:33 AM. Reason: Added code tags

  2. #2
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,371
    Blog Entries
    1
    Rep Power
    20

  3. #3
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,315
    Blog Entries
    1
    Rep Power
    26

    Default

    Quote Originally Posted by dsohi1821 View Post
    I need Write a Program that reads two times in military format. The function of the program is print the number of hours and minutes between the two times.
    Example would be:
    Please enter the first time: 0900
    Please enter the second time: 1730
    Result should be: 8 hours 30 minutes

    The code must have two classes. Timeinterval class and ElapsedTimePrinter

    This is what I have so far:
    Java Code:
    import java.util.Scanner;
    
    
    public class ElapsedTImePrinter 
    {
    public static void main(String[] args)
    {
    Scanner s = new Scanner(System.in) ;
    TimeInterval t = new TimeInterval(time1, time2);
    
    System.out.println("Enter two times in military format, using 4 digits.");
    System.out.println("Please Enter time one Military Format:");
    int time1 = s.nextInt() ;
    System.out.println("Please Enter time two in Military Format:");
    int time2 = s.nextInt() ;
    
    System.out.println("hours:");
    System.out.println(t.getHours(time1, time2));
    System.out.println("minutes:");
    System.out.println(t.getMinutes(time1, time2));
    }
    }
    
    
    import java.lang.Math;
    public class TimeInterval
    
    {
    
    int time1 = scanner.nextInt() ;
    int time2 = scanner.nextInt() ;
    private int hr;
    private int min;
    
    int hrformula = ((time2 - time1)/100)-(((time2 - time1)/100) % 100);
    
    int minutes=((time2-time1)-hrformula);
    
    public int getHours(){
    return hrformula;
    }
    
    public int getMinutes(){
    return minutes;
    }
    }

    Oh come on now. You've copied that code out of this thread: Java, Military Format using "/" and "%" Operator!!

    And I already told you that the code was no good, to not use it, to not get ideas from it. To put it bluntly, that code is complete and utter rubbish. Please show us code that you have created, not that you've copied.

  4. #4
    HPcompaq256 is offline Member
    Join Date
    Feb 2010
    Posts
    12
    Rep Power
    0

    Default

    yes I'm getting few error such as:
    cannot find symbol variable class in Timeinterval.class
    it also says cannot find symbol time1 in ElapsedTimePrinter

  5. #5
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,371
    Blog Entries
    1
    Rep Power
    20

    Default

    Quote Originally Posted by dsohi1821 View Post
    yes I'm getting few error such as:
    cannot find symbol variable class in Timeinterval.class
    it also says cannot find symbol time1 in ElapsedTimePrinter
    Is that true, what Fubarable says? If so read that comments of him.

  6. #6
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,315
    Blog Entries
    1
    Rep Power
    26

    Default

    Quote Originally Posted by dsohi1821 View Post
    yes I'm getting few error such as:
    cannot find symbol variable class in Timeinterval.class
    it also says cannot find symbol time1 in ElapsedTimePrinter
    Again, scrap that code, it's worthless. Have you read what I posted in the previous thread and in this thread?

  7. #7
    HPcompaq256 is offline Member
    Join Date
    Feb 2010
    Posts
    12
    Rep Power
    0

    Default

    Ok this is my code. It has been modified. Also the code does compile but has an runtime error that the results never show up? I'm sure there are a plenty of errors in my code. I'm trying my best. I'm not trying to copy and paste someone else work. I'm trying my best to understand this stuff. Guys please help me out... I feel really frustrated at this moment.

    import java.util.Scanner;


    public class ElapsedTImePrinter
    {



    public static void main(String[] args)
    {

    Scanner s = new Scanner(System.in) ;
    int time1=s.nextInt();
    int time2=s.nextInt();

    TimeInterval a= new TimeInterval();

    System.out.println("Enter two times in military format, using 4 digits.");
    System.out.println("Please Enter time one Military Format:");

    System.out.println("Please Enter time two in Military Format:");







    System.out.println("hours:");
    System.out.println(a.getHours(time1, time2));
    System.out.println("minutes:");
    System.out.println(a.getMinutes(time1, time2));

    }
    }


    import java.lang.Math;
    public class TimeInterval

    {

    int time1=0;
    int time2=0;
    private int hr;
    private int min;




    int hrformula =(((time2-time1)/100)-((time2-time1)/100%100));

    int minutes=((time2-time1)-hrformula);


    public int getHours(int time1, int time2){

    return hrformula;
    }

    public int getMinutes(int time1, int time2 ){

    return minutes;
    }
    }

  8. #8
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,315
    Blog Entries
    1
    Rep Power
    26

    Default

    Quote Originally Posted by dsohi1821 View Post
    Ok this is my code. It has been modified. Also the code does compile but has an runtime error that the results never show up?
    What does the error state exactly, and what line causes the error?

    Also, please edit your post and add code tags so that the code is readable. Do this and more folks will be willing to read your code and help you, so it's a win-win situation, right?

    Good luck.

  9. #9
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,315
    Blog Entries
    1
    Rep Power
    26

    Default

    Quote Originally Posted by dsohi1821 View Post
    Ok this is my code. ... I'm trying my best. I'm not trying to copy and paste someone else work.
    Aw heck!! I've looked over your code and it's still mostly from that other guy's crap code. This is your code? Who's kidding who here? Most will gladly help when you're up front and honest, but now when you claim some code is yours and telling an outright lie.

    Good bye and luck, because it looks like you'll need it.

  10. #10
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,315
    Blog Entries
    1
    Rep Power
    26

    Default

    Quote Originally Posted by dsohi1821 View Post
    The program runs but nothing shows up. such as the output of the program or anything else. I'm using Bluej and its say the machine is executing. Any suggestions?
    Yes, be honest with us and with yourself. Scrap this entire program because it's worthless even if you don't believe me. Good night.

  11. #11
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,315
    Blog Entries
    1
    Rep Power
    26

    Default

    Quote Originally Posted by dsohi1821 View Post
    Ok this is my code. It has been modified. Also the code does compile but has an runtime error that the results never show up? I'm sure there are a plenty of errors in my code. I'm trying my best. I'm not trying to copy and paste someone else work. I'm trying my best to understand this stuff. Guys please help me out... I feel really frustrated at this moment.

    import java.util.Scanner;


    public class ElapsedTImePrinter
    {



    public static void main(String[] args)
    {

    Scanner s = new Scanner(System.in) ;
    int time1=s.nextInt();
    int time2=s.nextInt();

    TimeInterval a= new TimeInterval();

    System.out.println("Enter two times in military format, using 4 digits.");
    System.out.println("Please Enter time one Military Format:");

    System.out.println("Please Enter time two in Military Format:");







    System.out.println("hours:");
    System.out.println(a.getHours(time1, time2));
    System.out.println("minutes:");
    System.out.println(a.getMinutes(time1, time2));

    }
    }


    import java.lang.Math;
    public class TimeInterval

    {

    int time1=0;
    int time2=0;
    private int hr;
    private int min;




    int hrformula =(((time2-time1)/100)-((time2-time1)/100%100));

    int minutes=((time2-time1)-hrformula);


    public int getHours(int time1, int time2){

    return hrformula;
    }

    public int getMinutes(int time1, int time2 ){

    return minutes;
    }
    }
    Quoted for posterity.

Similar Threads

  1. Java, Military Format using "/" and "%" Operator!!
    By sk8rsam77 in forum New To Java
    Replies: 11
    Last Post: 02-26-2010, 04:03 AM
  2. Simple program involving military time
    By busdude in forum New To Java
    Replies: 4
    Last Post: 10-08-2008, 07:03 PM
  3. Struts 1.x <bean:write format="0.00%"> help?
    By prabhurangan in forum Web Frameworks
    Replies: 0
    Last Post: 07-02-2008, 01:59 PM
  4. How to write an image of a given format
    By Java Tip in forum java.awt
    Replies: 0
    Last Post: 06-25-2008, 11:30 AM
  5. Replies: 0
    Last Post: 11-06-2007, 03:20 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •