could someone plz help.. i'm stuck in one part where u have to access the array form the main class(random) ive juss posted the two classes i have doubt in.. the question goes soemthin like this:
Q:Make a java class file for function that can do addition, then make a new java class file again for random numbers(which will allow your program to make random equations for addition).Make a new java class file for menu where the user decides what grade(from 1 to 6) they study in and if u type something wrong like a character or anything, the program shouldnt shut down but print out “invalid type again” and then the user decided how many equations they want to solve; 10, 20, 30 or 50 . Your math program should ask to answer the equations. In
Grade1,your program shoud only ask equations from numbers between 1-20.
Grade2 from numbers between 1-50.
Grade3 from numbers between 10-
50.
Grade4 from numbers between 10-
100
Grade5 from numbers between 50-
100
Grade 6 numbers from 100-500.
When the user types in the answer,your program should state wether the answer was correct or wrong.In the end, it should tell how many eqautions the user got correct and how many wrong.
import java.util.Random;
public class Main {
public static void main(String[] args) {
Random generator= new Random();
int num1 = generator.nextInt(20)+1;
int num2 = generator.nextInt(20)+1;
addition aObject=new addition ();
aObject.add( num1,num2);
}
}// this is the main class
import java.util.Scanner;
public class addition {
public void add(int num1, int num2){
Scanner input1=new Scanner(System.in);
int choice2=input1.nextInt();
switch(choice2){
case 10:
int read=0;
int[] numbers=new int [10];
for (int i=0;i<numbers.length; i++){
numbers[i]=generator.nextInt(10)+1;// this is the area of problem, the java gives error in recognizin 'generator.nextInt(10)+1' since random is in the other class.
System.out.println(" wat is"+ num1 +"*"+num2);
int answer=num1*num2;
int guess=input1.nextInt();
if(answer==guess){
System.out.println("you are right, the correct answer is "+ answer);
}
else{
System.out.println("you are wrong, the correct answer is "+ answer);
}
}
break;
}
}
}//this is another 'addition' class