Connecting Tech Pros Worldwide Help | Site Map
Reply
 
LinkBack Thread Tools Search this Thread
  #1  
Old October 5th, 2008, 11:31 PM
Newbie
 
Join Date: Oct 2008
Posts: 2
Default Calling a method with a scanner parameter

For my class i have to write a program that has a method to combine integer time input values into a single double value, return that to a method that sums the values, then return that to a main. The method names i have written have to be exactly as they are shown, and i cannot for the life of me figure out how to call the "public static double RouteTotalOperationalTime(Scanner input)" method into my main. If someone can explain to me how to call the method that would be great, thanks.
Expand|Select|Wrap|Line Numbers
  1. import java.util.*;
  2. public class Testpage
  3. {
  4.     public static void main (String [] args)
  5.     {
  6.         /*
  7.         want to call RouteTotalOperationalTime here and define it as variable name duration1
  8.         */
  9.         double duration1 = RouteTotalOperationalTime();
  10.         System.out.println("Duration is: " + duration1);
  11.     }
  12.     public static double RouteTotalOperationalTime(Scanner input)
  13.     {
  14.         System.out.println("How many runs?");
  15.         int runs = input.nextInt();
  16.         double duration = 0;
  17.         for(int i=0; i<runs; i++)
  18.         {
  19.             System.out.println("How many hours?");
  20.             int hours = input.nextInt();
  21.             System.out.println("How many minutes?");
  22.             int minutes = input.nextInt();
  23.             double time = convertHoursMinutesToDouble(hours, minutes);
  24.             duration += time+.5;
  25.         }
  26.         return duration;
  27.     }
  28.     public static double convertHoursMinutesToDouble(int hours, int minutes)
  29.     {
  30.         double Hours = hours/1.0;
  31.         double Minutes = minutes/60.0;
  32.         double sum = Hours+Minutes;
  33.         return sum;
  34.     }
  35. }
  36.  
  37. /*
  38. The Error:
  39.  
  40. Testpage.java:7: RouteTotalOperationalTime(java.util.Scanner) in Testpage cannot
  41.  be applied to ()
  42.                 double duration1 = RouteTotalOperationalTime();
  43.                                    ^
  44. 1 error
  45. */
  46.  
Reply
  #2  
Old October 6th, 2008, 12:36 AM
Expert
 
Join Date: Sep 2007
Posts: 853
Default

It means you have to pass the method a Scanner object. Thus, you have to create a Scanner first (don't forget to import java.util.Scanner) and then you can pass it to the function.
Reply
  #3  
Old October 6th, 2008, 01:01 AM
Newbie
 
Join Date: Oct 2008
Posts: 2
Default

Quote:
Originally Posted by Laharl
It means you have to pass the method a Scanner object. Thus, you have to create a Scanner first (don't forget to import java.util.Scanner) and then you can pass it to the function.
thanks a bunch gah i can't believe i missed that, believe it or not ive spent about 3 hours going over that, :-) compiles nice and smooth now ty again
Reply
Reply

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Popular Articles

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over 205,248 network members.