Here's the code for "test":
Expand|Select|Wrap|Line Numbers
- import java.util.Scanner;
- public class test
- {
- private double amt;
- Scanner input = new Scanner( System.in);
- public void setAmt()
- {
- System.out.println("Input number: "); //User imputs number here
- double wagerAmt = input.nextDouble();
- amt = wagerAmt; //Assigns wagerAmt to amt
- }
- public double getAmt()
- {
- return amt;
- }
- }
Expand|Select|Wrap|Line Numbers
- import java.util.Scanner;
- public class test2
- {
- public void printNum()
- {
- test a = new test();
- System.out.println(a.getAmt()); //Prints amt from file "test"
- }
- public static void main(String args[])
- {
- test a = new test();
- a.setAmt(); //calls method setAmt() from file "test"
- test2 b = new test2();
- b.wagerNum(); //calls method printNum() from above method, although this does not function properly.
- }
- }
OUTPUT:
Input number: //Prompt to input number
2 //The value of amt in file "test"
0.0 //The value of amt in file "test2"
Press any key to continue . . .
In other words, I would like the value of amt in test one to be the same as the one in test2. I am relatively new to Java and I am sorry if I bother anyone with something that "should" be incredibly obvious. Any suggestions would be greatly appreciated. Thank you.