Here is the code I created below. There is a problem that it does not recognize the choice statements or public static. What did I do wrong so I can compile?
import java.util.*;
public class Math
{
double d1, d2, d3, total, d4, d5, sum;
public static void output()
{
Scanner scannerObject = new Scanner(System. in);
System.out.prin tln("Let's add three whole numbers");
choice=scannerO bject.nextInt() ;
if(choice==1)
{
Math.addThreeWh ole();
}
if (choice==2)
{
Math.addTwoDeci mals();
}
else if ((choice<1)||(c hoice>2))
{
System.out.prin t("You must enter either 1 or 2.\n");
System.out.prin t("You will need to run the program again.\n\n");
}
}
public static void addThreeWhole()
{
Scanner scannerObject = new Scanner(System. in);
System.out.prin t("Enter whole number:");
d1 = scannerObject.n extDouble();
System.out.prin t("Enter whole number:");
d2 = scannerObject.n extDouble();
System.out.prin t("Enter whole number:");
d3 = scannerObject.n extDouble();
System.out.prin t("\n");
total = d1+d2+d3;
}
public static void addTwoDecimals( )
{
Scanner scannerObject = new Scanner(System. in);
System.out.prin t("Enter decimal point number:");
d4 = scannerObject.n extDouble();
System.out.prin t("Enter decimal point number:");
d5 = scannerObject.n extDouble();
sum = d4+d5;
}
}
import java.util.*;
public class Math
{
double d1, d2, d3, total, d4, d5, sum;
public static void output()
{
Scanner scannerObject = new Scanner(System. in);
System.out.prin tln("Let's add three whole numbers");
choice=scannerO bject.nextInt() ;
if(choice==1)
{
Math.addThreeWh ole();
}
if (choice==2)
{
Math.addTwoDeci mals();
}
else if ((choice<1)||(c hoice>2))
{
System.out.prin t("You must enter either 1 or 2.\n");
System.out.prin t("You will need to run the program again.\n\n");
}
}
public static void addThreeWhole()
{
Scanner scannerObject = new Scanner(System. in);
System.out.prin t("Enter whole number:");
d1 = scannerObject.n extDouble();
System.out.prin t("Enter whole number:");
d2 = scannerObject.n extDouble();
System.out.prin t("Enter whole number:");
d3 = scannerObject.n extDouble();
System.out.prin t("\n");
total = d1+d2+d3;
}
public static void addTwoDecimals( )
{
Scanner scannerObject = new Scanner(System. in);
System.out.prin t("Enter decimal point number:");
d4 = scannerObject.n extDouble();
System.out.prin t("Enter decimal point number:");
d5 = scannerObject.n extDouble();
sum = d4+d5;
}
}
Comment