Hi,
I'm terribly new at java, i created a program for a poster availability system and there are 8 errors that I have no idea how to resolve. The program is meant only to run at the command prompt.
The errors are:
C:\Project\Enrol.java:46: cannot find symbol
symbol : method getID()
location: class Record
if(data.getID()!=0)
^
C:\Project\Enrol.java:93: cannot find symbol
symbol : method getID()
location: class Record
if(temp==database[count].getID()){
^
C:\Project\Enrol.java:134: cannot find symbol
symbol : constructor Record(java.lang.String,int,int)
location: class Record
database[size]=new Record(name,age,ID);
^
C:\Project\Enrol.java:141: cannot find symbol
symbol : method getAge()
location: class Record
System.out.println("Age: "+database[tgt].getAge());
^
C:\Project\Enrol.java:142: cannot find symbol
symbol : method getID()
location: class Record
System.out.println("ID: "+database[tgt].getID());
^
C:\Project\Enrol.java:157: cannot find symbol
symbol : method getID()
location: class Record
if(database[x].getID()==ID){
^
C:\Project\Enrol.java:214: cannot find symbol
symbol : method setAge(int)
location: class Record
database[tgt].setAge(age);
^
C:\Project\Enrol.java:221: cannot find symbol
symbol : method setID(int)
location: class Record
database[tgt].setID(ID);
^
8 errors
Tool completed with exit code 1
Enrol.java
import java.io.*;
import java.util.*;
import java.text.*;
public class Enrol{
private Record database[];
private int size;
private Record data;
private RandomAccessFile input;
private RandomAccessFile output;
//constructor
public Enrol(){
database=new Record[100];
size=0;
load();
}
//loading rom file to array
public void load(){
try{
input=new RandomAccessFile("members1.dat","r");
}catch(Exception e){
System.out.println("Error opening file");
System.exit(1);
}
readRecord();
try{
input.close();
}catch(IOException e){
System.out.println("Problem closing file");}
System.out.println("records loaded="+size);
}
//reading from file and filling the array.
public void readRecord(){
try{
long fp=0;
size=input.readInt();
for (int count=0;count<=size;count++){
fp=input.getFilePointer();
input.seek(((long)count*Record.size())+4);
data=new Record();
data.read(input);
if(data.getID()!=0)
database[count]=data;
}
}catch (EOFException eof){
System.out.println("End of File");
}catch(IOException e){
System.out.println("Error reading file");
System.exit(1);
}
}
//writing the array to the file
public void writeRecord(){
try{
output.writeInt(size);
for (int count=0;count<size;count++){
output.seek(((long)count*Record.size())+4);
database[count].write(output);
}
}catch(IOException e){
System.out.println("Error!");
System.exit(1);
}
}
public int menu() throws Exception{
BufferedReader userInput=new BufferedReader (new InputStreamReader(System.in));
System.out.println("\n\n\n\t**************Homecare Inc************");
System.out.println("\t\t*******Main Menu*********");
System.out.println("\t\t*************************");
System.out.println("\n");
System.out.println("\t1) Enter Member's Records");
System.out.println("\t2) Delete Member's Records");
System.out.println("\t3) Search Member's Records");
System.out.println("\t4) Display Member's Records");
System.out.println("\t5) Modify Member's Records");
System.out.println("\t6) Exit");
System.out.println("\n\n");
System.out.print("\tPlease make a choice(1-6) :");
String input=userInput.readLine();
return Integer.parseInt(input);
}
//validation for ID
public boolean isNotDuplicate(int temp){
for(int count=0;count<size;count++)
if(temp==database[count].getID()){
System.out.println("ID alrady in Use!");
return true;
}
return false;
}
public void AddRecord() throws Exception{
BufferedReader userInput=new BufferedReader(new InputStreamReader(System.in));
String name;
int age;
int ID;
do{
System.out.println("Enter ID: ");
ID=Integer.parseInt(userInput.readLine());
}
while(isNotDuplicate(ID));
do{
System.out.println("Enter Name: ");
name=userInput.readLine();
if (name.length()>20)
System.out.println("Name exceed 20 characters!!!");
}while(name.length()>20);
do{
System.out.println("Enter Age: ");
age=Integer.parseInt(userInput.readLine());
if (age<0 || age >100)
System.out.println("Age exceed limit!!!");
}while((age<0) || (age>100));
database[size]=new Record(name,age,ID);
size++;
}
public void display(int tgt){
System.out.println("\nName: "+database[tgt].getName());
System.out.println("Age: "+database[tgt].getAge());
System.out.println("ID: "+database[tgt].getID());
}
public int SearchRecord() throws Exception{
BufferedReader userInput=new BufferedReader(new InputStreamReader(System.in));
int tgt=0;
int x;
System.out.println("\nEnter ID: ");
int ID=Integer.parseInt(userInput.readLine());
for (x=0; x<size; x++)
if(database[x].getID()==ID){
display(x);
return x;
}
if(x==size)
{
System.out.println("Not Found!");
}
return -1;
}
public void DeleteRecord() throws Exception{
BufferedReader userInput=new BufferedReader(new InputStreamReader(System.in));
int tgt=0;
int x=0;
try{
tgt=SearchRecord();
}catch(Exception e){}
if(tgt!=-1){
System.out.println("Deletion Confirmation");
String reply=userInput.readLine();
if (reply.equals("y"))
{for (x=tgt; x<size; x++)
database[x]=database[x+1];
size=size-1;
System.out.println("Record Deleted");}
}
}
public void DisplayRecords(){
for(int count=0; count<size; count++)
display(count);
System.out.println("\n");
}
public void ModifyRecord() throws Exception{
BufferedReader userInput=new BufferedReader(new InputStreamReader(System.in));
String reply="";
int tgt=0;
try{
tgt=SearchRecord();
}catch(Exception e){}
if(tgt!=-1){
System.out.println("\nModify Name?");
reply=userInput.readLine();
if(reply.equals("y")){
String name=userInput.readLine();
database[tgt].setName(name);
}
System.out.println("\nModify Age?");
reply=userInput.readLine();
if(reply.equals("y")){
int age=Integer.parseInt(userInput.readLine());
database[tgt].setAge(age);
}
System.out.println("\nModify ID?");
reply=userInput.readLine();
if(reply.equals("y")){
int ID=Integer.parseInt(userInput.readLine());
database[tgt].setID(ID);
}
System.out.println("Record Updated");
}
}
public void Exit(){
try{
output=new RandomAccessFile("members1.dat","rw");
}catch(IOException e){
System.out.println("Error in Opening File");
System.exit(1);
}
writeRecord();
try{
output.close();
}catch(IOException e){
System.out.println("Problem Closing File");}
}
public void process (int count){
switch(count){
case 1:try{
AddRecord();
}catch(Exception e){}
break;
case 2:try{
DeleteRecord();
}catch(Exception e){}
break;
case 3:try{
SearchRecord();
}catch(Exception e){}
break;
case 4:try{
DisplayRecords();
}catch(Exception e){}
break;
case 5:try{
ModifyRecord();
}catch(Exception e){}
break;
case 6:Exit();
break;
default:System.out.println("\nPlease Enter choice from 1 to 6");
}
}
public static void main(String args[]){
Enrol data=new Enrol();
int count=0;
do{
try{count=data.menu();
}catch(Exception e){}
data.process(count);
}while(count!=6);
}
}
Record.java
import java.io.*;
import java.util.*;
import java.text.*;
public class Record
{
private String name, qty, size, price, details, arrival;
public Record(String name, String qty, String size, String price, String details, String arrival)
{
this.name=name;
this.arrival=arrival;
this.size=size;
this.price=price;
this.details=details;
this.arrival=arrival;
}
public Record(){}
public void read(RandomAccessFile file)throws IOException
{
char namearray[]=new char[100];
for(int x=0; x<30; x++)
namearray[x]=file.readChar();
name=new String(namearray);
char qtyarray[]=new char[9];
for(int x=0; x<9; x++)
qtyarray[x]=file.readChar();
qty=new String(qtyarray);
char sizearray[]=new char[50];
for(int x=0; x<50; x++)
sizearray[x]=file.readChar();
size=new String(sizearray);
char pricearray[]=new char[6];
for(int x=0; x<6; x++)
pricearray[x]=file.readChar();
price=new String(pricearray);
char detailsarray[]=new char[200];
for(int x=0; x<200; x++)
detailsarray[x]=file.readChar();
char arrivalarray[]=new char[12];
for(int x=0; x<12; x++)
arrivalarray[x]=file.readChar();
arrival=new String(arrivalarray);
}
public void write(RandomAccessFile file)throws IOException
{
StringBuffer namebuffer, qtybuffer, sizebuffer, pricebuffer, detailsbuffer, arrivalbuffer;
if(name!=null)
namebuffer=new StringBuffer(name);
else
namebuffer=new StringBuffer(100);
namebuffer.setLength(100);
file.writeChars(namebuffer.toString());
if(qty!=null)
qtybuffer=new StringBuffer(qty);
else
qtybuffer=new StringBuffer(9);
qtybuffer.setLength(9);
file.writeChars(qtybuffer.toString());
if(size!=null)
sizebuffer=new StringBuffer(size);
else
sizebuffer=new StringBuffer(50);
sizebuffer.setLength(50);
file.writeChars(sizebuffer.toString());
if(price!=null)
pricebuffer=new StringBuffer(price);
else
pricebuffer=new StringBuffer(6);
pricebuffer.setLength(6);
file.writeChars(pricebuffer.toString());
if(details!=null)
detailsbuffer=new StringBuffer(details);
else
detailsbuffer=new StringBuffer(200);
detailsbuffer.setLength(200);
file.writeChars(detailsbuffer.toString());
if(arrival!=null)
arrivalbuffer=new StringBuffer(arrival);
else
arrivalbuffer=new StringBuffer(12);
arrivalbuffer.setLength(12);
file.writeChars(arrivalbuffer.toString());
}
public void setName(String sname)
{
this.name=sname;
}
public String getName()
{
return name;
}
public void setQty(String sqty)
{
this.qty=sqty;
}
public String getQty()
{
return qty;
}
public void setSize(String ssize)
{
this.size=ssize;
}
public String getSize()
{
return size;
}
public void setPrice(String sprice)
{
this.price=sprice;
}
public String getPrice()
{
return price;
}
public void setDetails(String sdetails)
{
this.details=sdetails;
}
public String getDetails()
{
return details;
}
public void setArrival(String sarrival)
{
this.arrival=sarrival;
}
public String getArrival()
{
return arrival;
}
public static long size()
{
return 1000;
}
}
Create.java
import java.io.*;
import java.util.*;
import java.text.*;
public class Create{
private Record blank;
private RandomAccessFile file;
public Create() {
blank=new Record();
int count;
try{
file=new RandomAccessFile("members1.dat","rw");
for (count=0; count<100; count++)
blank.write(file);
}catch(IOException e){
System.out.println("Error Opening File");
System.exit(0);
}
}
public static void main (String args[]){
Create x=new Create();
}
}