1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

help confuse bout this java

Discussion in 'Java' started by eyeore, Oct 9, 2009.

  1. eyeore

    eyeore New Member

    Joined:
    Oct 9, 2009
    Messages:
    1
    Likes Received:
    0
    Trophy Points:
    0
    help please im really confuse about this problem its about computation about a telephone bill but my first variable keep messing up with my second variable which is my first variable is 2.50 dollars and my second is 2.00 dollars
    but when i tried my code started day 1 hours 00 min 30 end hours 1 min 30 its duration its 60 by bill is 150
    when i tried to do it again day 1started hours 06 min 30 end hours 07 min 30
    the same thing happen duration 60 and bill 150 the first hour 00 min 30 and end hour 1 min 30 should have suppose to be " duration 60 and bill 120 " please can anyone kindly me help me whats wrong with my variable i really dont know what do anymore

    Code:
    import java.util.Scanner;
    
    public class act8 {
    
        
        public static void main(String[] args) {
            Scanner input = new Scanner(System.in);
                
                int num;
                int startHrs;
                int endHrs;
                int duration;
                int startMin;
                int endMin;
                int bill;
                
                
                System.out.println("Enter Day");
                num = input.nextInt();
                
                if(num >= 5){
                    System.out.print("Call started hours");
                    startHrs = input.nextInt();
                    System.out.print("Minutes");
                    startMin = input.nextInt();
                    System.out.print("Call ended hours");
                    endHrs = input.nextInt();
                    System.out.print("Minutes");
                    endMin = input.nextInt();
                    if (startHrs >= 6 && endHrs >= 18){
                        startHrs = endHrs - startHrs;
                        duration = startHrs * 60 - startMin + endMin;
                        System.out.print("Duration "+ duration);
                        bill = (int) (duration * 2.50);
                        System.out.println("Bill"+ bill);
                        System.exit(0);
                        
                    if(num >=5)
                        if(startHrs <=24)
                         startHrs = endHrs - startHrs;
                         duration = startHrs * 60 - startMin + endMin;
                         System.out.print("Duration "+ duration);
                         bill = (int) (duration * 2.00);
                         System.out.println("Bill"+ bill);
                         System.exit(0);
                    
                         if(num <= 7){
                                System.out.print("Call started hours");
                                startHrs = input.nextInt();
                                System.out.print("Minutes");
                                startMin = input.nextInt();
                                System.out.print("Call ended hours");
                                endHrs = input.nextInt();
                                System.out.print("Minutes");
                                endMin = input.nextInt();
                                if (startHrs < 24){
                                    startHrs = endHrs - startHrs;
                                    duration = startHrs * 60 - startMin + endMin;
                                    System.out.print("Duration "+ duration);
                                    bill = (int) (duration * 1.50);
                                    System.out.println("Bill"+ bill);
                                    System.exit(0);
                                }
                         }
                    }
                }
        }
        
    }
     
    Last edited by a moderator: Oct 9, 2009

Share This Page