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.println("Let's add three whole numbers");
choice=scannerObject.nextInt();
if(choice==1)
{
Math.addThreeWhole();
}
if (choice==2)
{
Math.addTwoDecimals();
}
else if ((choice<1)||(choice>2))
{
System.out.print("You must enter either 1 or 2.\n");
System.out.print("You will need to run the program again.\n\n");
}
}
public static void addThreeWhole()
{
Scanner scannerObject = new Scanner(System.in);
System.out.print("Enter whole number:");
d1 = scannerObject.nextDouble();
System.out.print("Enter whole number:");
d2 = scannerObject.nextDouble();
System.out.print("Enter whole number:");
d3 = scannerObject.nextDouble();
System.out.print("\n");
total = d1+d2+d3;
}
public static void addTwoDecimals()
{
Scanner scannerObject = new Scanner(System.in);
System.out.print("Enter decimal point number:");
d4 = scannerObject.nextDouble();
System.out.print("Enter decimal point number:");
d5 = scannerObject.nextDouble();
sum = d4+d5;
}
}
7 1737
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.println("Let's add three whole numbers");
choice=scannerObject.nextInt();
if(choice==1)
{
Math.addThreeWhole();
}
if (choice==2)
{
Math.addTwoDecimals();
}
else if ((choice<1)||(choice>2))
{
System.out.print("You must enter either 1 or 2.\n");
System.out.print("You will need to run the program again.\n\n");
}
}
public static void addThreeWhole()
{
Scanner scannerObject = new Scanner(System.in);
System.out.print("Enter whole number:");
d1 = scannerObject.nextDouble();
System.out.print("Enter whole number:");
d2 = scannerObject.nextDouble();
System.out.print("Enter whole number:");
d3 = scannerObject.nextDouble();
System.out.print("\n");
total = d1+d2+d3;
}
public static void addTwoDecimals()
{
Scanner scannerObject = new Scanner(System.in);
System.out.print("Enter decimal point number:");
d4 = scannerObject.nextDouble();
System.out.print("Enter decimal point number:");
d5 = scannerObject.nextDouble();
sum = d4+d5;
}
}
where u define choice.....
listen one more thing ur static method can access only non-static data members
welcome ..... have a good day
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.println("Let's add three whole numbers");
choice=scannerObject.nextInt();
if(choice==1)
{
Math.addThreeWhole();
}
if (choice==2)
{
Math.addTwoDecimals();
}
else if ((choice<1)||(choice>2))
{
System.out.print("You must enter either 1 or 2.\n");
System.out.print("You will need to run the program again.\n\n");
}
}
public static void addThreeWhole()
{
Scanner scannerObject = new Scanner(System.in);
System.out.print("Enter whole number:");
d1 = scannerObject.nextDouble();
System.out.print("Enter whole number:");
d2 = scannerObject.nextDouble();
System.out.print("Enter whole number:");
d3 = scannerObject.nextDouble();
System.out.print("\n");
total = d1+d2+d3;
}
public static void addTwoDecimals()
{
Scanner scannerObject = new Scanner(System.in);
System.out.print("Enter decimal point number:");
d4 = scannerObject.nextDouble();
System.out.print("Enter decimal point number:");
d5 = scannerObject.nextDouble();
sum = d4+d5;
}
}
Please use code tags next time when posting code.
Where did you tell the compiler that choice is an int?
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.println("Let's add three whole numbers");
choice=scannerObject.nextInt();
if(choice==1)
{
Math.addThreeWhole();
}
if (choice==2)
{
Math.addTwoDecimals();
}
else if ((choice<1)||(choice>2))
{
System.out.print("You must enter either 1 or 2.\n");
System.out.print("You will need to run the program again.\n\n");
}
}
public static void addThreeWhole()
{
Scanner scannerObject = new Scanner(System.in);
System.out.print("Enter whole number:");
d1 = scannerObject.nextDouble();
System.out.print("Enter whole number:");
d2 = scannerObject.nextDouble();
System.out.print("Enter whole number:");
d3 = scannerObject.nextDouble();
System.out.print("\n");
total = d1+d2+d3;
}
public static void addTwoDecimals()
{
Scanner scannerObject = new Scanner(System.in);
System.out.print("Enter decimal point number:");
d4 = scannerObject.nextDouble();
System.out.print("Enter decimal point number:");
d5 = scannerObject.nextDouble();
sum = d4+d5;
}
}
Keep one problem in one thread please.
where u define choice.....
listen one more thing ur static method can access only non-static data members
welcome ..... have a good day
- import java.util.*;
-
public class Math
-
{
-
-
public static double addThreeWhole =0;
-
-
public static double addTwoDecimals =0;
-
-
public static double choice =0;
-
-
double d1, d2, d3, total;
-
public static void output()
-
-
{
-
-
-
Scanner scannerObject = new Scanner(System.in);
-
System.out.println("Let's add three whole numbers");
-
choice=scannerObject.nextDouble();
-
if(choice==1)
-
{
-
Math.addThreeWhole();
-
}
-
if (choice==2)
-
{
-
Math.addTwoDecimals();
-
}
-
else if ((choice<1)||(choice>2))
-
{
-
System.out.print("You must enter either 1 or 2.\n");
-
System.out.print("You will need to run the program again.\n\n");
-
}
-
}
-
public static void addThreeWhole()
-
{
-
Scanner scannerObject = new Scanner(System.in);
-
System.out.print("Enter whole number:");
-
d1 = scannerObject.nextDouble();
-
System.out.print("Enter whole number:");
-
d2 = scannerObject.nextDouble();
-
System.out.print("Enter whole number:");
-
d3 = scannerObject.nextDouble();
-
System.out.print("\n");
-
total = d1+d2+d3;
-
}
-
public static void addTwoDecimals()
-
{
-
double d4, d5, sum;
-
Scanner scannerObject = new Scanner(System.in);
-
System.out.print("Enter decimal point number:");
-
d4 = scannerObject.nextDouble();
-
System.out.print("Enter decimal point number:");
-
d5 = scannerObject.nextDouble();
-
sum = d4+d5;
-
}
-
}
-
-
This is my new version. It is telling me now that non static variable cannot be referenced to a static context?? What variable is that? What do I need to change? I'm lost? I've updated this though from the Choice.
- import java.util.*;
-
public class Math
-
{
-
-
public static double addThreeWhole =0;
-
-
public static double addTwoDecimals =0;
-
-
public static double choice =0;
-
-
double d1, d2, d3, total;
-
public static void output()
-
-
{
-
-
-
Scanner scannerObject = new Scanner(System.in);
-
System.out.println("Let's add three whole numbers");
-
choice=scannerObject.nextDouble();
-
if(choice==1)
-
{
-
Math.addThreeWhole();
-
}
-
if (choice==2)
-
{
-
Math.addTwoDecimals();
-
}
-
else if ((choice<1)||(choice>2))
-
{
-
System.out.print("You must enter either 1 or 2.\n");
-
System.out.print("You will need to run the program again.\n\n");
-
}
-
}
-
public static void addThreeWhole()
-
{
-
Scanner scannerObject = new Scanner(System.in);
-
System.out.print("Enter whole number:");
-
d1 = scannerObject.nextDouble();
-
System.out.print("Enter whole number:");
-
d2 = scannerObject.nextDouble();
-
System.out.print("Enter whole number:");
-
d3 = scannerObject.nextDouble();
-
System.out.print("\n");
-
total = d1+d2+d3;
-
}
-
public static void addTwoDecimals()
-
{
-
double d4, d5, sum;
-
Scanner scannerObject = new Scanner(System.in);
-
System.out.print("Enter decimal point number:");
-
d4 = scannerObject.nextDouble();
-
System.out.print("Enter decimal point number:");
-
d5 = scannerObject.nextDouble();
-
sum = d4+d5;
-
}
-
}
-
-
This is my new version. It is telling me now that non static variable cannot be referenced to a static context?? What variable is that? What do I need to change? I'm lost? I've updated this though from the Choice.
1.)Avoid naming classes with names of classes in the java API (especially from the java.lang package)
variables d1,d2, etc must be declared static as well if you want to access them in static methods.
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Rajesh |
last post by:
Hi,
I am using iplanet webserver 4.1. I want to call a java class from
ssjs file. But I am not getting the result. I have created a java class
file and put it in the folder...
|
by: acemann7 |
last post by:
Windows 2000
udb v 7.2
Got the latest fixpak 13
Applied it.
Still can't get a single java sp to run.
I used to get reason "2"... now reason "0" - reason 0 is not even
documented.
I point...
|
by: Miro |
last post by:
I've read a couple of threads on this error but none of them could help me so
I'm posting myself.
When I try open and read (not update) an ACCESS database on a network share
I occasionally get:...
|
by: satish mullapudi |
last post by:
Hi,
I am using DB2 v 8.2 & jdk 1.5.
I have created a java "Hello World" program. Now I want to bind that
program to SAMPLE database.
anybody plz help me out with the detailed process to do this....
|
by: =?Utf-8?B?S2Vubnk=?= |
last post by:
I have one bat file that contains a command to startup Java Program. Then, I
would like to create a cluster job to call the bat file. In case of one
computer is down, another computer can also call...
|
by: Begreen |
last post by:
Hi All,
I wrote a java program which outputs a xml file!
But I would prefer this program to insert the DTD code on the fly, in
the xml file when created!
I want the xml file to look like...
|
by: eyeofsoul |
last post by:
hello..i am having a difficulties in calling the function in other file.
for example..this is the file that use xxx.java;
package netbean5test;
import netbean5test.xxx;
import java.awt.*;...
|
by: jpr |
last post by:
I have 2 classes saved as 2 different java files.(eg- class ABC.java & PQR.java)
->ABC.java
classABC extends JTextField
{
ABC(int i)
{
super(i);
...
|
by: bsonline |
last post by:
I have to modify a .java file in a project. But I dont have any editor to compile java. I use putty to connect server(Solaris). And using putty console I modify .java file and save it. Then I down...
|
by: Faith0G |
last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
|
by: ryjfgjl |
last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
|
by: taylorcarr |
last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
|
by: aa123db |
last post by:
Variable and constants
Use var or let for variables and const fror constants.
Var foo ='bar';
Let foo ='bar';const baz ='bar';
Functions
function $name$ ($parameters$) {
}
...
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
| |