Creating a new class and dont know how to generate a random number math code

• September 15th, 2011, 02:14 PM
beatlebaby70
Creating a new class and dont know how to generate a random number math code

I am creating a new class the calculates random integers in simplistic mathematical operations for school. Bellow I have copy/paste my code from JGRASP, I have commented on the two portions that are not performing correctly. The first error message in correlation to the first portion that I commented on as being a mistake states the following:

PrintingIntCalculator.java:4: error: illegal start of type
import java.until.Random;
^
PrintingIntCalculator.java:4: error: ';' expected
import java.until.Random;
^
PrintingIntCalculator.java:4: error: illegal start of type
import java.until.Random;
^
PrintingIntCalculator.java:4: error: ';' expected
import java.until.Random;
^
PrintingIntCalculator.java:4: error: <identifier> expected
import java.until.Random;
^
The second portion in which I commented on (at the end of my code) states the following error message:

PrintingIntCalculator.java:34: error: ';' expected
total = ran.nextInt(b-a+1)+a)
^
Both of these are suppose to tell the class that it needs to generate a random number. Could someone please help me correct these problems. It is greatly appreciated.
Thank you so much in advance

public class PrintingIntCalculator {

//This part is wrong:
import java.until.Random;

public PrintingIntCalculator(){}

private int total = 0;
private int a = 0;
private int b = 0;

public int add(int a, int b){
total = a + b;
return (total);
}
public int subtract(int a, int b){
total = a - b;
return (total);
}
public int multiply(int a, int b){
total = a * b;
return (total);
}
public int divide(int a, int b){
total = a / b;
return (total);
}
public int remainder(int a, int b){
total = a % b;
return (total);
}

//This part is wrong:

public int random(int a, int b){
Random ran = new Random ();
total = ran.nextInt(b-a+1)+a)
return (total);
}
}
• September 15th, 2011, 02:18 PM
KevinWorkman
Re: Creating a new class and dont know how to generate a random number math code
Missing semicolon?
• September 15th, 2011, 02:21 PM
copeg
Re: Creating a new class and dont know how to generate a random number math code
2 Suggestions. First, suggest the following link for reading up on how to use import statement, especially the part that discusses where to place them
Using Package Members (The Java™ Tutorials > Learning the Java Language > Packages)
Second, make sure your lines/code statements end in semicolons - the compiler error point you to the exact line where this happens.
• September 15th, 2011, 02:39 PM
KevinWorkman
Re: Creating a new class and dont know how to generate a random number math code
Extra parenthesis?
• September 15th, 2011, 03:03 PM
Norm
Re: Creating a new class and dont know how to generate a random number math code
What are on the first three lines of your source?
The error message refers to an import statement on line 4.