1 Reply Latest reply: Apr 22, 2009 1:44 PM by 843810 RSS

    Yep...  TOTALLY CONFUSED.

    843810
      Okay, so I have a program here... It's my application file and every time I try to build it, it tells me that '{' is expected. I checked all of my curly brackets and they all match up. I'll put my code on here...

      import java.util.Scanner; //Imports Scanner library to the program.

      public class AddressBook_app()

      {

           {
                
                Scanner keyboard = new Scanner(System.in); //Allows keyboard to be used by user for input.
                
           String sName = "";
                String sStreet = "";
                String sCity = "";
                String sState = "";
                String sZip = "";
                int iMenu = 1; //Initializes the variables

                System.out.println("Please enter Required Information, Press ENTER to start:"); //Scan in User inputs
                
      do

           {

           String sFAKE = keyboard.nextLine();// this is to solve the problem when in...
           //loop and pressing 1 "enter" it skips Enter name because when pressing...
           //enter its reading that as next line
           Address userAddress = new Address();
           //Places Scanner into a new file called Address

           System.out.print("Enter Full Name: ");
                sName = keyboard.nextLine();
                oMyApplication2.setName(sName);

                System.out.print("\nEnter Street Address: ");
                sStreet = keyboard.nextLine();
                oMyApplication2.setStreet(sStreet);

                System.out.print("\nEnter City: ");
                sCity = keyboard.nextLine();
                oMyApplication2.setCity(sCity);

                System.out.print("\nEnter State: ");
                sState = keyboard.nextLine();
                oMyApplication2.setState(sState);

                System.out.print("\nEnter Zipcode: ");
                sZip = keyboard.nextLine();
      oMyApplication2.setZip(sZip);

                System.out.println("\n\nThe Address entered is: \n" + oMyApplication2.getString());

                System.out.println("\n" + oMyApplication2.numEntries() + "\n");

                System.out.print("Press 1 to enter another address or 2 to quit: ");
                iMenu = keyboard.nextInt();

           }
                
                while(iMenu!=2);
                
           }

      class Address     //Address class allows user to input addresses
           {
                     //class variables
                private String sName;
                private String sStreet;
                private String sCity;
                private String sState;
                private String sZip;
                private int iAddress;
                     //blank constructor increments number so far     
                public Address()
                {
                     iAddress++;
                }
                     //constructor for all parameters
                public Address(String name, String street, String city, String state, String zip)
                {
                     sName = name;
                     sStreet = street;
                     sCity = city;
                     sState = state;
                     sZip = zip;
                     iAddress++;
                }
                     //set constructors to allow for changing variables     
                public void setName(String name)
                {
                     sName = name;
                }
           
                public void setStreet(String street)
                {
                     sStreet = street;
                }
           
                public void setCity(String city)
                {
                     sCity = city;
                }
           
                public void setState(String state)
                {
                     sState = state;
                }
           
                public void setZip(String zip)
                {
                     sZip = zip;
                }

                     //methods to return variable values     
                public String getName()
                {
                     return sName;
                }
           
                public String getStreet()
                {
                     return sStreet;
                }
           
                public String getCity()
                {
                     return sCity;
                }
           
                public String getState()
                {
                     return sState;
                }
           
                public String getZip()
                {
                     return sZip;
                }
                public String getString()
                {
                     return(sName + "\n" + sStreet + "\n" + sCity + ", " + sState + " " + sZip);
                }
           
                public String numEntries()
                {
                     if(iAddress==1)
                     {
                     return(iAddress + " Address has been entered.");
                     }     
                     else
                     {
                     return(iAddress + " Addresses have been entered so far.");
                     }
                }
           }
      }
        • 1. Re: Yep...  TOTALLY CONFUSED.
          843810
          Hi,

          You should remove parethesis from the first line.

          For example define class like this:
          public class AddressBook_app

          Also, according to Java naming convention, you shouldn't use underline (_) in the class name. Better name could be AddressBookApp.

          There may be other problems also, but try to remove the parethesis and see what happens...

          BR,
          Markku