Welcome to Dream.In.Code
Become a Java Expert!

Join 149,506 Java Programmers for FREE! Get instant access to thousands of Java experts, tutorials, code snippets, and more! There are 1,330 people online right now. Registration is fast and FREE... Join Now!




Expected '}'

 
Reply to this topicStart new topic

Expected '}', Array comparison code won't compile

Carlton
16 Aug, 2007 - 12:33 PM
Post #1

New D.I.C Head
*

Joined: 16 Aug, 2007
Posts: 1


My Contributions
CODE

/*
* OrderHistory.java
*
* Created on August 15, 2007, 4:35 PM
*
* To change this template, choose Tools | Template Manager
* and open the template in the editor.
*/

/**
*
* @author Carlton Brown
*/
import java.io.*;


public class OrderHistory {
    
    //interger of the array the constructor of OrderHistory will
    //take an array of integers representing the scenario of steps
    //in the coffeeVending Project.
    
    public  final static int SEL_LARGE_COFFEE=1;
    public  final static int SEL_SUGAR=2;
    public  final static int SEL_XSUGAR=3;
    public  final static int SEL_CREAMER=4;
    public  final static int SEL_XCREAMER=5;
    public  final static int SEL_SMALL_COFFEE=6;
    public  final static int SEL_DONE =-1;
    
    private static int[] scenario1={SEL_LARGE_COFFEE,SEL_SMALL_COFFEE,SEL_SUGAR,SEL_XSUGAR,
                                   SEL_CREAMER,SEL_XCREAMER,SEL_DONE};
    
    //create an array to put output from customer's selection
    private int[] readOrder;    
    
    /** Creates a new instance of OrderHistory */
    public OrderHistory(int [] steps) {
        
        try{
            System.out.println("Entering try statement for output");
                  FileOutputStream fsout = new  //Opens file for data
                          FileOutputStream("newOrders.dat");
                  ObjectOutputStream out = new ObjectOutputStream(fsout);
            out.writeObject(steps);
        out.close();
             }
               catch(FileNotFoundException ex)
              {
        System.out.println(ex.getMessage());
    }
               catch(IOException ex)
    {
        System.out.println(ex.getMessage());
    
    }
        try{
            System.out.println("Entering try Statement for input");
        
                  FileInputStream fsin = new
                          FileInputStream("newOrder.dat");
                              ObjectInputStream in = new ObjectInputStream(fsin);
                          readOrder = (int[])in.readObject();
                    in.close();      
            
        }
               catch(FileNotFoundException ex)
              {
        System.out.println(ex.getMessage());
    }
               catch(IOException ex)
    {
        System.out.println(ex.getMessage());
    
     }
    }
    
    public int[] getReadOrder() //returns the read order array
    {
        return readOrder;
    }
    public static void main(String[] args)
    {
      OrderHistory myOrderHistory = new
              OrderHistory(scenario1);
      int[] readOrderBack =myOrderHistory.getReadOrder();
      
      for(int i=0;i<scenario1.length;i++){
          int aStep=scenario1[i];
          switch(aStep){
              case SEL_LARGE_COFFEE:
               if(readOrder[i]==OrderHistory[1]){
                if(ScenarioSteps.SEL_LARGE_COFFEE)
                  System.out.println("Found Large Coffee!!!");
              else
                  System.out.println("Large Coffee Not Found");
              break;
               }
              case SEL_SMALL_COFFEE:
                if(readOrderBack[i]==OrderHistory[6]){
                  if(ScenarioSteps.SEL_SMALL_COFFEE)
                  System.out.println("Found Small Coffee!!!");
              else
                  System.out.println("Small Coffee Not Found");
              break;
                }
              case SEL_SUGAR:
              if(readOrderBack[i]==OrderHistory[2]){
                  if(ScenarioSteps.SEL_SUGAR)
                  System.out.println("Found Sugar");
              else
                  System.out.println("Sugar not found");
              break;
              }
              case SEL_XSUGAR:
                 if(readOrderBack[i]==OrderHistory[3]){
                  if(ScenarioSteps.SEL_XSUGAR)
                  System.out.println("Found extra sugar");
              else
                  System.out.println("extra sugar not found");
              break;
             }
          
              case SEL_CREAMER:
                 if(readOrderBack[i]==OrderHistory[4]){
                    if(ScenarioSteps.SEL_CREAMER)
                  System.out.println("Found creamer");
              else
                  System.out.println("Creamer not found");
              break;
      }
              case SEL_XCREAMER:
                 if(readOrderBack[i]==OrderHistory[5]){
                    if(ScenarioSteps.SEL_XCREAMER)
                  System.out.println("Found extra creamer");
              else
                  System.out.println("Extra creamer not found");
              break;
    }
              case SEL_DONE:
                 if(readOrderBack[i]==OrderHistory[-1]){
                    if(ScenarioSteps.SEL_DONE)
                  System.out.println("Found done");
              else
                  System.out.println("Done not found");
              break;
          }
      }
    
   }
}


User is offlineProfile CardPM
+Quote Post

no2pencil
RE: Expected '}'
16 Aug, 2007 - 12:40 PM
Post #2

My fridge be runnin OH NOEZ!
Group Icon

Joined: 10 May, 2007
Posts: 7,121



Thanked: 76 times
Dream Kudos: 2425
Expert In: Goofing Off

My Contributions
QUOTE(Carlton @ 16 Aug, 2007 - 01:33 PM) *

CODE

scenario1={SEL_LARGE_COFFEE,SEL_SMALL_COFFEE,SEL_SUGAR,SEL_XSUGAR, SEL_CREAMER,SEL_XCREAMER,SEL_DONE};



Is this correct syntax?

This post has been edited by no2pencil: 16 Aug, 2007 - 12:43 PM
User is online!Profile CardPM
+Quote Post

skyhawk133
RE: Expected '}'
16 Aug, 2007 - 12:42 PM
Post #3

Head DIC Head
Group Icon

Joined: 17 Mar, 2001
Posts: 15,262



Thanked: 61 times
Dream Kudos: 1650
Expert In: Web Development

My Contributions
LOL.

I think what no2pencil is trying to say by quoting you is... we need more info.

Are you getting an error? What is that error? What is the program supposed to do, what is the desired output?

Johnny 5 Alive, Need More Input.
User is online!Profile CardPM
+Quote Post

no2pencil
RE: Expected '}'
16 Aug, 2007 - 12:45 PM
Post #4

My fridge be runnin OH NOEZ!
Group Icon

Joined: 10 May, 2007
Posts: 7,121



Thanked: 76 times
Dream Kudos: 2425
Expert In: Goofing Off

My Contributions
QUOTE(skyhawk133 @ 16 Aug, 2007 - 01:42 PM) *

LOL.

I think what no2pencil is trying to say by quoting you is... we need more info.

Are you getting an error? What is that error? What is the program supposed to do, what is the desired output?

Johnny 5 Alive, Need More Input.

I actually had miss-counted. Turned out on a 0 number. That's what I always do when I'm missing some curly brackets. I think the code gets sloppy in the area of if/else inside of the select statement. Either always use the brackets, or stick the else statement code on the same line. Keep it consistent.
User is online!Profile CardPM
+Quote Post

Martyr2
RE: Expected '}'
16 Aug, 2007 - 01:00 PM
Post #5

Programming Theoretician
Group Icon

Joined: 18 Apr, 2007
Posts: 5,655



Thanked: 313 times
Expert In: C/C++, Java, VB, VB.NET, C#, PHP, Web Development, HTML & CSS, Javascript

My Contributions
Of course there are a lot of things wrong with this, but to solve the immediate error so you can get to the rest of the errors this thing produces, you have to add one more closing brace at the very end. You close your main function but you forgot to close the entire class.

Once you do this you will get several errors.

1) The readorder array is going to have to be static if you reference it from static main
2) You don't have an array called OrderHistory defined. Perhaps you mean myOrderHistory?
3) Unless you got another file in this package, ScenarioSteps is undefined.


Fixing those problems should get you through most of your second round of errors. Who knows what will be after this.

In the spirit of skyhawk and his short circuit reference I guess it is safe to say (after smashing this program's problems like the colt gun in the movie) Playyy dohhhh
User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic
Time is now: 1/7/09 07:02PM

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter

Live Java Help!

Java Tutorials

Reference Sheets

Java Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month