• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

cannot resolve symbol error

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi everybody,
i have written one hava program.i am getting so many errors but all are "cannot resolve symbol" i am sending my code.can anyone help me solve this...i will be very greatful to u....
class Directory {
/*********************** MENU CONTROLLER ************************/
public static void main (String[] args) throws Exception {
// declare variables & object
boolean toRepeat;
char option, subOption, searchOption;
EntryController EC = new EntryController();
// display main menu
do {
option = '0'; // Initialise option
Main.displayMenu(option);
option = getUserOption('1', '3');
// display sub menu
subOption = '0'; // Initialise subOption
while (option != '3' && subOption != '6') {
Main.displayMenu(option);
subOption = getUserOption('1', '6');
switch(subOption) {
case '1': // New entry
do{
EC.addEntry(option);
System.out.print
("\tEntry saved. Add another (Y/N) > ");
toRepeat = getAnswer();
} while (toRepeat);
break;
case '2': // Edit entry
do{
EC.editEntry(option);
System.out.print("\tEdit another (Y/N) > ");
toRepeat = getAnswer();
} while (toRepeat);
break;
case '3': // Delete entry
do{
EC.deleteEntry(option);
System.out.print("\tDelete another (Y/N) > ");
toRepeat = getAnswer();
} while (toRepeat);
break;

case '4': // Search entry
do {
Main.displaySearchMenu(option);
searchOption = getUserOption('1', '4');
if (searchOption == '4')
toRepeat = false;
else {
EC.searchEntry(option, searchOption);
System.out.print
("\tEnd of search. Search another (Y/N) > ");
toRepeat = getAnswer();
}
} while (toRepeat);
break;
case '5': // Display all entries
do{
if (option =='1') System.out.println
("\n\n\t***** Friends: Display All Entries *****");
else System.out.println
("\n\n\t**** Business: Display All Entries *****");
EC.displayAllEntry(option);
System.out.print
("\tEnd of record. Display again (Y/N) > ");
toRepeat = getAnswer();
} while (toRepeat);
break;
default: // Return to main menu
break;
} // End switch
} // End while
} while (option != '3');
} // End main() method

/******************** GET USER TO INPUT OPTION ********************/
public static char getUserOption(char min, char max)
throws Exception {
// Get input from user
char option = (char)System.in.read();
System.in.read(); System.in.read(); // Clear buffer
// Test whether input is within acceptable range
while (option < min || option > max) {
System.out.print("\tlnvalid option! Try again > ");
option = (char)System.in.read();
System.in.read(); System.in.read(); // Clear buffer
}
return option;
} // End getUserOption() method

/******************* ANSWER YES OR NO ******************/
public static boolean getAnswer() throws Exception {
// Receive input from user
char answer = (char)System.in.read();
// Test whether input is acceptable
while (answer != 'Y' && answer !='y' &&
answer != 'N' && answer != 'n') {
System.in.read(); System.in.read(); // Clear buffer
System.out.print("\tEntry must be Y or N > ");
answer = (char)System.in.read();
}
System.in.read();System.in.read(); // Clear buffer
// Return result
if (answer == 'Y' || answer == 'y') return true;
else return false;
} // End getAnswer() method
} // End Directory class
/*****************MAIN CLASS TO DISPLAY ALL MENUS *******************/
class Main {
/****************** DISPLAY MAIN MENU & SUB MENU ******************/
public static void displayMenu(char option) {
switch(option) {
case '0': // Display Main Menu
System.out.println("\n\n");
System.out.println("\n<<<<< ELECTRONIC DIRECTORY SYSTEM >>>\n");
System.out.println("\t*** MAIN MENU ***\n");
displayMainMenu();
break;
case '1': // Display Friend Menu
System.out.println("\n \n");
System.out.println("\t***** Friends *****\n");
displaySubMenu();
break;
case '2': // Display Business Menu
System.out.println("\n \n");
System.out.println("\t***** Business *****\n");
displaySubMenu();
break;
} // End switch
} // End displayMenu() method

/**************** DISPLAY DETAILS OF MAIN MENU *******************/
public static void displayMainMenu() {
System.out.println("\t1. Friends");
System.out.println("\t2. Business");
System.out.println("\t3. Exit\n");
System.out.print("\tOption > ");
} // End displayMainMenu() method

/**************** DISPLAY DETAILS OF SUB MENU ******************/
public static void displaySubMenu() {
System.out.println("\t1. New Entry");
System.out.println("\t2. Edit Entry");
System.out.println("\t3. Delete Entry");
System.out.println("\t4. Search Entry");
System.out.println("\t5. Display All Entries");
System.out.println("\t6. Main\n");
System.out.print("\tOption > ");

} // End subMenu() method
/********************** DISPLAY EDIT MENU *************************/
public static void displayEditMenu(char listCategory) {
// Display heading
if (listCategory =='1')
System.out.println("\n\n\t*** Friends: Edit Entry ***\n");
else
System.out.println("\n\n\t*** Business: Edit Entry ***\n");
// Display edit functions
System.out.println("\tl. Edit Name Only");
System.out.println("\t2. Edit Telephone Only");
System.out.println("\t3. Edit Address Only");
System.out.println("\t4. Edit Name, Telephone & Address");
System.out.println("\t5. Skip\n");
System.out.print("\tOption > ");
} // End displayEditMenu() method
/********************** DISPLAY SEARCH MENU ***********************/
public static void displaySearchMenu(char listCategory) {
// Display heading
if (listCategory == '1')
System.out.println("\n\n\t*** Friends: Search Entry ***\n");
else
System.out.println("\n\n\t*** Business: Search Entry ***\n");
// Display search functions
System.out.println("\tl. Search by Name");
System.out.println("\t2. Search by Telephone");
System.out.println("\t3. Search by Address");
System.out.println("\t4. Skip\n");
System.out.print("\tOption > ");
// End displaySearchMenu()
} // End Main class
/*********** PERSON CLASS TO HOLD PERSON DATA *****************/
class Person {
// Declaration of attributes of Person class
private String name;
private String telephone;
private String address;
/*************** RETRIEVE NAME FROM A PERSON OBJECT ***************/
public String getName() {
return name;
} // End getName() method
/************ RETRIEVE TELEPHONE FROM A PERSON OBJECT *************/
public String getTelephone() {
return telephone;
} // End getTelephone() method
/************* RETRIEVE ADDRESS FROM A PERSON OBJECT **************/
public String getAddress() {
return address;
} // End getAddress() method
/***************** ASSIGN NAME TO A PERSON OBJECT *****************/
public void setName(String entry) {
name = entry;
} // End setName()method
/************* ASSIGN TELEPHONE TO A PERSON OBJECT ***************/
public void setTelephone(String entry) {
telephone = entry;
} // End setTelephone() method
/*************** ASSIGN ADDRESS TO A PERSON OBJECT ****************/
public void setAddress(String entry) {
address = entry;
} // End setAddress() method
} // End Person class
/***** ENTRYCONTROLLER CLASS TO CONTROL ENTRIES & MAINTAIN DATA ******/
class EntryController {
// Declare variables
int noOfFriends, noOfBusiness;
// Declare arrays for friends and business category
Person[] friendsList = new Person[100];
Person[] businessList = new Person[100];
/***** CONSTRUCTOR TO INITIALISE NUMBER OF FRIENDS & BUSINESS *****/
EntryController() {
noOfFriends = 0;
noOfBusiness =0;
} //End EntryController() method
/******************* CONTROLLER FOR NEW ENTRY ********************/
public void addEntry(char listCategory) throws Exception {
// Declare variables
boolean valid;
Person addEntry = new Person();
String header, input;
// Display heading
if (listCategory == '1')
header = "\n\n\t*** Friends: New Entry ***\n";
else
header = "\n\n\t*** Business: New Entry ***\n";
System.out.println(header);
// Get user to input name
System.out.print("\tEnterName\t> ");
//addEntry.setName(getUserInput());
// Get user to input telephone
System.out.print("\tEnter Telephone\t> ");
do { // Test validity of telephone
input = getUserInput();
valid = validTelephone(input);
if (!valid) System.out.print
("\tOnly numeric and space allowed. Try again > ");
else addEntry.setTelephone(input);
} while (!valid);
// Get user to input address
System.out.print("\tEnter Address\t> ");
addEntry.setAddress(getUserInput());
// Add new entry to the relevant list
if (listCategory =='1'){
friendsList[noOfFriends++] = addEntry;
bubbleSort(friendsList, noOfFriends);
}
else {
businessList[noOfBusiness++] = addEntry;
bubbleSort(businessList, noOfBusiness);
} // End addEntry() method
/***************** CONTROLLER FOR EDIT ENTRY ********************/
public void editEntry(char listCategory) throws Exception {
// Declare variables & objects
boolean matched, toEdit, valid;
char editOption;
int count = 0, noOfMatch = 0, recordNum = 0;
int[] matchedRecord;
Person[] editList = getDirectoryList(listCategory);
Person editEntry = new Person();
String header, input;
// Display heading
if (listCategory == '1')
header = "\n\n\t*** Friends: Edit Entry ***\n";
else
header = "\n\n\t*** Business: Edit Entry ***\n";
// Get user to input name to edit
do{
matched = toEdit = true;
System.out.println(header);
System.out.print("\tEnter Name to Edit > ");
// Search for matching records
matchedRecord = searchEntry(listCategory, '0');
// Test if any matching record exists
if (matchedRecord[0] == -1) {
matched = toEdit = false;
}
} while (!matched && toEdit);
// Calculate no of matches if matching record(s) exist
while (matchedRecord[count] != -1) {
noOfMatch = ++count;
}
// Get user to select one if multiple matching records exist
if (noOfMatch ==1) recordNum = 1;
else if (noOfMatch > 1) {
System.out.print
("\tEnter matched record number to Edit (0 to Skip) > ");
do { // Test validity of record number
input = getUserlnput();
valid = validNumber(input);
if (valid) {
recordNum = Integer.parselnt(input);
if (recordNum < 0 || recordNum > noOfMatch)
valid = false;
}
if(!valid)
System.out.print("\tlnvalid entry! Try again > ");
} while (!valid);
// Skip editing if user chooses "0"
if (recordNum == 0) toEdit = false;
else toEdit = true;
}//End if
// Display Edit Menu
if (toEdit) {
editEntry = editList[matchedRecord[recordNum - 1]];
Main.displayEditMenu(listCategory);
editOption = Directory.getUserOption('1', '5');
switch(editOption) {
case '1': // Edit name only
System.out.println
("\tExisting Name > " + editEntry.getName());
System.out.print("\tEnter New Name > ");
editEntry.setName(getUserInput());
break;
case '2': // Edit telephone only
System.out.println
("\tExisting Telephone > " + editEntry.getTelephone());
System.out.print("\tEnter New Telephone > ");
do {// Test validity of Telephone
input = getUserInput();
valid = validTeIephone(input);
if (!valid) System.out.print
("\tOnIy numeric and space allowed. Try again > ");
else editEntry.setTelephone(input);
} while (!valid);
break;

case '3': // Edit address only
System.out.println
("\tExisting Address > " + editEntry.getAddress());
System.out.print("\tEnter New Address > ");
editEntry.setAddress(getUserInput());
break;

case '4': // Edit name, telephone & address
System.out.println
("\tExisting Name\t\t> " + editEntry.getName());
System.out.print("\tEnter New Name\t\t> ");
editEntry.setName(getUserInput());
System.out.println("\tExisting Telephone\t> " +
editEntry.getTelephone());
System.out.print("\tEnter New Telephone\t> ");
do { // Test validity of telephone
input = getUserInput();
valid = validTelephone(input);
if (!valid) System.out.print
("\tOnly numeric and space allowed. Try again > ");
else editEntry.setTelephone(input);
} while (!valid);
System.out.println("\tExisting Address\t> " + editEntry.getAddress());
System.out.print("\tEnterNew Address\t> ");
editEntry.setAddress(getUserInput());
break;
default: // Skip editing
break;
} // End switch
// Update entry in list
if (editOption == '5')
System.out.print("\tEntry not edited. ");
else {
editList[matchedRecord[recordNum - 1]] = editEntry;
System.out.print("\tEntry edited. ");
// Sort relevant list in order of names
if(listCategory == '1')
bubbleSort(friendsList, noOfFriends);
else
bubbleSort(businessList,noOfBusiness);
}
}
else System.out.print("\tEntry not edited. ");
} // End editEntry() method
/****************** CONTROLLER FOR DELETE ENTRY *******************/
public void deleteEntry(char listCategory) throws Exception {
// Declare variables & objects
boolean matched, toDelete, valid;
int count = 0, noOfMatch = 0, recordNum = 0;
int[] matchedRecord;
Person[] deleteList = getDirectoryList(listCategory);
String header, input;
// Display heading
if (listCategory == '1')
header = "\n\n\t*** Friends: Delete Entry ***\n";
else
header = "\n\n\t*** Business: Delete Entry ***\n";
// Gef user to input name to delete
do{
matched = toDelete = true;
System.out.println(header);
System.out.print("\tEnterName to Delete > ");
// Search for any matching record
matchedRecord = searchEntry(listCategory, '0');
// Test if any matching record exists
if (matchedRecord[0] = -1) { matched = toDelete = false;
}
} while (!matched && toDelete);
// Calculate no of matches if matching record(s) exist
while (matchedRecord[count] !=-1){
noOfMatch = ++count;
}
// Get user to select one if multiple matching records exist
if (noOfMatch ==1){
recordNum= 1;
System.out.print("\tOnly 1 matched record. Delete it (Y/N) > ");
toDelete = Directory.getAnswer();
}
else if (noOfMatch > 1 ) {
System.out.print
("\tEnter matched record number to Delete (0 to Skip) > ");
do { // Test validity of record number
input = getUserlnput();
valid = validNumber(input);
if (valid) {
recordNum = Integer.parselnt(input);
if (recordNum < 0 || recordNum > noOfMatch)
valid = false;
}
if (! valid)
System.out.print("\tlnvalid entry! Try again > ");
} while (!valid);
// Skip editing if user chooses "0" if (recordNum ==0) toDelete = false;
else toDelete = true;
}
// Delete entry
if (toDelete) {
count = matchedRecord[recordNum - 1];
// Pack the relevant list starting from deleted entry
while (deleteList[count] != null) {
deleteList[count]=deleteList[++count];
}
if (listCategory = '1') -noOfFriends;
else - noOfBusiness;
System.out.print("\tEntry deleted, ");
}
else System.out.print("\tEntry not deleted. ");
} // End deleteEntry() method
/***************** CONTROLLER FOR SEARCH ENTRY *******************/
public int[] searchEntry(char listCategory, char searchOption)
throws Exception {
// Declare variables & objects
int count = 0, noOfMatch = 0;
int[] matchedRecord = new int[100];
Person[] searchList = getDirectoryList(listCategory);
String header, searchEntry;
// Display heading
if (listCategory == '1')
header = "\n\n\t*** Friends: Search Entry ***\n";
else
header = "\n\n\t*** Business: SearchEntry ***\n";
matchedRecord[0] = -1;// Array to hold indices of matched record
switch(searchOption) {
case '1': // Search by name
System.out.println(header);
System.out.print("\tEnter Name to Search > ");
searchEntry = getUserInput();
while (searchList[count] != null) {
if (searchList[count].getName().toUpperCase().
startsWith(searchEntry.toUpperCase()))
matchedRecord[noOfMatch++-] = count;
matchedRecord[noOfMatch]=-1;
++count;
} // End while
break;

case '2': // Search by telephone
System.out.println(header);
System.out.print("\tEnter Telephone to Search > ");
searchEntry = getUserInput();
while (searchList[count] !=null){
if(searchList[count].getTelephone().
toUpperCase().startsWith(searchEntry.toUpperCase()))
matchedRecord[noOfMatch++] = count;
matchedRecord[noOfMatch] = -1;
++count;
} // End while
break;

case'3'://Search by address
System.out.println(header);
System.out.print("\tEnter Address to Search > ");
searchEntry = getUserlnput();
while (searchList[count] != null) {
if(searchList[count].getAddress().
toUpperCase().startsWith(searchEntry.toUpperCase()))
matchedRecord[noOfMatch++] = count;
matchedRecord[noOfMatch] = -1;
++count;
} // end while
break;
default: // Search by name for edit & delete only
searchEntry = getUserInput();
while (searchList[count] != null) {
if (searchList[count].getName().toUpperCase().
startsWith(searchEntry.toUpperCase()))
matchedRecord[noOfMatch++] = count;
matchedRecord[noOfMatch] = -1;
++count;
} // End while
break;
} //End switch
// Display all matching records
for (count = 0; count < noOfMatch; ++count) {
System.out.println("\tMatched record #" + (count + 1));
System.out.println("\tName\t\t: " +
searchList[matchedRecord[count]].getName());
System.out.println("\tTelephone\t: " +
searchList[matchedRecord[count]].getTelephone());
System.out.println("\tAddress\t\t: " +
searchList[matchedRecord[count]].getAddress());
// Display entries in group of 5
if ((count +1)% 5 == 0){
System.out.print("\tPress ENTER to Continue > ");
System.in.read(); System.in.read();
}
}
// Display number of matched records
if (noOfMatch == 0)
System.out.println("\tNo matched record.");
else
System.out.println("\t Total number of matched records: " + noOfMatch);
return matchedRecord;
} // End searchEntry() method
/*************** CONTROLLER FOR DISPLAY ALL ENTRIES ***************/
public void displayAllEntry(char listCategory) throws Exception {
// Declare variables & objects
int count = 0;
Person[] displayList = getDirectoryList(listCategory);
// Display all entries
while (displayListfcount] != null) {
System.out.println("\tName\t\t: " +
displayList[count] .getName());
System.out.println("\tTelephone\t: " +
displayList[count].getTelephone());
System.out.println("\tAddress\t\t: " +
displayList[count].getAddress() + "\n");
++count;
// Display entries in group of 5
if(count%5 = 0){
System.out.print("\tPress ENTER to Continue > ");
System.in.read(); System.in.read();
}
} // End while
System.out.println("\tTotal number of records: " + count);
} // End displayAllEntry()
/************** RETRIEVE FRIENDS OR BUSINESS LIST ****************/
public Person[] getDirectoryList (char HstCategory) {
if (listCategory == '1') return friendsList;
else return businessList;
} // End getDirectoryList() method
/******************* GET USER TO INPUT STRING ********************/
public String getUserlnput() throws Exception {
IStream userInput = new IStream();
return userInput.readStr();
} // End getUserInput() method
/****************SORT LISTING IN ORDER OF NAMES *****************/
public static void bubbleSort(Person[] list, int listSize) {
// Declare variables & object
int loop1, Ioop2;
int highSubscript = listSize - 1, comparesToMake = listSize - 1;
Person temp;
// Bubble sort Person object by names
for (loopl = 0; loopl < highSubscript; ++loop1) {
for (Ioop2 = 0; Ioop2 < comparesToMake; ++loop2) {
if (list[loop2] .getName().toUpperCase().compareTo
(list[loop2 + l].getName().toUpperCase()) > 0) {
temp = list[loop2];
list[loop2] = list[loop2 + 1];
list[loop2 + 1] = temp;
}
} // End loop2
--comparesToMake;
}//Endloop1
return Temp;
} // End bubbleSort() method
/************ TEST WHETHER STRING INPUT IS NUMERIC **************/
public static boolean validNumber(String input) {
// Declare variables
boolean valid = true;
int position = 0;
// Do not accept empty input
if (input.equals("")) valid = false;
// Test whether characters in the string are numeric
while (valid && position < inputlength()) {
if (input.charAt(position) < '0' ||
input.charAt(position) > '9')
valid = false;
++position;
} // End while
return valid;
} // End validNumber() method
/****** TEST WHETHER STRING INPUT IS NUMERIC (SPACE ALLOWED) ******/
public static boolean validTelephone(String input) {
// Declare variables
boolean valid = true;
int position = 0;
// Do not accept empty input
if (input.equals("")) valid = false;
// Test whether characters in the string are numeric or space
while (valid && position < input.length()) {
if ((input.charAt(position) <'0' ||
input.charAt(position) > '9') &&
input.charAt(position) != ' ')
valid = false;
++position;
} // End while
return valid;
}; //End validTelephone() method
}
} // End EntryController
}
import java.io.*;
public class IStream {
public String readStr() throws IOException {
InputStream istream;
int c;
char x;
String istr = new String();
istream = System.in;
try{
while ((c = istream.read()) != 13) {
x = (char) c;
istr = istr + x;
}//end while
}//end try
catch(IOException e) {
System.out.println ("Err Input");
return ("-1");
}//end catch
finally {
istream.close();
System.in.read();
return (istr);
}//end finally
}//end readstr
public int readlnt() throws IOException {
String inputString = new String();
char newchar;
int inputNumber=-1;
try{
System.out.println ("Enter Number > ");
newchar = (char) System.in.read();
while (newchar >= '0' && newchar <= '9') {
inputString = inputString + newchar;
newchar = (char) System.in.read();
inputNumber = Integer.parseInt(inputString);
System.out.println (inputNumber);
}
}//end try
catch(IOException e) {
System.out.println ("Err Input");
return (-1);
}//end catch
finally {
//istream.close();
System.in.read();
return (inputNumber);
}//end finally
}//end readstr
}

 
Ranch Hand
Posts: 70
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
few things i observed are
if (listCategory = '1')
{
- // remove this -
}
noOfFriends ;
else
{
-// remove this -
}
matchedRecord[noOfMatch++ -] = count ; // there is an - after ++
[ August 04, 2003: Message edited by: Karthikeyan Rajendraprasad ]
 
Ranch Hand
Posts: 1078
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Well for one thing are you importing the classes you're using?
reply
    Bookmark Topic Watch Topic
  • New Topic