3 Replies - 350 Views - Last Post: 29 November 2009 - 08:31 PM Rate Topic: -----

#1 atherton23  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 43
  • Joined: 18-November 09

Dont understand errors!

Post icon  Posted 29 November 2009 - 08:10 PM

I am having trouble understanding what my errors are and why I cant fix them. This program is the Inventory program that I am sure every one has viewed before. My errors are marked.
public class Main {

	/**
	 * @param args the command line arguments
	 */

	public void main(String[] args) {
		// TODO code application logic here


		String cdName;
		double cdItemnumber;
		double cdStock = 0;
		double cdPrice = 0;

		CD[] CD = new CD[100];

			CD bush = new CD("Bush", 1, 10, 10.99);
			System.out.println();
			CD acdc = new CD("ACDC", 2, 12, 12.99);
			System.out.println();
			CD creed = new CD("Creed", 3, 4, 9.99);
			System.out.println();
			CD korn = new CD("Korn", 4, 7, 14.99);
			System.out.println();

		acdc.showInventory();
			System.out.println();

		bush.showInventory();
			System.out.println();

		creed.showInventory();
			System.out.println();

		korn.showInventory();
			System.out.println();

		for (int i = 0; i<args.length; i++)
			System.out.println(args[i] + ",");

		double array[] = {109.90, 155.88, 39.96, 104.93};
		double total = 0;

		for (int counter = 0; counter < array.length; counter++)
			total += array[counter];

		System.out.println();
		System.out.printf("Total inventory value is: $%.2f\n", total);
		System.out.println();


		} // end public main



	class CD
	{
	private String cdName;
	private double itemNumber;
	private double unitsInStock;
	private double unitPrice;

	public CD(String itemName, double cdNumber, double unitsInStock, double unitPrice)
	{
	 this.cdName = itemName;
	 this.itemNumber = cdNumber;
	 this.unitsInStock = unitsInStock;
	 this.unitPrice = unitPrice;
	}

	 public String getItemName()
	 {
		  return this.cdName;
	 }

	 public double getItemNumber()
	 {
		  return this.itemNumber;
	 }

	 public double getStockNumbers()
	 {
		  return this.unitsInStock;
	 }

	 public double getPrice()
	 {
		  return this.unitPrice;
	 }

	 public double computeInventoryValue()
	 {
		  return this.unitsInStock * unitPrice;
	 }


	public void showInventory()
	{
		System.out.println("CD item number: " +itemNumber);
		System.out.println("CD Name: " +cdName);
		System.out.println("Number of Units: "+unitsInStock);
		System.out.println("Price: "+unitPrice);
		System.out.printf("Inventory Value of "+cdName+" is = $%.2f\n", computeInventoryValue());

	}

  
	class genre
	{
		private String cdGenre;
		String genre;

		genre(String itemName, double cdNumber, double unitsInStock, double unitPrice )
		{
			super(itemName, cdNumber, unitsInStock, unitPrice);  [color=#FF0000]***********error*********** [/color] 
			cdGenre = genre;
		}

		public void setGenre ( String genre)
		{
			this.cdGenre = genre;
		}

		public String getGenre()
		{
			return cdGenre;
		}

		public double getValue()
		{
			return super.computeInventoryValue() * 1.05; ********Error********* - can not find symbol computeInventoryValue 
		}

		public double getReStockingFee()
		{
			return super.computeInventoryValue() * .05; ********Error********* - can not find symbol computeInventoryValue 
		}

	@Override
		public String toString()
		{
			String formatString = "Genre:  %s";
			formatString += "Restocking Fee:  $%.2f";
			formatString = String.format(formatString, cdGenre, super.computeInventoryValue() * 0.05); ********Error********* - can not find symbol computeInventoryValue 
			return( formatString + super.toString() );
		}

		public void showInvwentory()
		{
			super.showInventory(); ********Error********* - can not find symbol showInventory
			System.out.println( toString());
			System.out.println( "Genre: "+cdGenre);
			System.out.printf("\nInventory value of "+cdGenre+" is = $%.2f\n", getReStockingFee() );
		}

	  }

	}
	
  }


I cant seem to use method computeInventoryValue and showInventory, however they are used earlier in the program. Any suggestions? I am also not understanding my errors with super()?
Any feedback is greatly appreciated.


You might have to move the code tab over to see where my errors are marked.
Thanks

Is This A Good Question/Topic? 0
  • +

Replies To: Dont understand errors!

#2 Dogstopper  Icon User is online

  • The Ninjaducky
  • member icon



Reputation: 2860
  • View blog
  • Posts: 10,964
  • Joined: 15-July 08

Re: Dont understand errors!

Posted 29 November 2009 - 08:20 PM

You call the line:
super.showInventory();



The super keyword activates a certain method or references a variable in the superclass. Well, your class is Main, and it does not explicitly subclass anything in particular. If you do not specify, it subclasses Object and object has no method called showInventory().

To extend another class, do it like this.
class Main extends AClassName {

}


Was This Post Helpful? 0
  • +
  • -

#3 erik.price  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 485
  • View blog
  • Posts: 2,690
  • Joined: 18-December 08

Re: Dont understand errors!

Posted 29 November 2009 - 08:21 PM

I'm not entirely sure as I'm posting this without thoroughly looking at your code and it is late, but I believe the references to super should be "this" instead.

this.showInventory();
return this.computeInventoryValue() * .05;
//and so on


Was This Post Helpful? 0
  • +
  • -

#4 atherton23  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 43
  • Joined: 18-November 09

Re: Dont understand errors!

Posted 29 November 2009 - 08:31 PM

View PostDogstopper, on 29 Nov, 2009 - 07:20 PM, said:

You call the line:
super.showInventory();



The super keyword activates a certain method or references a variable in the superclass. Well, your class is Main, and it does not explicitly subclass anything in particular. If you do not specify, it subclasses Object and object has no method called showInventory().

To extend another class, do it like this.
class Main extends AClassName {

}




Thanks, I added the " class genre extends CD" cleared all errors.
I am happy to see that one thing cleared all erros, I have been racking my brain for hours. I try to fix things before I result to asking for help but sometimes you just need some guidence. Again greatly appreciated.

View Posterik.price, on 29 Nov, 2009 - 07:21 PM, said:

I'm not entirely sure as I'm posting this without thoroughly looking at your code and it is late, but I believe the references to super should be "this" instead.

this.showInventory();
return this.computeInventoryValue() * .05;
//and so on




Thanks for Help. Greatly appreciated and yes I agree it is late.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1