473,698 Members | 2,179 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Calling a method with a scanner parameter

2 New Member
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 RouteTotalOpera tionalTime(Scan ner 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 23586
Laharl
849 Recognized Expert Contributor
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.Scann er) and then you can pass it to the function.
Oct 5 '08 #2
CRGoose
2 New Member
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.Scann er) 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
9632
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 populate with a reference to the object that constructed this current object. i would attempt to accomplish this by setting the appropriate field from within the constructor... i figured it might be obtainable from the stack trace, but that...
2
1543
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
1695
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 stuff from one of the Symbol SDK examples, and using their .Net classes, drive the scanning engine in my application. Basically the program has a main screen which allows you to perform differing actions, all of which involved the scanner....
7
4980
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 Parameter. I can call the first Method without Problems, the Parameter can be deserialized by the WebService. But if I want to call the second Method and give it an Array of Parameters, then the following exception is thrown by the WebService:...
3
4067
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, when I try it in the vb.net web app, I run into XML definition errors. Looks like the proxy class is not able to generate the correct XML with the ref parameter. Here is error: The element 'urn:test-com:document:test:rfc:functions:T_RETURN has
15
1528
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 last name. import java.util.*; import java.io.PrintStream; import java.io.File; import java.io.FileNotFoundException; public class coursework4
3
3520
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 extend the superclass and a Temp class that extends the Hourly class. From what I've read, this shouldn't be happening, since the object in employees is a Salaried object. The input is a text file with every line being some piece of information, in the...
7
2683
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 name based on the name of the VB6 application. A second choice would be a file name based on the # COM interface assembly. I have tried calling Assembly.GetCallingAssembly() but this fails when I use the VB6 client. Is there a way to get this...
1
6493
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 help will be appriciated here is the code: import java.io.*; import java.util.Scanner; public class Polynomial extends UnorderedArrayList { Scanner sc = new Scanner(System.in); //Default constructor
0
8674
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8604
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9157
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9028
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8895
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
7728
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6518
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4619
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3046
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.