944,147 Members | Top Members by Rank

Ad:
  • Java Discussion Thread
  • Unsolved
  • Views: 45797
  • Java RSS
You are currently viewing page 1 of this multi-page discussion thread
Mar 26th, 2006
0

JAVA Illegal Start of Expression Error

Expand Post »
Could someone please help me out. I have an illegal start of an expression error at line 8 in the following code.

Java Syntax (Toggle Plain Text)
  1. package untitled5;
  2.  
  3. public class Untitled1 {
  4. public static void main(String[] args) {
  5.  
  6.  
  7.  
  8. public static void main(String[] args) {
  9. int start_system, add_modify, add_modify_animal_data, report,
  10. exit_system;
  11. int check = menu();
  12. while (check != 4) {
  13. if (check == 1) {
  14. add_modify_data();
  15. }
  16. else
  17. if (check == 2) {
  18. add_modify_medical_data();
  19. }
  20. else
  21. if (check == 3) {
  22. report();
  23. }
  24. check = menu();
  25. }
  26.  
  27. exit_system();
  28. System.exit(0);
  29. }
  30.  
  31. {
  32. public static void start_system() {
  33. System.out.println("Start_system now");
  34. }
  35. }
  36. //sets up the output
  37. public static int menu() {
  38. int check;
  39. String output = "Modify Animal Data" + "\n " +
  40. "1. Add/Modify Animal Data " + "\n" +
  41. "2. Add/modify Meical Data " + "\n" +
  42. "3. Report Section " + "\n" +
  43. "4. Exit " + "\n " + "\n " + " Enter Your Selection:";
  44. String scheck = JOptionPane.showInputDialog(null, output, " ",
  45. JOptionPane.QUESTION_MESSAGE);
  46. check = Integer.parseInt(scheck);
  47. return check;
  48. }
  49. public static void add_modify() {
  50. int check1;
  51. while (check1 != 4) {
  52. if (check1 == 1) {
  53. add_animal_data();
  54. }
  55. else
  56. if (check1 == 2) {
  57. delete_animal_data();
  58. }
  59. else
  60. if (check1 == 3) {
  61. change_animal_data();
  62.  
  63. }
  64. check1 = menu();
  65.  
  66. }
  67. exit_system();
  68. System.exit(0);
  69. String output = "Modify Animal Data " + "\n " +
  70. "1. Add Animal Data " + "\n" +
  71. "2. Modify Animal Data " + "\n" +
  72. "3. Change Animal Data " + "\n" +
  73. "4. Exit " + "\n " + "\n " + " Enter Your Selection:";
  74. String scheck = JOptionPane.showInputDialog(null, output, " ",
  75. JOptionPane.QUESTION_MESSAGE);
  76. check1 = Integer.parseInt(scheck);
  77. }
  78. public static void add_modify_medical_data() {
  79. int check2;
  80. while (check2 != 4) {
  81. if (check2 == 1) {
  82. add_medical();
  83.  
  84. }
  85. else
  86. if (check2 == 2) {
  87. delete_medical();
  88.  
  89. }
  90. else
  91. if (check2 == 3) {
  92. change_medical();
  93.  
  94. }
  95. check2 = menu();
  96.  
  97. }
  98. exit_system();
  99. System.exit(0);
  100. String output = "Modify Medical Data " + "\n " +
  101. "1. Add Medical Data " + "\n" +
  102. "2. Modify Medical Data " + "\n" +
  103. "3. Change Change Data " + "\n" +
  104. "4. Exit " + "\n " + "\n " + " Enter Your Selection:";
  105. String scheck = JOptionPane.showInputDialog(null, output, " ",
  106. JOptionPane.QUESTION_MESSAGE);
  107. check2 = Integer.parseInt(scheck);
  108. }
  109. public static void report() {
  110. System.out.println("in Report");
  111. }
  112. public static void exit_system() {
  113. System.out.println("in exit system");
  114. };
  115.  
  116. }
  117. }



Thank you
Last edited by peter_budo; Aug 25th, 2011 at 6:31 am. Reason: Adding code tags to old post
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
lrw0831 is offline Offline
2 posts
since Mar 2006
Mar 26th, 2006
0

Re: JAVA Illegal Start of Expression Error

of course you do.

You're trying to declare a method inside of a method.

Remove the first public static void main method and then a ending } near the bottom of your code and that should help you out some.

Also, you have an extra ; at the end of your exit_system method.
Reputation Points: 11
Solved Threads: 8
Posting Whiz in Training
hooknc is offline Offline
216 posts
since Aug 2005
Mar 26th, 2006
0

Re: JAVA Illegal Start of Expression Error

I am getting the same error message except now it is at line 29
Reputation Points: 10
Solved Threads: 0
Newbie Poster
lrw0831 is offline Offline
2 posts
since Mar 2006
Mar 27th, 2006
0

Re: JAVA Illegal Start of Expression Error

of course you are.

You really need to check your combination of open and close brackets. You must have an equal amout of both and you must fallow the java rules for declaration of attributes and methods.

I would recommend picking up a basic java book to learn these rules.

[offtopic]
Arn't the smiles here about the most evil things you've ever seen? The normal smile looks like he just took you for all you're worth.
[/offtopic]
Reputation Points: 11
Solved Threads: 8
Posting Whiz in Training
hooknc is offline Offline
216 posts
since Aug 2005
Mar 27th, 2006
0

Re: JAVA Illegal Start of Expression Error

Quote originally posted by hooknc ...
of course you are.

You really need to check your combination of open and close brackets. You must have an equal amout of both and you must fallow the java rules for declaration of attributes and methods.

I would recommend picking up a basic java book to learn these rules.

[offtopic]
Arn't the smiles here about the most evil things you've ever seen? The normal smile looks like he just took you for all you're worth.
[/offtopic]
True it's more like a condescending smirk, I don't care tho... I like to antognise people...it's fun either way.
Featured Poster
Reputation Points: 1536
Solved Threads: 431
Posting Expert
iamthwee is offline Offline
5,865 posts
since Aug 2005
Jun 11th, 2007
0

hi..

hi can anyone help me please. I'm having problem with my program. It's only one error illegal starts of expression in public void check (), at line 53. What it is mean?..


Java Syntax (Toggle Plain Text)
  1. import javax.swing.JOptionPane;
  2. //public class waiter{
  3. //public static void main(String [] args)
  4. class waiter
  5.  
  6.  
  7. {
  8. private double tab;
  9. public waiter(String name);
  10. {
  11. System.out.println("My name is "+ name +", and i'll be your waiter!");
  12. tab = 0.0;
  13. }
  14. public double priceof(String s);
  15. {
  16. double price;
  17. if (s.equals("Chicken"))
  18. {price = 5.95;}
  19. else
  20. {//burger fries
  21. if (s.equals("burger"))
  22. {price = 4.95; }
  23. else
  24. {price = 1.95;}
  25.  
  26. }//burger or fries
  27. return price;
  28. }//priceof
  29. public void order(String s)
  30. {
  31. if(s.equals("Chicken"))
  32. {
  33. tab = tab + 5.95;
  34. }// burger fries
  35. else
  36. {//burger fries
  37. if (s.equals("Burger"))
  38. {
  39. tab = tab + 4.95;
  40. }
  41. else
  42. {
  43. tab = tab + 1.95;
  44. }
  45. }//price of
  46.  
  47. public void check()
  48. {
  49. System.out.println("Please pay $" + tab+",null");
  50. }
  51.  
  52. }//end of class waiter
  53. public class objects3
  54. {
  55. public static void main(String [] args)
  56. {
  57. waiter ourwaiter;
  58. ourwaiter = new waiter ("Manfred");// makes a waiter object
  59. double x; //to hold price of burger
  60. double y; //varikable to hold price of chicken
  61. x = ourwaiter.priceof("burger");
  62. y = ourwaiter.priceof("chicken");
  63. if (x<y)// buy cheaper product
  64. {
  65. System.out.println("I'll take the burger because it's cheaper");
  66. ourwaiter.order("Burger");
  67. }//burger
  68. else
  69. {
  70. System.out.println("I'll take the chicken. ");
  71. ourwaiter.order("chicken");
  72. }//chicekn
  73. System.out.println("And i'll have fries with that");
  74. ourwaiter.oreder("Fries");
  75. System.out.println("\n eat eat....\n");
  76.  
  77. ourwaiter.check();
  78. }//main
  79. }//class objects3
Last edited by peter_budo; Aug 25th, 2011 at 6:31 am. Reason: Adding code tags to old post
Reputation Points: 10
Solved Threads: 0
Newbie Poster
j3p0yz is offline Offline
9 posts
since Jun 2007
Jun 12th, 2007
0

Re: JAVA Illegal Start of Expression Error

use code tags if you want people to read your code.
And don't go hijacking other peoples' threads, not even old ones like this.
Team Colleague
Reputation Points: 1658
Solved Threads: 331
duckman
jwenting is offline Offline
7,719 posts
since Nov 2004
Jun 12th, 2007
0

Re: JAVA Illegal Start of Expression Error

i'm sory i don't know where to type my program. i'm very sory..
Reputation Points: 10
Solved Threads: 0
Newbie Poster
j3p0yz is offline Offline
9 posts
since Jun 2007
Jun 12th, 2007
0

Re: JAVA Illegal Start of Expression Error

h..i can anyone help me please. I'm having problem with this program. It's only one error illegal starts of expression in public void check (), at line 53. What it is mean?..


Java Syntax (Toggle Plain Text)
  1. import javax.swing.JOptionPane;
  2.  
  3. class waiter
  4.  
  5.  
  6. {
  7. private double tab;
  8. public waiter(String name);
  9. {
  10. System.out.println("My name is "+ name +", and i'll be your waiter!");
  11. tab = 0.0;
  12. }
  13. public double priceof(String s);
  14. {
  15. double price;
  16. if (s.equals("Chicken"))
  17. {price = 5.95;}
  18. else
  19. {//burger fries
  20. if (s.equals("burger"))
  21. {price = 4.95; }
  22. else
  23. {price = 1.95;}
  24.  
  25. }//burger or fries
  26. return price;
  27. }//priceof
  28. public void order(String s)
  29. {
  30. if(s.equals("Chicken"))
  31. {
  32. tab = tab + 5.95;
  33. }// burger fries
  34. else
  35. {//burger fries
  36. if (s.equals("Burger"))
  37. {
  38. tab = tab + 4.95;
  39. }
  40. else
  41. {
  42. tab = tab + 1.95;
  43. }
  44. }//price of
  45.  
  46. public void check()
  47. {
  48. System.out.println("Please pay $" + tab+",null");
  49. }
  50.  
  51. }
  52. public class objects3
  53. {
  54. public static void main(String [] args)
  55. {
  56. waiter ourwaiter;
  57. ourwaiter = new waiter ("Manfred");// makes a waiter object
  58. double x;
  59. double y;
  60. x = ourwaiter.priceof("burger");
  61. y = ourwaiter.priceof("chicken");
  62. if (x<y)// buy cheaper product
  63. {
  64. System.out.println("I'll take the burger because it's cheaper");
  65. ourwaiter.order("Burger");
  66. }
  67. else
  68. {
  69. System.out.println("I'll take the chicken. ");
  70. ourwaiter.order("chicken");
  71. }
  72. System.out.println("And i'll have fries with that");
  73. ourwaiter.oreder("Fries");
  74. System.out.println("\n eat eat....\n");
  75.  
  76. ourwaiter.check();
  77. }
  78. }
Last edited by peter_budo; Aug 25th, 2011 at 6:32 am. Reason: Adding code tags to old post
Reputation Points: 10
Solved Threads: 0
Newbie Poster
j3p0yz is offline Offline
9 posts
since Jun 2007
Jun 12th, 2007
0

Re: JAVA Illegal Start of Expression Error

As Jwenting mentioned, you need to start a new thread with your question and place your code between code tags to make it more readable. See the post at the top of the forum about code tags.

An illegal start of expression means that you have misformatted your code and it cannot be parsed correctly. This would include things like missing braces or parens, declaring a method within a method, missing semi-colon, etc.
Moderator
Featured Poster
Reputation Points: 3239
Solved Threads: 839
Posting Genius
Ezzaral is offline Offline
6,761 posts
since May 2007

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
This thread is currently closed and is not accepting any new replies.
Previous Thread in Java Forum Timeline: Priority Queue..
Next Thread in Java Forum Timeline: how do you use bucket sort to sort a list of strings?





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC