0

hopefully its easy.

in main class I have got method from proff

private class AddBBQChips implements ActionListener
	{
		public void actionPerformed(ActionEvent ae)
		{
			addChips( BagOfChips.Flavor.BBQ );
		}
	}

private void addChips(final BagOfChips.Flavor flavor){
    BagOfChips bag = new BagOfChips( flavor );
    System.out.println(bag.toString());
}

and from my class "BagofChips"

public String name;
	
	BagOfChips(String flavor){
		name= flavor;
	}
            public String toString(){
		return name;
	}

of course, it does not run. What's wrong with it?
I can only modify the second one.

2
Contributors
3
Replies
4
Views
8 Years
Discussion Span
Last Post by JamesCherrill
0

The first class tries to call a BagOfChips constructor with a parameter of type BagOfChips.Flavor, but you only have a constructor that takes a String.

0

whats the type of Flavor?

Is it class it self? if so should i define in BagOfChips class?

public class BagOfChips {
	public static class Flavor {
		
		public static final  Flavor BBQ = null ;
	
	}

	private Flavor type;

	
	public BagOfChips(Flavor flavor){
		type = flavor;
		
	}
	
	public String toString(){
		return type.toString();
	}
0

The syntax BagOfChips.Flavor.BBQ implies that Flavor is a public member of the BagOfChips class, and BBQ is a public member of Flavor. I can't tell whether iBagOfChips is a class or an enum, but if you haven't done enums yet, it's probably intended to be a class.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.