944,181 Members | Top Members by Rank

Ad:
  • Java Discussion Thread
  • Unsolved
  • Views: 24550
  • Java RSS
Mar 28th, 2007
0

interface, or enum expected errors

Expand Post »
I keep geting the following errors for my code while compilling can any one give me some dirrection on wha i have done wrong?


C:\Documents and Settings\Mark Standerfer.DESKTOP\My Documents\Inventory2.java:117: class, interface, or enum expected
System.out.printf("\n\nItem Name: %s\n",s.getItemName()); //display item name
^
C:\Documents and Settings\Mark Standerfer.DESKTOP\My Documents\Inventory2.java:118: class, interface, or enum expected
System.out.printf("Item Number: %s\n",s.getItemNumber()); //display item number
^
C:\Documents and Settings\Mark Standerfer.DESKTOP\My Documents\Inventory2.java:119: class, interface, or enum expected
System.out.printf("Quantity in Stock: %s\n",s.getStockQuantity()); //display quantity in stock
^
C:\Documents and Settings\Mark Standerfer.DESKTOP\My Documents\Inventory2.java:120: class, interface, or enum expected
System.out.printf("Item Price: $%.2f\n",s.getItemPrice()); //display item price
^
C:\Documents and Settings\Mark Standerfer.DESKTOP\My Documents\Inventory2.java:121: class, interface, or enum expected
System.out.printf("Value of Inventory: $%.2f\n",s.calculateInventoryValue()); //display total value of inventory for this item
^
C:\Documents and Settings\Mark Standerfer.DESKTOP\My Documents\Inventory2.java:122: class, interface, or enum expected
System.out.println("\n\nEnter item name or enter the word stop to quit: ");//prompt
^
C:\Documents and Settings\Mark Standerfer.DESKTOP\My Documents\Inventory2.java:123: class, interface, or enum expected
mySupplies.setItemName(input.next()); // read item name or stop

Java Syntax (Toggle Plain Text)
  1. //Inventory2.java
  2. //Program to display inventory information on multiple items
  3. //Modified February 12, 2007
  4. //Jeannie Pierce
  5. import java.util.*;
  6. class Product implements Comparable
  7. {
  8. private String name; // class variable that stores the item name
  9. private double number; // class variable that stores the item number
  10. private long stockQuantity; // class variable that stores the quantity in stock
  11. private double price; // class variable that stores the item price
  12. public Product() // Constructor for the Product class
  13. {
  14. name = "";
  15. number = 0.0;
  16. stockQuantity = 0L;
  17. price = 0.0;
  18. }
  19. public Product(String name, int number, long stockQuantity, double price) // Constructor for the Supplies class
  20. {
  21. this.name = name;
  22. this.number = number;
  23. this.stockQuantity = stockQuantity;
  24. this.price = price;
  25. }
  26. public void setItemName(String name) // Method to set the item name
  27. {
  28. this.name = name;
  29. }
  30. public String getItemName() // Method to get the item name
  31. {
  32. return name;
  33. }
  34. public void setItemNumber(double number) // Method to set the item number
  35. {
  36. this.number = number;
  37. }
  38. public double getItemNumber() // Method to get the item number
  39. {
  40. return number;
  41. }
  42. public void setStockQuantity(long quantity) // Method to set the quantity in stock
  43. {
  44. stockQuantity = quantity;
  45. }
  46. public long getStockQuantity() // Method to get the quantity in stock
  47. {
  48. return stockQuantity;
  49. }
  50. public void setItemPrice(double price) // Method to set the item price
  51. {
  52. this.price = price;
  53. }
  54. public double getItemPrice() // Method to get the item price
  55. {
  56. return price;
  57. }
  58. public double calculateInventoryValue() // Method to calculate the value of the inventory
  59. {
  60. return price * stockQuantity;
  61. }
  62. public int compareTo (Object o)
  63. {
  64. Product s = (Product)o;
  65. return name.compareTo(s.getItemName());
  66. }
  67. public String toString()
  68. {
  69. return "Name: "+name + "\nNumber: "+number+"\nPrice: $"+price+"\nQuantity: "+stockQuantity + "\nValue: $"+calculateInventoryValue();
  70. }
  71. }//end class Product
  72. public class Inventory2
  73. {
  74. // main methods begins execution of java application
  75. public static void main( String args[])
  76. {
  77. Product[] supplies = new Product[3];
  78. Product p1 = new Product("DVD", 02571, 167, 1500);
  79. Product p2 = new Product("CDs", 02572, 10, 1200);
  80. Product p3 = new Product("DVDRs", 02573, 17, 1600);
  81. supplies[0] = p1;
  82. supplies[1] = p2;
  83. supplies[2] = p3;
  84. double total = 0.0;
  85. for(int i= 0; i < 3;i++)
  86. {
  87. total = total + supplies[i].calculateInventoryValue();
  88. }
  89. System.out.println("Total Value is: $"+total);
  90. Arrays.sort(supplies);
  91. for(Product s: supplies)
  92. {
  93. System.out.println(s);
  94. System.out.println();
  95. }
  96. } // end main method
  97. }//end class Inventory2
  98.  
  99. System.out.printf("\n\nItem Name: %s\n",s.getItemName()); //display item name
  100. System.out.printf("Item Number: %s\n",s.getItemNumber()); //display item number
  101. System.out.printf("Quantity in Stock: %s\n",s.getStockQuantity()); //display quantity in stock
  102. System.out.printf("Item Price: $%.2f\n",s.getItemPrice()); //display item price
  103. System.out.printf("Value of Inventory: $%.2f\n",s.calculateInventoryValue()); //display total value of inventory for this item
  104. System.out.println("\n\nEnter item name or enter the word stop to quit: ");//prompt
  105. mySupplies.setItemName(input.next()); // read item name or stop
Attached Files
File Type: java Inventory2.java (3.6 KB, 51 views)
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
yohanus is offline Offline
2 posts
since Mar 2007
Mar 28th, 2007
0

Re: interface, or enum expected errors

why do you have statements outside any method?

Read some extreme beginner's tutorial.
Team Colleague
Reputation Points: 1658
Solved Threads: 331
duckman
jwenting is offline Offline
7,719 posts
since Nov 2004
Mar 28th, 2007
-1

Re: interface, or enum expected errors

Click to Expand / Collapse  Quote originally posted by jwenting ...
why do you have statements outside any method?

Read some extreme beginner's tutorial.
I guess I made a mistake in asking for help here in the first place never mind Ill find some one else to help me you did not have to treet me like Im a stupid little kid.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
yohanus is offline Offline
2 posts
since Mar 2007
Mar 29th, 2007
0

Re: interface, or enum expected errors

Those were valid statements. A forum is not the place to learn a language from the ground up. It just isn't the right medium. Go to Sun's Tutorials web site and do the tutorials, from top to bottom, starting with Getting Started.
Moderator
Reputation Points: 1471
Solved Threads: 490
Industrious Poster
masijade is offline Offline
4,043 posts
since Feb 2006
Mar 29th, 2007
1

Re: interface, or enum expected errors

correct. If you can't stand any criticism at all and expect to be spoonfed everything by someone holding your hand, you should not look for it online but hire an extremely thick skinned private tutor.
Team Colleague
Reputation Points: 1658
Solved Threads: 331
duckman
jwenting is offline Offline
7,719 posts
since Nov 2004
Mar 3rd, 2008
0

Re: interface, or enum expected errors

What's mean this error:
test.java:23: class, interface, or enum expected
import b;

Thanks, Evandro
Reputation Points: 10
Solved Threads: 0
Newbie Poster
esstein is offline Offline
1 posts
since Mar 2008
Mar 3rd, 2008
0

Re: interface, or enum expected errors

Show more of your code.

Edit:

And use code tags, and start your own thread rather than hijacking an old one.
Last edited by masijade; Mar 3rd, 2008 at 5:14 am. Reason: I'm an idiot.
Moderator
Reputation Points: 1471
Solved Threads: 490
Industrious Poster
masijade is offline Offline
4,043 posts
since Feb 2006
Apr 22nd, 2010
-2
Re: interface, or enum expected errors
What a useless post. What hateful nerds chasing people away for asking questions. I bet they don't even know how to use a computer, and FOR SURE they can't answer this guys questions. GROW UP PEOPLE. The forums are the place for these questions. Lets get these under accomplished geeks with nothing to offer OFF THE FORUMS!
Reputation Points: 6
Solved Threads: 0
Newbie Poster
righteous1 is offline Offline
1 posts
since Apr 2010
Apr 22nd, 2010
0
Re: interface, or enum expected errors
Don't ressurect old threads with useless posts.
Moderator
Reputation Points: 1471
Solved Threads: 490
Industrious Poster
masijade is offline Offline
4,043 posts
since Feb 2006

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: for loop
Next Thread in Java Forum Timeline: Binary Search Tree question





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


Follow us on Twitter


© 2011 DaniWeb® LLC