| | |
interface, or enum expected errors
Please support our Java advertiser: Programming Forums - DaniWeb Sister Site
![]() |
•
•
Join Date: Mar 2007
Posts: 2
Reputation:
Solved Threads: 0
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
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)
//Inventory2.java //Program to display inventory information on multiple items //Modified February 12, 2007 //Jeannie Pierce import java.util.*; class Product implements Comparable { private String name; // class variable that stores the item name private double number; // class variable that stores the item number private long stockQuantity; // class variable that stores the quantity in stock private double price; // class variable that stores the item price public Product() // Constructor for the Product class { name = ""; number = 0.0; stockQuantity = 0L; price = 0.0; } public Product(String name, int number, long stockQuantity, double price) // Constructor for the Supplies class { this.name = name; this.number = number; this.stockQuantity = stockQuantity; this.price = price; } public void setItemName(String name) // Method to set the item name { this.name = name; } public String getItemName() // Method to get the item name { return name; } public void setItemNumber(double number) // Method to set the item number { this.number = number; } public double getItemNumber() // Method to get the item number { return number; } public void setStockQuantity(long quantity) // Method to set the quantity in stock { stockQuantity = quantity; } public long getStockQuantity() // Method to get the quantity in stock { return stockQuantity; } public void setItemPrice(double price) // Method to set the item price { this.price = price; } public double getItemPrice() // Method to get the item price { return price; } public double calculateInventoryValue() // Method to calculate the value of the inventory { return price * stockQuantity; } public int compareTo (Object o) { Product s = (Product)o; return name.compareTo(s.getItemName()); } public String toString() { return "Name: "+name + "\nNumber: "+number+"\nPrice: $"+price+"\nQuantity: "+stockQuantity + "\nValue: $"+calculateInventoryValue(); } }//end class Product public class Inventory2 { // main methods begins execution of java application public static void main( String args[]) { Product[] supplies = new Product[3]; Product p1 = new Product("DVD", 02571, 167, 1500); Product p2 = new Product("CDs", 02572, 10, 1200); Product p3 = new Product("DVDRs", 02573, 17, 1600); supplies[0] = p1; supplies[1] = p2; supplies[2] = p3; double total = 0.0; for(int i= 0; i < 3;i++) { total = total + supplies[i].calculateInventoryValue(); } System.out.println("Total Value is: $"+total); Arrays.sort(supplies); for(Product s: supplies) { System.out.println(s); System.out.println(); } } // end main method }//end class Inventory2 System.out.printf("\n\nItem Name: %s\n",s.getItemName()); //display item name System.out.printf("Item Number: %s\n",s.getItemNumber()); //display item number System.out.printf("Quantity in Stock: %s\n",s.getStockQuantity()); //display quantity in stock System.out.printf("Item Price: $%.2f\n",s.getItemPrice()); //display item price System.out.printf("Value of Inventory: $%.2f\n",s.calculateInventoryValue()); //display total value of inventory for this item System.out.println("\n\nEnter item name or enter the word stop to quit: ");//prompt mySupplies.setItemName(input.next()); // read item name or stop
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.
Java Programmer and Sun Systems Administrator
----------------------------------------------
Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it.
--Brian Kernighan
----------------------------------------------
Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it.
--Brian Kernighan
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.
As people are clearly allowed to attack me but I'm not allowed to defend myself, I no longer post to this site.
Show more of your code.
Edit:
And use code tags, and start your own thread rather than hijacking an old one.
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.
Java Programmer and Sun Systems Administrator
----------------------------------------------
Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it.
--Brian Kernighan
----------------------------------------------
Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it.
--Brian Kernighan
![]() |
Similar Threads
- card game (Java)
- expected error on homepage (HTML and CSS)
- Help (Java)
- Java Multidimensional Arrays (Java)
Other Threads in the Java Forum
- Previous Thread: Help with run time error
- Next Thread: displaying time
| Thread Tools | Search this Thread |
2dgraphics account android api apple applet application array arrays automation banking binary binarytree bluetooth chat chatprogramusingobjects class classes client code component data database derby design draw eclipse encryption error event exception fractal game givemetehcodez graphics gui html ide if_statement image inheritance input integer interface j2me java javadesktopapplications javaprojects jlabel jni jpanel jtextfield julia linux list loop map method methods midlethttpconnection mobile monitoring netbeans newbie nullpointerexception open-source oracle print printing problem program programming project property recursion reference ria scanner screen search server set size sms sort sourcelabs splash sql static stop string swing testautomation threads time tree ui unicode validation windows






