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

//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

Recommended Answers

All 8 Replies

why do you have statements outside any method?

Read some extreme beginner's tutorial.

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.

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.

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.

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

Thanks, Evandro

Show more of your code.

Edit:

And use code tags, and start your own thread rather than hijacking an old one.

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!

commented: yeah right - like you've ever spent time helping streams of idiots "mr 1-posting driveby" -4

Don't ressurect old threads with useless posts.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.