In: Computer Science
Error: Main method is not static in class ArrayReview, please
define the main method as:
public static void main(String[] args)
please help me fast:
import java.util. Random;
import java.util.Scanner;
//ArrayReview class
class ArrayReview
{
int array[];
//constructor
ArrayReview (int n)
{
array = new int[n];
//populating array
Random r = new Random();
for (int i=0;i<n; i++)
array[i] = r.nextInt ();
}
//getter method return integer at given index
int getElement (int i)
{
return array[i];
}
//method to set element at given index
void setElement(int i, int e)
{
array[i]=e;
}
public static void main(String argv[])
{
String s;
int n;
Scanner sc = new Scanner (System.in);
System.out.println("Enter the number of items: ");
n =sc.nextInt ();
//flush the buffer.
sc.nextLine();
while (n!=0)
{
System.out.println("Enter the colors detected in a single item:
");
s=sc.nextLine();
String b[] =s.split(" ");
int m= b.length;
int c=0;
// counting blues
for (int i=0; i< m; i++)
{
if (b[i].equals("blue"))
c++;
}
double p = ((double) c/m)* 100;
//if atleast 50%
if (50<=p)
System.out.println("Passed");
else
System.out.println("Failed");
n--;
}
}
}
Dear Student ,
As per the requirement submitted above , kindly find the below solution.
Here a new java program with name "ArrayReview.java" is created, which contains following code.
ArrayReview.java :
import java.util.Random;
import java.util.Scanner;
//ArrayReview class
public class ArrayReview {
int array[];
// constructor
ArrayReview(int n) {
array = new int[n];
// populating array
Random r = new Random();
for (int i = 0; i < n;
i++)
array[i] =
r.nextInt();
}
// getter method return integer at given
index
int getElement(int i) {
return array[i];
}
// method to set element at given index
void setElement(int i, int e) {
array[i] = e;
}
//entry point , main() method
public static void main(String[] args) {
String s;
int n;
//creating object of Scanner
class
Scanner sc = new
Scanner(System.in);
//asking user to enter
System.out.println("Enter the
number of items: ");
n = sc.nextInt();//reading int
// flush the buffer.
sc.nextLine();
while (n != 0) {
System.out.println("Enter the colors detected in a single item:
");
s =
sc.nextLine();
String b[] =
s.split(" ");
int m =
b.length;
int c = 0;
// counting
blues
for (int i = 0;
i < m; i++) {
if (b[i].equals("blue"))
c++;
}
double p =
((double) c / m) * 100;
// if atleast
50%
if (50 <=
p)
System.out.println("Passed");
else
System.out.println("Failed");
n--;
}
}
}
======================================================
Output : Compile and Run ArrayReview.java to get the screen as shown below
Screen 1 :ArrayReview.java
NOTE : PLEASE FEEL FREE TO PROVIDE FEEDBACK ABOUT THE SOLUTION.