0

I am trying to use a menu system that can delete a customer from my array myHotel[], this is built from an object.

if(menu.charAt(0) == 'D')deleteCustomer(myHotel[]);

...

public void deleteCustomer(String myHotel[]){
         Scanner input = new Scanner(System.in);
         System.out.println("Please Enter Room Number to Delete Customer");
         roomNum=input.nextInt();
         myHotel[roomNum].setName("e");
    }

I get the errors, cannot find symbol?

Here is the Full Code

import java.util.*;
public class Main {

     public static void main(String[] args) {

        Scanner input = new Scanner(System.in);
        int roomNum=0;
        Room[] myHotel = new Room[10];
        for (int x =0; x<10; x++){
           myHotel[x] = new Room(); 
        }

        String roomName;

        String menu;
        do { 

        System.out.println("Please Select an Option from the Menu:");
        System.out.println("Enter V to View all Rooms");
        System.out.println("Enter A to Add Customer to Room");
        System.out.println("Enter D to Delete Customer from Room");
        System.out.println("Enter Q to Quit");
        menu=input.next();
        //if(menu.charAt(0) == 'V')viewAllRooms(); 
        //if(menu.charAt(0) == 'A')addCustomer(); 
        if(menu.charAt(0) == 'D')deleteCustomer(myHotel[]);
        } while (menu.charAt(0) != 'Q');

            while (roomNum < 10) {
            for (int x = 0; x < 10; x++ )
             if (myHotel[x].getName().equals("e"))System.out.println("room " + x + " is empty");

            System.out.println("Enter room number (0-9) or 10 to stop:");
            roomNum = input.nextInt();
            System.out.println("Enter name for room " + roomNum + " :");
            roomName = input.next();
            myHotel[roomNum].setName(roomName);

             for (int x = 0; x < 10; x++) {
                //System.out.println("room " + x + " occupied by " + myHotel[x].mainName);
                System.out.println("room " + x + " occupied by " + myHotel[x].getName());
            }
        }
    }
     public void deleteCustomer(String myHotelRef){
         Scanner input = new Scanner(System.in);
         System.out.println("Please Enter Room Number to Delete Customer");
         int deleteRoom=input.nextInt();
         myHotelRef[deleteRoom].setName("e");
    }

     }
2
  • 2
    which symbol is giving you this error? Commented Mar 19, 2014 at 14:09
  • can not find symbol means you may have not declared your method or some field. Check if every class is imported. Commented Mar 19, 2014 at 15:13

3 Answers 3

5

You get multiple errors. What is myHotel[]? roomNum is not defined, etc.

Please use your compiler.

Sign up to request clarification or add additional context in comments.

Comments

3

First you need declare myHotel array and pass it with out [].

deleteCustomer(myHotel);

Second, there is not such a method setName(String name) in String class

myHotel[roomNum].setName("e");// no such a method

Third, you need to declare the roomNum variable like:

int roomNum = input.nextInt();

1 Comment

roomNum should be int roomNum since it appears to be an array index variable. (also ignore previous messages if you saw them. Lousy phone.)
0

Your main problem is that you've included [] in your call to deleteCustomer. It should be:

if (menu.charAt(0) == 'D') {
    deleteCustomer(myHotel);
}

When you reference an array object as a whole you don't include square brackets. Square brackets are for the declaration, initialisation and for accessing individual elements within the array.

I'd also recommend that you get into the habit of always using curly braces with your if, for and while constructs, as not including them is often the cause of bugs. It also makes it easier to read when you come back to it, and you're clearly indicating to others what should be part of the loop and what shouldn't.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.