| | |
Java Assignment #6
Please support our Java advertiser: Programming Forums - DaniWeb Sister Site
![]() |
•
•
Join Date: Jun 2009
Posts: 5
Reputation:
Solved Threads: 0
•
•
•
•
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.
assign6 java.doc
•
•
•
•
this is the assignment that i am trying to finish up
•
•
•
•
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!!!
Last edited by theCRK; Jun 8th, 2009 at 1:05 pm.
•
•
Join Date: Jan 2008
Posts: 3,844
Reputation:
Solved Threads: 503
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.
[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.
•
•
Join Date: Jun 2009
Posts: 5
Reputation:
Solved Threads: 0
Java Syntax (Toggle Plain Text)
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.
•
•
Join Date: Jan 2008
Posts: 3,844
Reputation:
Solved Threads: 503
•
•
•
•
Java Syntax (Toggle Plain Text)
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.
[code=JAVA]
// code here
[/code]
or
[code]
// code here
[/code]
Here's an example.
Java-specific code tags (indentation, syntax highlighting, line numbers):
JAVA Syntax (Toggle Plain Text)
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)
Java Syntax (Toggle Plain Text)
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");
}
}
•
•
Join Date: Jun 2009
Posts: 5
Reputation:
Solved Threads: 0
JAVA Syntax (Toggle Plain Text)
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
•
•
Join Date: Jun 2009
Posts: 5
Reputation:
Solved Threads: 0
•
•
•
•
sorry about that...this looks better now
JAVA Syntax (Toggle Plain Text)
/* 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
•
•
Join Date: Jan 2008
Posts: 3,844
Reputation:
Solved Threads: 503
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?
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?
![]() |
Similar Threads
- getting errors in java for an assignment (Java)
- Help with one part of a Java college class assignment. (Java)
- Java Assignment Help Needed!!!!!!!!!! (Java)
- Assignment on java 2 j2sdk1.4.2_04 (Java)
- Java assignment help :/ (Java)
- Help: need feedback on my Java assignment about thread sleep. It's already coded. (Java)
- New to Java, please help with first Assignment (Java)
Other Threads in the Java Forum
- Previous Thread: client server communication
- Next Thread: Calculator (value of an arithmetic expression)
Views: 280 | Replies: 6
| Thread Tools | Search this Thread |
Tag cloud for Java
3d @param affinetransform android api apple applet application arc arguments array arrays automation binary bluetooth byte c# chat class classes click client code compare component corrupted database detection draw eclipse error event exception file fractal game givemetehcodez graphics gui guitesting helpwithhomework html ide image input integer j2me java java.xls javaprojects jmf jni jpanel julia keytool linux list loop map method methods mobile netbeans newbie number object oracle os pong print problem producer program programming project projectideas read recursion reflection replaysolutions rim scanner screen server set size sms socket sort sql string swing terminal test threads time transfer tree web windows






