example = Keyboard.readInt () ;
// CLASS 1
public class BagOfChips
{
private double height; // 0.00
private int width; // 0
private String type; //Salty, paprika, ...
//display() displays all the values of the variables in the console
public void display()
{
System.out.println("Details of BagOfChips:");
System.out.printf("Height variable value: %.2f\n", this.height);
System.out.printf("Width variable value: %d\n", this.width);
System.out.printf("Type variable value: %s\n", this.type);
}
//getter height
public double getHeight()
{
return this.height;
}
//setter height
public void setHeight(double height)
{
this.height = height;
}
//getter width
public int getWidth()
{
return this.width;
}
//setter width
public void setWidth(int width)
{
this.width = width;
}
//getter type
public String getType()
{
return this.type;
}
//setter type
public void setType(String type)
{
this.type = type;
}
}
//CLASS 2
public class Demo
{
public static void main(String[] args)
{
BagOfChips bagOfChip1 = new BagOfChips();
BagOfChips bagOfChip2 = new BagOfChips();
//set values of the first BagOfChips
bagOfChip1.setType("Salty");
bagOfChip1.setHeight(5.00); //.00 isn't needed, but it's just to show you it can take values beyond the '.'
bagOfChip1.setWidth(3); //This can't take values beyond the .00 if you would do 3.99 it would just be 3
//Set the values of the second bag of chips
bagOfChip2.setType("Paprika");
bagOfChip2.setHeight(10.00);
bagOfChip2.setWidth(6);
bagOfChip1.display();
bagOfChip2.display();
}
}
