I was just working on a quick class for an item to be sold. Here is the code for said class:
public class Item{
private int itemNumber;
private double itemCost;
private String manName;
public Item(int inum, double icost, String mname){
itemNumber = inum;
itemCost = icost;
manName = mname;
}
public int getNum(){
return itemNumber;
}
public double getCost(){
return itemCost;
}
public String getName(){
return manName;
}
public void setNum(int inum){
itemNumber = inum;
}
public void setCost(double icost){
itemCost = icost;
}
public void setName(String mname){
manName = mname;
}
}
And here is the calling method in the simple driver app I was using to test:
public static void testItem(){
Item item = new Item(4,44.50,"Example1");
item.setCost(50.00);
item.setNum(3);
item.setName("Example2");
System.out.println(item.getNum() + " " + item.getCost() + " " + item.getName());
}
}
My curiosity is that, originally, I had used floats for the cost variables. However, when compiling, I got an error for possible data loss as it was casting from double TO float.
I had declared the variables as floats, but they were considered doubles, it would seem.
I'm only a very junior Java man, and am currently using TextPad as my editor. I'm just curious about this fact so that I can keep the answer in mind. Thanks, guys!