In: Computer Science
Suppose jillsBook is a LooseLeaf object that has already been
created, but which you cannot see.
Now write one or several statements that double the number of blank
pages in jillsBook.
Thus if jillsBook starts with 45 blank pages, then after your
statements execute jillsBook should hold 90 pages. If her book
starts with 80 pages, after your statement executes her book should
hold 160 blank pages.
Hint: First use the getBlankPages method to extract the number of
blank pages in jill's book, make up an int variable, and store the
blank page value in that new variable. Then double that value.
Finally, use the setBlankPages method to make the change to the
number of blank pages in the book.
Editable code:
import java.io.*;
import java.util.Scanner;
class LooseLeaf
{
// declare the variable 'pages' as int data type
private int pages;
//get methods for blank pages
public LooseLeaf()
{
pages = 40;
}
public int getBlankPages()
{
return pages;
}
//set method for blank pages
public void setBlankPages(int p)
{
pages = p;
}
}
public class BookSample
{
public static void main(String [] args)
{
LooseLeaf jillsBook = new LooseLeaf();
int pages;
pages = jillsBook.getBlankPages();
pages = pages * 2;
jillsBook.setBlankPages(pages);
System.out.println("After changing, number of blank pages in the jill's book is: "+jillsBook.getBlankPages());
}
}