Results 1 to 5 of 5
- 03-07-2013, 10:53 PM #1
Member
- Join Date
- Mar 2013
- Posts
- 1
- Rep Power
- 0
Include a call in the main method
Hi,
I have created a program call 'Fruits' and have added another class call 'FruitOrder'.
How do I call a method by including a call in the main method?
Code for FruitOrder is:
public class FruitOrder {
private char fruitOrder;
private double weight;
private String message;
FruitOrder (char fruitCode, double weight) {
this.fruitCode = fruitCode;
this.weight = weight;
}
public String calculate() {
double price = 0;
String fruitType = "";
boolean isValidCode = true;
switch (friutCode) {
case 'A':
fruitType ="Apple";
price = weight * 1.75;
break;
case 'B':
fruitType ="Banana";
price = weight * 2.65;
break;
default:
isValidCode = false;
message = "iInvalid fruit cade entered";
break;
}
if (isValidCode) {
message = "You are buying " + weight + "Kgs of " + fruitType + " for $" + price;
}
return message;
}
}
This code is entered in the 'Fruits' class:
public static void case1() {
FruitOrder fo = new FruitOrder ('A', .5);
System.out.println ("case 1: " + "\n" + fo.calculate());
}
This is my question? how do I call this method by including a call in the main method as follow:
case1();
- 03-07-2013, 11:02 PM #2
Re: Include a call in the main method
To call a static method in a class use the classname dot the method name: ClassName.methodName();how do I call this methodIf you don't understand my response, don't ignore it, ask a question.
- 03-08-2013, 03:46 AM #3
Re: Include a call in the main method
Why do they call it rush hour when nothing moves? - Robin Williams
- 03-08-2013, 09:26 AM #4
Member
- Join Date
- Nov 2012
- Location
- India
- Posts
- 70
- Rep Power
- 0
Re: Include a call in the main method
Regards
Android developer at Trinay Technology Solutions,http://www.trinaytech.com,5705750475
- 03-08-2013, 09:38 AM #5
Moderator
- Join Date
- Apr 2009
- Posts
- 10,484
- Rep Power
- 16
Similar Threads
-
Call to main() twice ??
By Bgreen7887 in forum New To JavaReplies: 13Last Post: 07-19-2012, 04:41 AM -
Changing a code to include a main method
By Shlr in forum New To JavaReplies: 3Last Post: 04-23-2012, 04:33 PM -
how can main call other methods?
By rahuld.exe in forum New To JavaReplies: 1Last Post: 04-06-2012, 01:19 PM -
passing hashmap from a method and call it within main
By rajuchacha007 in forum New To JavaReplies: 2Last Post: 04-06-2010, 09:41 AM -
Call a main method from within a running program
By zoe in forum New To JavaReplies: 1Last Post: 08-07-2007, 06:16 AM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks