Java Assignment #6

Please support our Java advertiser: Programming Forums - DaniWeb Sister Site
Reply

Join Date: Jun 2009
Posts: 5
Reputation: theCRK is an unknown quantity at this point 
Solved Threads: 0
theCRK theCRK is offline Offline
Newbie Poster

Java Assignment #6

 
0
  #1
Jun 8th, 2009
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!!!
Last edited by theCRK; Jun 8th, 2009 at 1:05 pm.
Reply With Quote Quick reply to this message  
Join Date: Jan 2008
Posts: 3,844
Reputation: VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute 
Solved Threads: 503
Featured Poster
VernonDozier VernonDozier is offline Offline
Senior Poster

Re: Java Assignment #6

 
0
  #2
Jun 8th, 2009
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.
Reply With Quote Quick reply to this message  
Join Date: Jun 2009
Posts: 5
Reputation: theCRK is an unknown quantity at this point 
Solved Threads: 0
theCRK theCRK is offline Offline
Newbie Poster

Re: Java Assignment #6

 
0
  #3
Jun 8th, 2009
  1. 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.
Reply With Quote Quick reply to this message  
Join Date: Jan 2008
Posts: 3,844
Reputation: VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute 
Solved Threads: 503
Featured Poster
VernonDozier VernonDozier is offline Offline
Senior Poster

Re: Java Assignment #6

 
0
  #4
Jun 8th, 2009
Originally Posted by theCRK View Post
  1. 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):

  1. public class HelloWorld
  2. {
  3. public static void main (String args[])
  4. {
  5. System.out.println ("Hello World");
  6. }
  7. }

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

  1. public class HelloWorld
  2. {
  3. public static void main (String args[])
  4. {
  5. System.out.println ("Hello World");
  6. }
  7. }

No code tags (looks terrible):

public class HelloWorld
{
public static void main (String args[])
{
System.out.println ("Hello World");
}
}
Reply With Quote Quick reply to this message  
Join Date: Jun 2009
Posts: 5
Reputation: theCRK is an unknown quantity at this point 
Solved Threads: 0
theCRK theCRK is offline Offline
Newbie Poster

Re: Java Assignment #6

 
0
  #5
Jun 8th, 2009
  1. Program Name: hotDog.java
  2. Date : June 7, 2009
  3. Author : Casey Kucera
  4. Desc : Assignment #6
  5. */
  6.  
  7. import java.io.*;
  8.  
  9. public class hotDog //class name here, same as file name
  10.  
  11. {
  12. // use BufferedReader class to input from the keyboard
  13. // declare a variable of type BufferedReader
  14. BufferedReader input = new BufferedReader(new InputStreamReader(System.in));
  15. //declare variable for input
  16. String inputString;
  17. String menu[] = {"Hot Dog", "Fries", "Lemonade", "End Order"};
  18. double price[] = { 1.50, 1.00, 2.25, 0.0};
  19. int Qty[] = new int[4];
  20.  
  21. public hotDog()throws IOException{//constructor, place class name here
  22.  
  23. welcome();
  24. Order();
  25. printReceipt();
  26.  
  27. }//end constructor
  28.  
  29. public void welcome(){
  30. System.out.println("Welcome to SCC's Dog's");
  31.  
  32. }
  33.  
  34. public void Order()throws IOException {
  35. int selection;
  36. do
  37. {
  38. selection = displayMenu();
  39. switch(selection)
  40. {
  41. case 1:
  42. Qty[0] = (Qty[0] + 1);
  43. break;
  44.  
  45. case 2:
  46. Qty[1] = (Qty[1] + 1);
  47. break;
  48.  
  49. case 3:
  50. Qty[2] = (Qty[2] + 1);
  51. break;
  52.  
  53. case 4:
  54. System.out.print( "Ending Order");
  55. break;
  56.  
  57. default:
  58. System.out.println("You must choose from the menu!!!!");
  59. }
  60.  
  61. }while(selection !=4);
  62.  
  63. }
  64.  
  65. public int displayMenu()throws IOException{
  66. int choice;
  67. int item = 0;
  68.  
  69. System.out.println ("(1)Hot Dog $1.50");
  70. System.out.println ("(2)Fries $1.00");
  71. System.out.println ("(3)Lemonade $2.25");
  72. System.out.println ("(4)End Order");
  73. System.out.println();
  74.  
  75. while(item < 4)
  76. {
  77. System.out.println("(" + (item + 1) + ") " + menu[item] + "$" + price[item]);
  78. item ++;
  79. }
  80.  
  81. System.out.println("(" + (item + 1) + ")" + menu[item]);
  82. System.out.println();
  83. System.out.print("Please make your selection from the menu: ");
  84. choice = Integer.parseInt(input.readLine());
  85.  
  86. return choice;
  87.  
  88. }
  89.  
  90. }
  91.  
  92. public void printReceipt()throws IOException{
  93. double total = 0;
  94. double itemTotal = 0;
  95. double subTotal;
  96. double taxAmt;
  97. int index = 0;
  98.  
  99. System.out.println("Product" + "quantity" + "price");
  100.  
  101. while (index < 3)
  102. itemTotal = price[index] * Qty[index];
  103. System.out.println (menu[index] + Qty[index] + itemTotal);
  104. subTotal = subTotal + total;
  105. index ++;
  106. }
  107. taxAmt = calcTax (subTotal)
  108. total = subTotal + taxAmt;
  109.  
  110. System.out.println ("subTotal " + subTotal);
  111. System.out.println ("Tax " + taxAmt);
  112. System.out.println ("total " + total);
  113.  
  114. //begin calcTax
  115. private void calcTax()throws IOException{
  116. double tax;
  117. doube taxRate = .07;
  118. tax = subtotal * taxRate;
  119.  
  120. return tax;
  121. }
  122.  
  123.  
  124.  
  125. public static void main(String [] args) throws IOException // main method
  126.  
  127. {
  128. new hotDog();//class constructor name
  129. } // end the main method
  130. } // end the program
Reply With Quote Quick reply to this message  
Join Date: Jun 2009
Posts: 5
Reputation: theCRK is an unknown quantity at this point 
Solved Threads: 0
theCRK theCRK is offline Offline
Newbie Poster

Re: Java Assignment #6

 
0
  #6
Jun 8th, 2009
sorry about that...this looks better now
  1. /*
  2. Program Name: hotDog.java
  3. Date : June 7, 2009
  4. Author : Casey Kucera
  5. Desc : Assignment #6
  6. */
  7.  
  8. import java.io.*;
  9.  
  10. public class hotDog //class name here, same as file name
  11.  
  12. {
  13. // use BufferedReader class to input from the keyboard
  14. // declare a variable of type BufferedReader
  15. BufferedReader input = new BufferedReader(new InputStreamReader(System.in));
  16. //declare variable for input
  17. String inputString;
  18. String menu[] = {"Hot Dog", "Fries", "Lemonade", "End Order"};
  19. double price[] = { 1.50, 1.00, 2.25, 0.0};
  20. int Qty[] = new int[4];
  21.  
  22. public hotDog()throws IOException{//constructor, place class name here
  23.  
  24. welcome();
  25. Order();
  26. printReceipt();
  27.  
  28. }//end constructor
  29.  
  30. public void welcome(){
  31. System.out.println("Welcome to SCC's Dog's");
  32.  
  33. }
  34.  
  35. public void Order()throws IOException {
  36. int selection;
  37.  
  38. do
  39. {
  40. selection = displayMenu();
  41. switch(selection)
  42. {
  43. case 1:
  44. Qty[0] = (Qty[0] + 1);
  45. break;
  46.  
  47. case 2:
  48. Qty[1] = (Qty[1] + 1);
  49. break;
  50.  
  51. case 3:
  52. Qty[2] = (Qty[2] + 1);
  53. break;
  54.  
  55. case 4:
  56. System.out.print( "Ending Order");
  57. break;
  58.  
  59. default:
  60. System.out.println("You must choose from the menu!!!!");
  61. }
  62.  
  63. }while(selection !=4);
  64.  
  65. }
  66.  
  67. public int displayMenu()throws IOException{
  68. int choice;
  69. int item = 0;
  70.  
  71. System.out.println ("(1)Hot Dog $1.50");
  72. System.out.println ("(2)Fries $1.00");
  73. System.out.println ("(3)Lemonade $2.25");
  74. System.out.println ("(4)End Order");
  75. System.out.println();
  76.  
  77. while(item < 4)
  78. {
  79. System.out.println("(" + (item + 1) + ") " + menu[item] + "$" + price[item]);
  80. item ++;
  81. }
  82.  
  83. System.out.println("(" + (item + 1) + ")" + menu[item]);
  84. System.out.println();
  85. System.out.print("Please make your selection from the menu: ");
  86. choice = Integer.parseInt(input.readLine());
  87.  
  88. return choice;
  89.  
  90. }
  91.  
  92.  
  93.  
  94. }
  95.  
  96. public void printReceipt()throws IOException{
  97. double total = 0;
  98. double itemTotal = 0;
  99. double subTotal;
  100. double taxAmt;
  101. int index = 0;
  102.  
  103. System.out.println("Product" + "quantity" + "price");
  104.  
  105. while (index < 3)
  106. itemTotal = price[index] * Qty[index];
  107. System.out.println (menu[index] + Qty[index] + itemTotal);
  108. subTotal = subTotal + total;
  109. index ++;
  110. }
  111. taxAmt = calcTax (subTotal)
  112. total = subTotal + taxAmt;
  113.  
  114. System.out.println ("subTotal " + subTotal);
  115. System.out.println ("Tax " + taxAmt);
  116. System.out.println ("total " + total);
  117.  
  118. //begin calcTax
  119. private void calcTax()throws IOException{
  120. double tax;
  121. doube taxRate = .07;
  122. tax = subtotal * taxRate;
  123.  
  124. return tax;
  125. }
  126.  
  127.  
  128.  
  129. public static void main(String [] args) throws IOException // main method
  130.  
  131. {
  132. new hotDog();//class constructor name
  133. } // end the main method
  134. } // end the program
Reply With Quote Quick reply to this message  
Join Date: Jan 2008
Posts: 3,844
Reputation: VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute 
Solved Threads: 503
Featured Poster
VernonDozier VernonDozier is offline Offline
Senior Poster

Re: Java Assignment #6

 
0
  #7
Jun 8th, 2009
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?
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:




Views: 280 | Replies: 6
Thread Tools Search this Thread



Tag cloud for Java
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC