Inheritance II

My program won't run due to an error with one of my classes.

Page 1 of 1

2 Replies - 1146 Views - Last Post: 24 April 2009 - 08:58 PM Rate Topic: -----

#1 babygirl(TM)   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 17
  • Joined: 30-March 09

Inheritance II

Posted 23 April 2009 - 09:49 PM

ok now my whole program is not working :smh:
My assignment is to make a Beverage superclass with wine and water as a subclass.

here's my code for the whole program:

Beverage.java
package beverage;
import staugIO.StaugIO;

public abstract class Beverage
{
	protected String bevCode, bevName, bevType="";	 // Beverage code, name, and type
	protected double bevPrice=0.0;										// Price of beverage
	protected StaugIO io;														  // StaugIO

// empty Beverage() class
	public Beverage() 
	{
	}
	
	// setBevCode method
	
	public void setBevCode(String code)
	{
		code = bevCode;
	}	

	// setBevName method
	public void setBevName(String name)
	{
		name = bevName;
	}
	
	// setBevType method
	public void setBevType(String type)
	{
		type = bevType;
	}
	
	// setBevCategory method
	public void setBevCategory(String category)
	{
		this.Category = category;
	}
	
	// setPrice method
	public void setPrice(double price)
	{
		this.Price = price;
	}
	
		/**
	 * getBevCode method
	 */
	 
	public String getBevCode()
	{
		return bevCode;
	}
	
	/**
	 *getBevname method
	 */
	
	public String getBevName()
	{
		return bevName;
	}
	
	/**
	 * getBevType method
	 */
	 
	 public String getBevType()
	 {
	 	return bevType;
	 }
	 
	 /**
	  *getBevCategory()
	  */
	  
	 public String getBevCategory()
	 {
	 	return bevCategory;
	 }
	 
	public double getPrice()
	{
		return price=0.0;
	}
}


BeverageProcessing.java
 
import beverage.*;
import staugIO.StaugIO;


public class BeverageProcessing 
{
	private int wineSize, waterSize, choice=0;
	private char anotherBev=' ';
	private StaugIO io;
	private Wine[] wine;
	private Water[] water;

	public BeverageProcessing() 
	{
	}
	
	public void createArrays()
	{
		do
		{
			choice = io.readInt("Enter your beverage group: "
					+ "\n\n1. wine"
					+ "\n\n2. water");
			if (choice == 1)
			{
				ProcessWineArray();
			}
			else
			{
				ProcessWaterArray();
			}
			anotherBev = io.readChar("Do you want to input information for another beverage group?");
		}
		
		while (anotherBev == 'y' || anotherBev == 'y');
	}
	public void ProcessWineArray()
	{
		wineSize = io.readInt("How many wine bottles need information input?");
		wine = new Wine[wineSize];

		for (int i = 0; i < wineSize; ++i);
		{
			wine[wineSize] = new Wine();
			wine[wineSize].setBevCode();
			wine[wineSize].setBevName();
			wine[wineSize].setBevType();
			wine[wineSize].setRegion();
			wine[wineSize].setGrape();
			wine[wineSize].setVintage();
			wine[wineSize].setPrice();
			wine[wineSize].setReview();
		}
	}
	public void ProcessWaterArray()
	{
		waterSize = io.readInt("How many water bottles need information input?");
		water = new Water[waterSize];
		
		for (int i = 0; i < waterSize; ++i);
		{
			water[waterSize] = new Water();
			water[waterSize].setBevCode();
			water[waterSize].setBevName();
			water[waterSize].setBevType();
			water[waterSize].setCountry();
			water[waterSize].setCarbonation();
			water[waterSize].setSweetner();
			water[waterSize].setUnit();
			water[waterSize].setPrice();
		}
	}
	public void displayArrays()
	{
		
		String arrayInfo = "Wine and Water Listing";
		
		for (int i = 0; i < wineSize; ++i)
		{
			arrayInfo = "\n\nBEVERAGE CODE: " + wine[i].getBevCode()
								+ "\nBEVERAGE: " + wine[i].getBevName()
								+ "\nCATEGORY:" + wine[i].getBevCategory()
								+ "\nTYPE:" + wine[i].getBevType()
								+ "\nGRAPE:" + wine[i].getGrape()
								+ "\nVINTAGE:" + wine[i].getVintage()
								+"\nREGION:" + wine[i].getRegion()
								+ "\nPRICE:" + wine[i].getPrice()
								+ "\nREVIEW:" + wine[i].getReview();
		}
		
		for (int i = 0; i < waterSize; ++i)
		{
			arrayInfo = "\n\nBEVERAGE CODE:" + water[i].getBevCode()
								+ "\nBEVERAGE:" + water[i].getBevName()
								+ "\nCATEGORY:" + water[i].getBevCategory()
								+ "\nTYPE:" + water[i].getBevType()
								+ "\nCARBONATION:" + water[i].getCarbonation()
								+ "\nSWEETNER:" + water[i].getSweetner()
								+ "\nCOUNTRY:" + water[i].getCountry()
								+ "\nUNIT:" + water[i].getPrice();
		}
		
	}
}
   

ERROR:
cannot find any of my symbol variables such as BevName, Bev Type, category, etc etc etc...
wine.java
package beverage;

public abstract class Wine extends Beverage
{
private String Grape, Vintage, Region, Review;


	public Wine(String bevCode, String bevName, String bevType)
	{
		super();
	}
	
	public void setGrape(String grape)
	{
		this.Grape = grape;
	}
	
	public void setVintage(String vintage)
	{
		this.Vintage = vintage;
	}
	
	public void setRegion(String region)
	{
		this.Region = region;
	}
	
	public void setReview(String review)
	{
		this.Review = review;
	}
	
	public String getGrape()
	{
		return Grape;
	}
	
	public String getVintage()
	{
		return Vintage;
	}
	
	public String getRegion()
	{
		return Region;
	}
	
	public String getReview()
	{
		return Review;
	}
}


water.java
  
package beverage;

public abstract class Water extends Beverage
{
private String Carbonation, Sweetner, Country, Unit;
private double Price;


	public Water(String bevCode, String bevName, String bevType)
	{
		super();
	}
	
	public void setCarbonation(String carbonation)
	{
		this.Carbonation = carbonation;
	}
	
	public void setSweetner(String sweetner)
	{
		this.Sweetner = sweetner;
	}
	
	public void setCountry(String country)
	{
		this.Country = country;
	}
	
	public void setUnit(String unit)
	{
		this.Unit = unit;
	}
	
	public void setPrice(double price)
	{
		this.Price = price;
	}
	
	public String getCarbonation()
	{
		return Carbonation;
	}
	
	public String getSweetner()
	{
		return Sweetner;
	}
	
	public String getCountry()
	{
		return Country;
	}
	
	public String getUnit()
	{
		return Unit;
	}
	
	public double getPrice()
	{
		return Price;
	}
}


The only issue I think is wrong is with the beverageProcessing.java.

Is This A Good Question/Topic? 0
  • +

Replies To: Inheritance II

#2 skaoth   User is offline

  • D.I.C Addict
  • member icon

Reputation: 91
  • View blog
  • Posts: 601
  • Joined: 07-November 07

Re: Inheritance II

Posted 23 April 2009 - 11:29 PM

Quote

ERROR:
cannot find any of my symbol variables such as BevName, Bev Type, category, etc etc etc...


I assume you meant to do this?

public class Wine extends Beverage {
...
}

and

public class Water extends Beverage {
... 
}



Otherwise statements like this don't make sense

Quote

water = new Water[waterSize];


because abstract classes can't be instantiated.
Was This Post Helpful? 0
  • +
  • -

#3 pbl   User is offline

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

Reputation: 8381
  • View blog
  • Posts: 31,956
  • Joined: 06-March 08

Re: Inheritance II

Posted 24 April 2009 - 08:58 PM

And your displayInfo() method just assign a lot of different values to the String arrayInfo without doing anything with it
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1