Hi, I have a java assignment due in a couple of hours and I am stuck and i am getting a lot of errors in my code, if someone out their can help me out, i would appreciate it, thanks.

here is my java assignment.........
assign6 java.doc
this is the assignment that i am trying to finish up
hotDog.java
This is the java file I am working on!!!

Program Name: hotDog.java
Date : June 7, 2009
Author : Casey Kucera
Desc : Assignment #6
*/

import java.io.*;

public class hotDog //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 menu[] = {"Hot Dog", "Fries", "Lemonade", "End Order"};
double price[] = { 1.50, 1.00, 2.25, 0.0};
int Qty[] = new int[4];

public hotDog()throws IOException{//constructor, place class name here

welcome();
Order();
printReceipt();

}//end constructor

public void welcome(){
System.out.println("Welcome to SCC's Dog's");

}

public void Order()throws IOException {
int selection;
do
{
selection = displayMenu();
switch(selection)
{
case 1:
Qty[0] = (Qty[0] + 1);
break;

        case 2:
            Qty[1] = (Qty[1] + 1);
            break; 

        case 3:
            Qty[2] = (Qty[2] + 1);
            break;  

        case 4:
            System.out.print( "Ending Order");
            break;          

        default:
            System.out.println("You must choose from the menu!!!!");
    }

}while(selection !=4);

}

public int displayMenu()throws IOException{
int choice;
int item = 0;

System.out.println ("(1)Hot Dog    $1.50");
System.out.println ("(2)Fries      $1.00");
System.out.println ("(3)Lemonade   $2.25");
System.out.println ("(4)End Order");
System.out.println();    

while(item < 4)
{
    System.out.println("(" + (item + 1) + ") " + menu[item] + "$" + price[item]);
    item ++;
}

System.out.println("(" + (item + 1) + ")" + menu[item]);
System.out.println();
System.out.print("Please make your selection from the menu: ");
choice = Integer.parseInt(input.readLine());

return choice;

}

}

public void printReceipt()throws IOException{
double total = 0;
double itemTotal = 0;
double subTotal;
double taxAmt;
int index = 0;

System.out.println("Product" + "quantity" + "price");

while (index < 3)
    itemTotal = price[index] * Qty[index];
    System.out.println (menu[index] + Qty[index] + itemTotal);
    subTotal = subTotal + total;
    index ++;

}
taxAmt = calcTax (subTotal)
total = subTotal + taxAmt;

System.out.println ("subTotal         " + subTotal);
System.out.println ("Tax              " + taxAmt);
System.out.println ("total            " + total);

//begin calcTax
private void calcTax()throws IOException{
double tax;
doube taxRate = .07;
tax = subtotal * taxRate;

return tax;
}

public static void main(String [] args) throws IOException // main method

{
new hotDog();//class constructor name
} // end the main method
} // end the program

If someone can help me out that would be great!!!

Recommended Answers

All 6 Replies

You almost certainly have a brackets problem, either one bracket too many or one bracket too few. Format and use code tags to preserve that formatting.

[code=JAVA] // code here

[/code]

Without indentation, your chances of finding the bracket problem go way down. That's why consistent indentation is key.

First step: comment out everything inside the class except main and the constructor, and comment out everything inside the constructor. That should compile and run perfectly. It won't do anything, but it'll compile and run. If it doesn't, you've found your bracket problem already. If it does, start uncommenting your functions till you find the bracket problem.

thanks for the reply!! i will see if i can find the problem with what you have asked me to do. i have the file indented in the attached file but when i copied and pasted it that is how it turned out to look like in this forum.
thanks for the reply!! i will see if i can find the problem with what you have asked me to do. i have the file indented in the attached file but when i copied and pasted it that is how it turned out to look like in this forum.

That's where the code tags help.

[code=JAVA] // code here

[/code]

or

[code]

// code here

[/code]

Here's an example.

Java-specific code tags (indentation, syntax highlighting, line numbers):

public class HelloWorld
{
    public static void main (String args[])
    {
        System.out.println ("Hello World");
    }
}

Non-Java-specific code tags (indentation, but no highlighting or line numbers)

public class HelloWorld
{
    public static void main (String args[])
    {
        System.out.println ("Hello World");
    }
}

No code tags (looks terrible):

public class HelloWorld
{
public static void main (String args[])
{
System.out.println ("Hello World");
}
}

Program Name: hotDog.java
Date : June 7, 2009
Author : Casey Kucera
Desc : Assignment #6
*/

import java.io.*;

public class hotDog //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 menu[] = {"Hot Dog", "Fries", "Lemonade", "End Order"};
double price[] = { 1.50, 1.00, 2.25, 0.0};
int Qty[] = new int[4];

public hotDog()throws IOException{//constructor, place class name here

welcome();
Order();
printReceipt();

}//end constructor

public void welcome(){
System.out.println("Welcome to SCC's Dog's");

}

public void Order()throws IOException {
int selection;
do
{
selection = displayMenu();
switch(selection)
{
case 1:
Qty[0] = (Qty[0] + 1);
break; 

case 2:
Qty[1] = (Qty[1] + 1);
break; 

case 3:
Qty[2] = (Qty[2] + 1);
break; 

case 4:
System.out.print( "Ending Order");
break; 

default:
System.out.println("You must choose from the menu!!!!");
}

}while(selection !=4);

}

public int displayMenu()throws IOException{
int choice;
int item = 0;

System.out.println ("(1)Hot Dog $1.50");
System.out.println ("(2)Fries $1.00");
System.out.println ("(3)Lemonade $2.25");
System.out.println ("(4)End Order");
System.out.println(); 

while(item < 4)
{
System.out.println("(" + (item + 1) + ") " + menu[item] + "$" + price[item]);
item ++;
}

System.out.println("(" + (item + 1) + ")" + menu[item]);
System.out.println();
System.out.print("Please make your selection from the menu: ");
choice = Integer.parseInt(input.readLine());

return choice;

}

}

public void printReceipt()throws IOException{
double total = 0;
double itemTotal = 0;
double subTotal;
double taxAmt;
int index = 0;

System.out.println("Product" + "quantity" + "price");

while (index < 3)
itemTotal = price[index] * Qty[index];
System.out.println (menu[index] + Qty[index] + itemTotal);
subTotal = subTotal + total;
index ++;
}
taxAmt = calcTax (subTotal)
total = subTotal + taxAmt;

System.out.println ("subTotal " + subTotal);
System.out.println ("Tax " + taxAmt);
System.out.println ("total " + total);

//begin calcTax
private void calcTax()throws IOException{
double tax;
doube taxRate = .07;
tax = subtotal * taxRate;

return tax;
}



public static void main(String [] args) throws IOException // main method

{
new hotDog();//class constructor name
} // end the main method
} // end the program

sorry about that...this looks better now

/*
Program Name: hotDog.java
Date        : June 7, 2009
Author      : Casey Kucera
Desc        : Assignment #6
*/

import java.io.*;

public class hotDog //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 menu[] = {"Hot Dog", "Fries", "Lemonade", "End Order"};
    double price[] = { 1.50, 1.00, 2.25, 0.0};
    int Qty[] = new int[4];
      
  public hotDog()throws IOException{//constructor, place class name here
   
   welcome();
   Order();
   printReceipt();

  }//end constructor
  
   public void welcome(){
  	System.out.println("Welcome to SCC's Dog's");
  	
  	}
  
  public void Order()throws IOException {
  	int selection;
  	
  	do
  	{
  		selection = displayMenu();
  		switch(selection)
  		{
  			case 1:
  				Qty[0] = (Qty[0] + 1);
  				break;  
  								
  			case 2:
  				Qty[1] = (Qty[1] + 1);
  				break; 
  					 		
  			case 3:
  				Qty[2] = (Qty[2] + 1);
  				break;  
  							
  			case 4:
  				System.out.print( "Ending Order");
  				break;  		
  			 					
  			default:
  				System.out.println("You must choose from the menu!!!!");
  		}
  		
  	}while(selection !=4);
  	
  }
    
  public int displayMenu()throws IOException{
  	int choice;
  	int item = 0;
  	
  	System.out.println ("(1)Hot Dog    $1.50");
  	System.out.println ("(2)Fries      $1.00");
  	System.out.println ("(3)Lemonade   $2.25");
  	System.out.println ("(4)End Order");
  	System.out.println();    
  	
  	while(item < 4)
  	{
  		System.out.println("(" + (item + 1) + ") " + menu[item] + "$" + price[item]);
  		item ++;
   	}
   	
   	System.out.println("(" + (item + 1) + ")" + menu[item]);
   	System.out.println();
   	System.out.print("Please make your selection from the menu: ");
   	choice = Integer.parseInt(input.readLine());
   	
   	return choice;
   	
  }
  
 
  	
  }
 
  public void printReceipt()throws IOException{
  	double total = 0;
  	double itemTotal = 0;
  	double subTotal;
  	double taxAmt;
  	int index = 0;
  	
  	System.out.println("Product" + "quantity" + "price");
  	
  	while (index < 3)
  		itemTotal = price[index] * Qty[index];
  		System.out.println (menu[index] + Qty[index] + itemTotal);
  		subTotal = subTotal + total;
  		index ++;
  }
  	taxAmt = calcTax (subTotal)
  	total = subTotal + taxAmt;
  	
  	System.out.println ("subTotal         " + subTotal);
  	System.out.println ("Tax              " + taxAmt);
  	System.out.println ("total            " + total);
  	
  	//begin calcTax
  	private void calcTax()throws IOException{
  	double tax;
  	doube taxRate = .07;
  	tax = subtotal * taxRate;
  	
  	return tax;
  	}
  	
  	
  	
  public static void main(String [] args) throws IOException // main method

  {
    new hotDog();//class constructor name
	  } // end the main method
} // end the program

Another tip regarding posting on forums. Try not to mix spaces and tabs. A tab on Daniweb is eight spaces. It's usually four or five spaces in most IDEs, so what lines up in an IDE like NetBeans may well not line up when you post here. Solution? Convert tabs to spaces before pasting. Most IDEs have an option where you can change tabs to spaces fairly easily.

Look at lines 96 - 112. The starting bracket is on line 96. The ending bracket is on line 110. Lines 111 and 112 are not in the printReceipt function.

I assume the while statement on line 105 is supposed to go to line 110, but there is no STARTING bracket on line 105, which I assume is an oversight?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.