import javax.swing.JOptionPane;
import java.io.*;
public class gym
{
public static void main (String [] args) throws IOException
{
int Counter=0;
member[] members = new members[45]; //you are creating and "OBJECT" member for another object "member"
//you must define a class that will accept this type of object creation "member"
//(e.g) <Classname> newObject = new <Classname>( );,
// or <Class> newObject = new Class( );
Controller(members, Counter);
}
public static void Controller(members[] values, int Counter) throws IOException
{
int Control=Integer.parseInt(JOptionPane.showInputDialog("MeNu\n" + "0 To Quit\n" + "1 to Add new employee" + "2 to Print the Employee" + "3 to Search\n"));
while (Control!=0)
{
if (Control==1)
{
for (int count=0; count<1; count++)
{
values[Counter] = new members( ); //you have a method "members( );" its an instance of a class you cannot create an instance for an instance
//or you cannot create an object for an object
String name=JOptionPane.showInputDialog("Name of member", "member");
int number=Integer.parseInt(JOptionPane.showInputDialog("gym number", "gym number"));
int postcode=Integer.parseInt(JOptionPane.showInputDialog("postcode","postcode"));
values[Counter]= new Database(name, number, postcode); //you dont have a class or a file that names Database
Counter++; //There is no Database Class that exist in your program or package
}
} // end of if 1
else if (Control==2)
{
for (int count=0; count<Counter; count++)
{
values[count].showValues();
}
}
else if (Control==3)
{
int DoSearch=Integer.parseInt(JOptionPane.showInputDialog("Searching\n" + "1 to Search member\n" + "2 to Search gym number\n" + "3 to Search postcode"));
if (DoSearch==1)
{
String nameSearching=JOptionPane.showInputDialog("Search Name of member", "Name of member");
int result=nameSearch(values, nameSearching , Control);
if (result==-5)
System.out.println("member That you Searched -> Not Found");
else
{
System.out.println(nameSearching + "\nis found in position\n" + (result+1));
values[result].showValues();
}
}
else if (DoSearch==2)
{
int numberSearching=Integer.parseInt(JOptionPane.showInputDialog("Searc h gym number", "Search gym number"));
int result=numberSearch(values, numberSearching , Control);
if (result==-5)
System.out.println("number That you Searched -> Not Found");
else
{
System.out.println(numberSearching + "\nis found in position\n" + (result+1));
values[result].showValues();
}
}
else if (DoSearch==3)
{
int postcodeSearching=Integer.parseInt(JOptionPane.showInputDialog("Search postcode", "Search postcode"));
int result = number(values, numberSearching , Control); //there is no variable numbersearching
if (result==-5)
System.out.println("postcode That you Searched -> Not Found");
else
{
System.out.println(postcodeSearching + "\nis found in position\n" + (result+1));
values[result].showValues();
}
}
}
Control=Integer.parseInt(JOptionPane.showInputDialog("MeNu\n" + "0 To Quit\n" + "1 to Add new member\n" + "2 to Print gym number\n" + "3 to Search postcode\n"));
}
}
public static int nameSearch(members[] values, String Thekey, int Size)
{
for (int y=0; y<Size; y++)
{
if (values[y].name.equals(Thekey))
{
return y;
}
}
return -5;
}
public static int numberSearch(members[] values, int Thekey, int Size)
{
for (int h=0; h<Size; h++)
{
if (values[h].number.equalsIgnoreCase(Thekey))
{
return h;
}
}
return -5;
}
public static int postcode(members[] values, int Thekey, int Size)
{
for (int r=0; r<Size; r++)
{
if (values[r].postcode==Thekey)
{
return r;
}
}
return -5;
}
}
//an outer class which must be used by the gym class, you have used the class name "gym" here,
//but you didnt notice that you already define this class name before.. your main program.
class TheGym //duplicated class.This is the name of your main class ,the top-level agent class where you are using the gym class ,this must class name must be changed
{
String name;
int number; //this was declared as int
int postcode;
String num;
public TheGym(String n, int nm, int p)
{
name=n;
number = nm;
postcode=p;
}
public String members( )
{
name="Edward Downing";
num ="12345"; //the method was asking for a return method, on the contrary you have 2 data types inside the method which is String and int
return name + number;
}
public int postCode( )
{
postcode=2009; //this data member was inside the method members( ); but this method doesnt have a return type so i put a String return type in it
//ive put a String because i notice that you have a string data members
return postcode;
}
public void showValues()
{
System.out.println("member " + " number " + " postcode ");
}
}