error message:" class interface or enum expected"

error message in java programming language

Page 1 of 1

2 Replies - 4502 Views - Last Post: 21 June 2008 - 12:10 PM Rate Topic: -----

#1 javagreenhorn  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 24
  • Joined: 19-June 08

error message:" class interface or enum expected"

Post icon  Posted 21 June 2008 - 11:05 AM

Hello, I am creating a program for school called Inventory Program; I am currently on Part 3 of the program. The assignment calls for modifying the Inventory Program by creating a subclass of the product class that uses one additional unique feature of the product I chose. In the subclass I am to create a method to calculate the value of the inventory of a product with the same name as the method previously created for the product class. The subclass method should also add a 5% restocking fee to the value of the inventory of that product.

Here is what I have so far, it will build compile and run; but I have alot of error messages on the DVD extends Product page. These all say "class interface or enum expected", I have tried and tried to figure out what this means and can't find this information anywhere. Thanks for any help you can give me.


 * This program displays product information: product number, name, number of
 * units in stock, price of each unit, and the value of the inventory.
 * 
 */

package mydvdsjava;

import java.util.Scanner;

/** Inventory Program
 * IT 215
 * @author Tammy Fica
 * June 13, 2008
 */
public class MyDvds {
   
  
	//main method begins execution of Java application
	/**
	 * @param args the command line arguments
	 */
	
	public static void main(String[] args) 
	{
		//create and initialize a DVD object
		DVD dvd = new DVD(); //invokes constructor
		//create Scanner to obtain input from command window
		Scanner input = new Scanner( System.in);
		
		System.out.print("Enter product name, item number, number of units in stock, and price of each unit"); 
		// prompt for user input
		
		String title = "get this from input";
		
		double stock = 0.0; 
		double price = 0.0; 
		double item = 0.0; 
		dvd = new DVD(title, price, stock, item);
		
		System.out.println(dvd);
		
		System.out.println("Title is: " + dvd.getTitle());
		System.out.println("The item number is: " + dvd.getDVDNumber());
		System.out.println("The number of units in stock is: " + dvd.getDVDStock());
		System.out.println("The price of each unit is: " + dvd.getDVDPrice());
		System.out.println("The value of inventory is: " + dvd.inventoryValue());
  
		} //end method main
		
} //end classMyDvds



 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package mydvdsjava;


 /**
 *
 * @author Tammy
 */
 /**
 *
 * @author Tammy
 */
class DVD  {

	// fields
   
	private String dvdTitle;
	private double dvdItem;
	private double dvdStock;
	private double dvdPrice;
	
	public DVD(String title, double stock, double price, double item)
	{
	 dvdTitle = title;
	 dvdItem = item;
	 dvdStock = stock;
	 dvdPrice = price;
	} //end class DVD constructor

	DVD() {
		 this ("Unspecified", 0.0, 10.0, 0.0);
	}
	//set DVD name
	public void setDVDTitle(String title)
	{
		dvdTitle = title;
	} // end method setDVDTitle
	
	//return DVD name
	public String getDvdTitle(String title)
	{
		return dvdTitle;
	} //end method get DvdTitle
	
	//set item number
	public void setDvdItem(double item)
	{
		dvdItem = item;
	} //end method setDvdItem
	
	//return item number
	public double getDvdItem()
	{
		return dvdItem;
	} //end method getDvdItem
	
	//set number of units in stock
	public void setDvdStock (double stock)
	{
		dvdStock = stock;
	} //end method setDvdStock
	
	//return number of units in stock
	public double getDvdStock()
	{
		return dvdStock;
	} //end method getDvdStock
	
	//set price of each unit
	public void setDvdPrice (double price)
	{
		dvdPrice = price;
	} //end method setDvdPrice
   
	//return price of each unit
	public double getDvdPrice()
	{
		return dvdPrice;
	} //end method getDvdPrice
	
	//calculate inventory value
	public double inventoryValue()
	{
		return dvdPrice * dvdStock;
	} //end method inventoryValue

	String getDVDNumber() 
	   
	{   
		String DVDNumber = null;
   
	  return DVDNumber;
	}
		
	 String getDVDPrice()
	 {		
		 String DVDPrice = null;
			return DVDPrice;
  
 }
	String getDVDStock() 
	{	
		String DVDStock = null;
			return DVDStock;
	}
		
	
	String getTitle() 
	{   
		String DVDTitle = null;
			return DVDTitle;
	}
	
	}
	//end class DVD
		  


/* 
 * 
 */
// Import class to format values into currency
	import java.text.DecimalFormat;
/** 
 * 
 * @author Tammy
 */

public class Inventory {
	// Set up an array 0f Products
	int inventorySize = 30;
	private Product items[] = new Product[inventorySize];
	
	// Set formatter to format values into currency 
	DecimalFormat formatter = new DecimalFormat("$###,###.00");
	private int InventorySize;

	// Add a product to array, adds to first empty slot found
	private void addProduct (Product Item) {
		Product item = null;
		
	 for (int i = 0; i< inventorySize; i++){
			if (items[i] == null) {
				items[i] = item; 
				return; 
			}
	 }
	}
 
	/* Loop through array and add up the total value
	* Add quantity on hand and multiply by its price
	* Add the value to a running total
	*/
 
	public double getTotalInvValue(){
		double sumOfInventory = 0.0;
		
		for (Product item : items) {
		   
			// Make sure there is an item
			if (item != null) {
				sumOfInventory += item.getItemValue();
			}
		}
		return sumOfInventory;
	}
	
	// Prints inventory list with; name, quantity, price, and total stock value for each item.
	public void printInventory() {
		System.out.println("Printing items in inventory...\n");
		
		boolean hasItems = false;
		
		for (Product item : items) {
			if (item!= null)  {
				hasItems = true; 
				  System.out.println("Inventory is currently empty.\n"); 
			}
		 }
	 }
}		
		
		   
			   
   
	  * @author Tammy
 */
class DVD extends Product {
	
	private String name;
	private int quantity;
	private double price;
	private int productid = 0;
	private int movieyear;
	
}
	public DVD(int productId, String itemname, quantityOnHand, itemprice); {
	
		this (0,"Unknown", 0, 0.00);
   
   
	// Constructor to specify name, quantity, and price for items
	public Product (int productId, String itemname, int quantityOnHand, double itemprice){
	   super(productId, itemname, quantityOnHand, itemprice);
			movie year = year;
	
	
		productid = productId;
		setName (itemname);
		setQuantityOnHand (quantityOnHand);
		setPrice (itemprice);
   
	
	
	// Set the year manually
	public void setYear(int year){
		movieyear = year;
	}
   
	// Get the year of DVD
	public int getYear() {
		return movieyear;
	}
	
	// Override getItemValue()in Product Class and adds on 5% restocking fee
	public double getItemValue() {
		return super.getItemValue() * 1.05;
	}
	
	// Get base class value and figure out restocking fee
	public double getRestockingFee() {
		return super.getItemValue() * .05;
	
	}
		public void setName(String itemname) {
		name = itemname;
		}  
	// Sets quantity on hand and defaults to zero, if negative
	public void setQuantityOnHand (int quantityOnHand) {
		if (quantityOnHand > 0) {
			quantity = quantityOnHand;
			
		else { quantity = 0; }
		
	}
	// Set price of product and default to zero if negative
	public void setPrice (double itemPrice) {
		if (itemPrice > 0.00) {
			price = itemPrice;
			}
		else { price = 0.00; }
		
	}
	
	// Get product name
	public String getName() {
		return name;
	   
	}
	public int getQuantityOnHand() {
		return quantity;
		
	
	}
	public double getPrice() {
		return price;
	}
	// Calculate value of stock on this item
	public double getItemValue() {
		return (price * (double)quantity);
 
	}
	@Override
	public String toString() {
		return name + "-" + price;
	
	}
	}
	
	
	
	
 


Is This A Good Question/Topic? 0
  • +

Replies To: error message:" class interface or enum expected"

#2 pbl  Icon User is offline

  • There is nothing you can't do with a JTable
  • member icon

Reputation: 8324
  • View blog
  • Posts: 31,857
  • Joined: 06-March 08

Re: error message:" class interface or enum expected"

Posted 21 June 2008 - 11:22 AM

You cannot have at the same time a:

class DVD
and a
class DVD extends Poduct

how do you manage to have 2 DVD.java in the same directory ?
Was This Post Helpful? 0
  • +
  • -

#3 javagreenhorn  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 24
  • Joined: 19-June 08

Re: error message:" class interface or enum expected"

Posted 21 June 2008 - 12:10 PM

I don't have a clue how I managed this. I am lost in this class. I know one thing is for sure, I will be changing my area for my bachelor degree because I am not getting this Java language.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1