What you need is a main method. It is an entry point
public static void main(String[] args) {
//Your code here
}
in your case it can look like:
package feetToInches2;
public class Feet2Inches {
public double feetToInches_ (double feet) {
return 12* feet;
}
public int max(int val1, int val2) {
if (val1 > val2) {
return (val1);
}
else {
return (val2);
}
}
public static void main(String[] args) {
Feet2Inches converter=new Feet2Inches();
int max = converter.max(100,50);
double inches = converter.feetToInches_(10.5);
System.out.println("Max value = " + max);
System.out.println("Inches = " + inches);
}
}
i've changed your method modifiers so it would be more usefull. Class with no public method is unneeded class ;) I also fixed some of errors in your code.
EDIT:
If you want to allow people to youse your code to their own calculation you have two choises. You can take parameters from args
array which holds parameters that was program runned with. or you can prompt for a data at the runtime.
1 Using parameters
public static void main(String[] args) {
Feet2Inches converter = new Feet2Inches();
if (args.length != 3) {
System.err.println("Missing arguments! give me three numbers");
System.exit(1);//error exit
}
int val1 = Integer.valueOf(args[0]);
int val2 = Integer.valueOf(args[1]);
double val3 = Double.valueOf(args[1]);
int max = converter.max(val1, val2);
double inches = converter.feetToInches_(val3);
System.out.println("Max value from (" + val1 + "," + val2 + ")= " + max);
System.out.println(val3 + "Feet = " + inches + " inches");
}
now you have to call your program with arguments Here you can see how to do it from cmd and Here is how to do it in Eclipse
2 ask user for parameters at runtime
public static void main(String[] args) {
Feet2Inches converter = new Feet2Inches();
Scanner input = new Scanner(System.in);
System.out.print("Argument 1:");
int val1 = input.nextInt();
System.out.print("Argument 2:");
int val2 = input.nextInt();
System.out.print("Argument 3:");
double val3 = input.nextDouble();
int max = converter.max(val1, val2);
double inches = converter.feetToInches_(val3);
System.out.println("Max value from (" + val1 + "," + val2 + ")= " + max);
System.out.println(val3 + "Feet = " + inches + " inches");
}