Reputation: 69
here are my 3 classes: which are the main method, dog class and getFee class.
Main method
package test;
import java.util.Scanner;
import pets.Dog;
import Utilities.FeeCalculator;
public class TestKennel
{
public static void main(String[] args)
{
Scanner input = new Scanner(System.in);
Dog dog = new Dog();
System.out.println("Hello " + dog.name + ", who's a good dog?");
dog.talk();
FeeCalculator getFeeStatment = new FeeCalculator();
getFeeStatement.getFee();
input.close();
}
}
Dog Class
package pets;
public class Dog
{
public String name = "Fido";
public byte age = 10;
public void talk()
{
System.out.println("Woof Woof Woof!!!");
System.out.println("I am " + age * 7 + " the equivalent of human years old.");
}
}
and finally the getFee Class
package Utilities;
import pets.Dog;
import java.util.Scanner;
public class FeeCalculator
{
double dailyRate;
public String getFee(Dog dog, Scanner input)
{
System.out.println();
System.out.println();
System.out.println("What is the name of your pet?");
dog.name = input.next();
System.out.println("Input how many days your pet will be staying.");
int numberOfDays = input.nextInt();
String feeStatement = "The cost for boarding "
+ dog.name
+ " for "
+ numberOfDays
+ " days is $" + numberOfDays * dailyRate;
return feeStatement;
}
}
at the main method part, why is eclipse giving me an error? isn't this how i call a method?:
FeeCalculator getFeeStatment = new FeeCalculator();
getFeeStatement.getFee();
help will be really appreciated!
Upvotes: 1
Views: 4595
Reputation: 2323
Either Add Parameters for the method getFee();
in TestKennel class or implement the getFee();
method in FeeCalculator Class without parameters!
Upvotes: 0
Reputation: 1567
It would be helpful if you provided the error that eclipse is throwing. For instance one reason you're getting an error is probably because of spelling mistakes. Check your Initialization parameters or not passing parameters, but I suspect the former. You have:
FeeCalculator getFeeStatment = new FeeCalculator();
getFeeStatement.getFee();
Now, the variables getFeeStatment
is different from getFeeStatement
, check the spellings. Another one is you do not have parameters in your method call. The method signature shows you expect two parameters. You need to pass the two parameters for it to work.
P.S. Also desist from using capitalization in your package names. It's a Java conventation to use lower case for package names.
Upvotes: 0
Reputation: 26067
FeeCalculator
class has method getFee()
with two arguments.
public String getFee(Dog dog, Scanner input){}
you need to pass the arguments in order to invoke it.
change
getFeeStatement.getFee();
to
getFeeStatement.getFee(dog,input );
also variable names are different, FeeCalculator getFeeStatment = new FeeCalculator();
and getFeeStatement.getFee(dog, input);
. Spelling mistake for getFeeStatment
Upvotes: 2
Reputation: 1982
Since the prototype is
public String getFee(Dog dog, Scanner input)
your call getFeeStatement.getFee();
requires two arguments, one of Dog
type and the other of Scanner
type.
As per your code I think what you need to pass is getFeeStatement.getFee(dog, input);
Also if you require to save the value that you're getting from this function, remember to assign this statement to a String
variable. Hope this helps.
Upvotes: 0
Reputation: 102
getFee(dog,input);
--> Returns a String so do someting with it :-)
For example:
String s = getFeeStatement.getFee(dog, input); System.out.println(s);
Upvotes: 0
Reputation: 8657
you have to pass the method arguments like:
getFeeStatement.getFee(dog, input);
Upvotes: 0