I am attempting to complete an assignment but an having some major issues as my java knowledge is basic to say the least. Below is what I am trying to do and below that is the current code that I have. Am I way off base or on the right track?

Wings Coffee Shop
A local coffee shop sells a variety of different items shown below to their customers. You are asked to write a Java application that can be used to keep track of these items. Additionally, this program provides a way to print out a listing of the items.
Item Name Price Coffee $1.00 Water $2.00 Milk $1.50 Bagel $1.25 Donut $0.75
Your program will create a class, named Item. This class has the following: * A String instance variable to hold the item name * A double instance variable to hold the price * A constructor that takes a String and double to initialize the instance variables * A get and set method for each instance variable
Once you have this class created, you write a second class named CoffeeDriver. This class has the following methods: * sortName – this method sorts the array of items by item name and then displays the name and price of all items on the screen * sortPrice – this method sorts the array of items by item price and then displays the name and price of all items on the screen * main - It creates an array of Item objects using the data above to set each Item's information. After initializing the array, prompt the user for how they want to see the list – sorted by name or price. Then call the appropriate method.

public class Item
{
	private double coffee;
	private double water;
	private double milk;
	private double bagel;
	private double donut;
	
	public Item(double coffee, double water, double milk, double bagel, double donut)
	
	{
		coffee = 1.00;
		water = 2.00;
		milk = 1.50;
		bagel = 1.25;
		donut = 0.75;
	}
	
	{
		System.out.println("Item Name			Price");
		System.out.println("Coffee			$1.00");
		System.out.println("Water			$2.00");
		System.out.println("Milk			$1.50");
		System.out.println("Bagel			$1.25");
		System.out.println("Donut			$0.75");	
	}
}

I don't quite understand the whole project but this is as much as I gathered so far. It asks for me to use a string and a double but I am unsure how to combine the two.

If the price is fixed you could have just initialized it already e.g.

private double coffee = 1.00;

Now I don't see a method name for the following.. Is this supposed to print the output

{
System.out.println("Item Name	 Price");
System.out.println("Coffee	 $1.00");
System.out.println("Water	 $2.00");
System.out.println("Milk	 $1.50");
System.out.println("Bagel	 $1.25");
System.out.println("Donut	 $0.75");	
}

Now I could tell you the right way to make your class but learning on your own will be more rewarding so I'll post this link on how java classes are constructed

commented: will not do the work but will help the person, I like this method as it helps me understand the material. +0

yes, all it is supposed to do it print out the list. I figured that was the easiest and best way but if I set the private double to a set value how can I use a string and the double together? It is a simple concept I am having problems with.

yes, all it is supposed to do it print out the list. I figured that was the easiest and best way but if I set the private double to a set value how can I use a string and the double together? It is a simple concept I am having problems with.

What do you mean by use a string and double together? combine them? print them in same line?

A constructor that takes a String and double to initialize the instance variables

Now constructors as I have learned are simple mechanisms like this:

public Box(int x, int y, int z) //Triple Argument Constructor
	{
		length = x;
		width = y;
		height = z;
        }

From what I have here from a past assignment it simply assigns values based on input or a set value and then applies them to say System.out.println in any way I might want like adding. I'm confused as to how to apply this knowledge to what I have in italics above. Strings just store whatever it is that you may put in them correct?

A constructor that takes a String and double to initialize the instance variables

Now constructors as I have learned are simple mechanisms like this:

public Box(int x, int y, int z) //Triple Argument Constructor
    {
        length = x;
        width = y;
        height = z;
        }

From what I have here from a past assignment it simply assigns values based on input or a set value and then applies them to say System.out.println in any way I might want like adding. I'm confused as to how to apply this knowledge to what I have in italics above.

Can't the link I provided help you?

Strings just store whatever it is that you may put in them correct?

yes

It is helpful, my apologies it is just that this kind of stuff is new to me as I am a IT network technician.

Can you go on from here or do you still have questions?

Can you go on from here or do you still have questions?

I am going to attempt to complete the rest. I have a week and a half to complete this assignment so I will have to revisit concepts. I honestly need all the help I can get but I prefer to actually do the work myself while I am being told "why".

commented: if only most people here are as smart as you by doing a good research rather than posting questions where solutions can already be found on the web +4

For a getter setter method example check this link

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.