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

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




Ordering Menu stuck

 
Reply to this topicStart new topic

Ordering Menu stuck

cnewman
16 Sep, 2007 - 07:02 PM
Post #1

New D.I.C Head
*

Joined: 15 Sep, 2007
Posts: 14


My Contributions
Hi guys,

Im new to the forum and although I have read A LOT in this forum, I decided to register and become and active member. I really want to take my focus into java and c++ maybe.... I Guess its what code I really get into, im sure i'll learn them all. icon_up.gif

Well I just wanted to say thanks to all of the community, together we can grow.

The reason im posting this is because im in a beginning programmers course. Were focusing on the 6 steps of programming, and java right now. In class we do a lot a pseudo and then take it home and code it ourselves. We have done payroll programs and other fun beginner's stuff.

Right now we are working on a selection menu and storing in arrays. We have recently learned about calling other modules and global/local variables.

When I'm creating this selection menu, (on selection 4) it ends with a subtotal and a total, with a tax included. We did the pseudo code in class and I typed it all out correctly as far as I can see but im getting about 13 errors or so... its due Monday, so I'll have to turn in the grade, but as far as my own education goes I want to see exactly where I went wrong here. Can anyone help?

CODE

/*
Program Name: hotDog menu.java
Date        : 9-16-07
Author      : Christopher XXXX
*/

import java.io.*;

public class  newhotDog//class name here, same as file name

{
     // use BufferedReader class to input from the keyboard
    // declare a variable of type BufferedReader
    BufferedReader input = new BufferedReader(new InputStreamReader(System.in));
    //declare variable for input
    String inputString;
    String product(3);
    String quanity(3);
    Double price(3);
    
    public newhotDog()throws IOException{
        
    welcome();
    mainMenu();
    finishUp();


  }
  
  public void mainMenu()throws IOException{
        
        int choice;
        
        do
        {
            choice = displayMenu();
            switch(choice)
            {
                case 1:
                        quanity[0] = quanity[0]+1;
                        break;
                case 2:
                        quanity[1] = quanity[1]+1;
                        break;
                
                case 3:
                        quanity[2] = quanity[2]+1;
                        break;
                        
                case 4:
                        System.out.println("End of order");
                        break;
                
                default:
                    System.out.println("You must choose from the menu!!!!");
            }  
            
        }while(choice != 4);
        
        
        
    }
    
    public void finishUp()
           int total = 0;
           int subtotal = 0;
           int choice;
           double taxamount;
               
           choice=0;
           
           while(choice < 3){
           System.out.println(product[choice] + quanity[choice] + (quanity [choice] * price[choice]));
           
           subtotal= subtotal + quanity[choice] * price[choice];
           choice ++;
        }
        
        taxamount = .07 * subtotal;
        total = taxamount + subtotal;
        
        System.out.println(subtotal);
        System.out.println(taxamount);
        System.out.println(total);
}
   }
  
  public static void main(String [] args) throws IOException // main method

  {
    new hotDogs();
  }
}




Any help would be appreciated. I got the jist of it in, now if it would just compile correctly. .07 is the tax im sure you seen that already wink2.gif im kinda at a loss at this point, and have been racking my brain.... crazy.gif
User is offlineProfile CardPM
+Quote Post

alpha02
RE: Ordering Menu Stuck
17 Sep, 2007 - 03:27 AM
Post #2

D.I.C Addict
Group Icon

Joined: 20 May, 2006
Posts: 687


Dream Kudos: 850
My Contributions
Hi and welcome to DIC, glad you decided to join! I found a few uncorrect things here, first:

CODE
String quanity(3);

throws a syntax error. If you want to declare an array, do it like that:
CODE
String[] quanity;
quanity = new String[3]; //Put this where you want to create your array


Next point: In the constructor, you haven't defined the welcome() method, so it throws a compile error saying the welcome() method is undefined.

At the end of the code, you called:
CODE
new hotDog();

your class is named newHotDog, so you should have called:
CODE
new newHotDog();

creating an object is saying "new "+class name.
By convention, a class name starts with a capital letter, but it won't throw an error if you don't follow that.

Also, a method body is between {}. I know you know this, maybe you just forgot it at the start of the finishUp method, add it.

This was a basic overview of your errors, I suggest you use Eclipse SDK to develop in Java, get it here: http://www.eclipse.org. It shows your compile errors as you write your code.

In this forum, there's a Java FAQ topic which shows some beginner tutorials, I think you need a syntax tutorial.

Hope this helps, any questions then just reply!

This post has been edited by alpha02: 17 Sep, 2007 - 03:46 AM
User is offlineProfile CardPM
+Quote Post

cnewman
RE: Ordering Menu Stuck
17 Sep, 2007 - 01:28 PM
Post #3

New D.I.C Head
*

Joined: 15 Sep, 2007
Posts: 14


My Contributions
thanks much im actually sitting in the lab trying to do some last minute changes before I go into the final test. We are not actually learning java, this isnt java class we were taught the jist, just to let us view the overall methods, etc of progamming. Next quarter im taking java, this could be fun. Im very addictive personality and can alredy see myself awake at 4am working on proggies. Anyways thank you very much for your insight and im going to go clean up that code now, hope to see you around.

-Chris
User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic
Time is now: 1/8/09 12:30AM

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