How do you create a variable class to hold double values? My String works as I want it to, but I can't figure out how to instance all the double values.
Also, how do i create a constructor that takes the listofItems String and the (to be created) itemCosts double to initialize the instance variables and also uses get and set methods for each instance?Code:class Item
{
public static void main(String args[])
{
//These are the items values which I want to call itemCosts
Double itemCoffee = new Double("1.00");
//Coffe is $1.00
Double itemWater = new Double("2.00");
// Water is $2.00
Double itemMilk = new Double("1.50");
// Milk is $1.50
Double itemBagel = new Double("1.25");
// Bagel is $1.25
Double itemDonut = new Double("0.75");
//Donut is $0.75
//This mess here prints out each item
System.out.println(itemCoffee);
System.out.println(itemWater);
System.out.println(itemMilk);
System.out.println(itemBagel);
System.out.println(itemDonut);
//This String of items works as I want, it neatly lists
//each item and its price and uses only 1 println
String listofItems =
"Coffee - $1.00 \n"+
"Water - $2.00 \n"+
"Milk - $1.50 \n"+
"Bagel - $1.25 \n"+
"Donut - $0.75 ";
System.out.println(listofItems);
}
}
I know (read: i think) that get and set would be something like:
Many thanks in advance!Code:get itemPrices
set itemPrices
get itemNames
set itemNames

