473,407 Members | 2,359 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,407 software developers and data experts.

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.  
Oct 5 '08 #1
2 23524
Laharl
849 Expert 512MB
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.
Oct 5 '08 #2
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
Oct 6 '08 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: Murat Tasan | last post by:
i have a quick question... is there a way to obtain the reference to the object which called the currently executing method? here is the scenario, i have a class and a field which i would like to...
2
by: Alexander Straschil | last post by:
Hello! I'm fooling around with a class wich can map cgi-parameters to function named parameter. I have a dic like dic = { 'action': 'myfunc', 'x': 1, 'y': 2,
0
by: Daniel Bass | last post by:
Symbol MC9000k scanner running Windows Mobile 2003. C# .Net (.Net CF) with OpenNetCf 1.2 installed. Latest Symbol SDK driving the scan engine stuff. I've extracted the barcode scanner handling...
7
by: Christian Wilhelm | last post by:
Hi! I'm trying to call a Java WebService out of a .net Client. There are two Methods, one Method requires one Parameter of type Parameter, the other Method requires one Parameter of type...
3
by: Pratcp | last post by:
Hello, I have an asp.net Web app in vb.net trying to call a C# web service which takes a reference parameter. I tried a simple C# web app to call the Web service and it works perfectly. However,...
15
by: djtosh | last post by:
hi there hoping someone can help me out with this. im designing a code that is a basic database holding peoples details and i need to implement a method that searches by txt for a record by their...
3
by: bassman2112 | last post by:
I'm having issues with calling a method defined in a subclass on a superclass object. This program is an exercise using inheritance, with an Employee superclass, Salaried and Hourly classes that...
7
by: =?Utf-8?B?UVNJRGV2ZWxvcGVy?= | last post by:
I have a C# logging assembly with a static constructor and methods that is called from another C# Assembly that is used as a COM interface for a VB6 Application. Ideally I need to build a file...
1
by: madman228 | last post by:
Hi guys I have run in to a littl bit of trouble. I am writing a class called polynomial in which i need a derivative method I have everything, just dont know how to start the derivative method. Any...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.