Hi everyone!
I need some help in my programme. I have an error message: "error: int cannot be dereferenced" at line 134. Could you help me solve this problem, as I do not know what it means? Many thanks.
/**
* @(#)PrizeCollection.java
*
* PrizeCollection application
*
* @author
* @version 1.00 2011/8/25
*/
import javax.swing.JOptionPane;
import java.lang.*;
import java.util.*;
public class PrizeCollection {
public static void main (String[]args) {
// Declare variables and arrays which will be used in the programme
String[] Description = new String [3];
String[] Color = new String [3];
int[] Value = new int [3];
//Call the Menu
optionMenu(Description,Color,Value);
}
//Method for the menu that will appear each time a task is completed
public static void optionMenu(String Description[], String Color[], int Value[]) {
int option = 0;
while (option!=1 || option!=2 || option!=3 || option!=4){
option = Integer.parseInt(JOptionPane.showInputDialog("Please choose an option: \n"
+ "1 - Enter the details of a prize \n"
+ "2 - Print the details stored for all prizes \n"
+ "3 - Search for a prize with a particular value or by description \n"
+ "4 - Quit"));
if (option==1)
enterDetails(Description,Color,Value);
if (option==2)
printDetails(Description,Color,Value);
if (option==3)
searchDetails(Description,Color,Value);
if (option==4)
System.exit(0);}
System.exit(0);
}
//Method to enter details for each prize
public static void enterDetails(String Description[], String Color[], int Value[]){
for (int i=0; i<3; i++){
Description [i] = JOptionPane.showInputDialog (null, "Please enter the description of the prize: ");
Color [i] = JOptionPane.showInputDialog (null, "Please enter the color of the prize: ");
Value[i] = Integer.parseInt(JOptionPane.showInputDialog(null, "Please enter the value of the prize: "));
}
optionMenu(Description,Color,Value);
}
// Method to search prizes
public static void searchDetails(String Description[], String Color[], int Value[]) {
// A Menu if needed to choose between search by description or by value
int choice = 0;
while (choice!=1 || choice!=2 || choice!=3){
choice = Integer.parseInt(JOptionPane.showInputDialog("Please choose an option: \n"
+ "1 - Search prize by description \n"
+ "2 - Search prize by value \n"
+ "3 - Return to the previous menu"));
if (choice==1)
searchDescription(Description,Color,Value);
if (choice==2)
searchValue(Description,Color,Value);
if (choice==3)
optionMenu(Description,Color,Value);}
System.exit(0);
}
//Method to search by description
public static void searchDescription(String Description[], String Color[], int Value[]){
String search_a_description = JOptionPane.showInputDialog("Please enter the name of the prize you want to search for");
boolean if_a_description_is_found = false; // the boolean is initialize from false
//loop start here
for (int a=0; a<Description.length; a++) // counter start from 0, the length does match a vehicle in the list and is less than i, then boolean is true and program continues
{
if (Description[a].equals (search_a_description)) // .equals compare 2 objects if prize type entered by user is matching of one the prize in the list then the boolean is true and program should continue
{
System.out.println("Successful search! A prize is found");
System.out.println("The prize is: " + Description[a] + "\t\t Color: " + Color[a] + "\t\t Value: " + Value[a]);
if_a_description_is_found = true; // then is this case the program will go to the next step
}
} // loop end here
if (if_a_description_is_found == false)// boolean are true or false, in this case if the program cannot find the prize in the list then it should do the following
System.out.println("No prize has been found!");
optionMenu(Description,Color,Value);
}
//Method to search by value
public static void searchValue(String Description[], String Color[], int Value[]){
String search_a_value = JOptionPane.showInputDialog("Please enter the name of the prize you want to search for");
boolean if_a_value_is_found = false; // the boolean is initialize from false
//loop start here
for (int b=0; b<Value.length; b++) // counter start from 0, the length does match a prize in the list and is less than i, then boolean is true and program continues
{
if (Value[b].equals (search_a_value)) // .equals compare 2 objects if prize type entered by user is matching of one the prize in the list then the boolean is true and program should continue
{
System.out.println("Successful search! A prize is found");
System.out.println("The prize is: " + Description[b] + "\t\t Color: " + Color[b] + "\t\t Value: " + Value[b]);
if_a_value_is_found = true; // then is this case the program will go to the next step
}
} // loop end here
if (if_a_value_is_found == false)// boolean are true or false, in this case if the program cannot find the prize in the list then it should do the following
System.out.println("No prize has been found!");
optionMenu(Description,Color,Value);
}
// Method to show the list of prizes
public static void printDetails(String Description[], String Color[], int Value[])
{
for (int i=0; i<Description.length; i++) // counter start from 0, i shouldn't be less than any prize length value, counter =+1
//.length return the length of the string type as an integer value
{
System.out.println("Description: " + Description[i] + "\t\t Color: " + Color[i] + "\t\t Value: " + Value[i]);
// will print the list
} // end of loop
optionMenu(Description,Color,Value);
} // end of method
//method to exit the program
public static void Exit()
{
System.exit(0);
}
} //end the program