Question

In: Computer Science

Suppose jillsBook is a LooseLeaf object that has already been created, but which you cannot see....

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.

Solutions

Expert Solution

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());

      }

}


Related Solutions

Object A, which has been charged to + 16 nC , is at the origin. Object...
Object A, which has been charged to + 16 nC , is at the origin. Object B, which has been charged to − 22 nC , is at (x,y)=(0.0cm,2.0cm)What is the magnitude of the electric force on object A? Express your answer using two significant figures. Part B What is the magnitude of the electric force on object B? Part C What is the direction of the electric force on object A? a. positive x-axis b. positive y-axis c. negative...
You have been given a ticket to see Katy Perry in concert tonight. You cannot resell...
You have been given a ticket to see Katy Perry in concert tonight. You cannot resell the ticket. Adele is performing on the same night & her concert is the only other activity you are considering. An Adele ticket costs $85 & on any given day you would be willing to pay as much as $150 to see her play. There is no other cost of seeing either performer. What is the opportunity cost of attending the Katy Perry concert?...
a) You wish to melt a 3.0-kg block of aluminum, which has already been heated to...
a) You wish to melt a 3.0-kg block of aluminum, which has already been heated to 660ºC. How much heat is required to melt the aluminum? (the textbook lists the latent heat of aluminum as 396,000 J/kg) b) You wish to melt a 3.0-kg block of aluminum, which initially at 20ºC. How much heat is required to melt the aluminum? (the textbook lists the latent heat of aluminum as 396,000 J/kg)
Object A , which has been charged to + 14 nC , is at the origin....
Object A , which has been charged to + 14 nC , is at the origin. Object B , which has been charged to − 22 nC , is at (x,y)=(0.0cm,2.0cm) . Part A What is the magnitude of the electric force on object A ? Express your answer using two significant figures. Part B What is the magnitude of the electric force on object B? Part C What is the direction of the electric force on object A? positive...
Explain why you cannot see through silicon
Explain why you cannot see through silicon
Research (Literature Review): [Search the net, see if there are paper towers that have already been...
Research (Literature Review): [Search the net, see if there are paper towers that have already been made, what is unique in these towers. Select one idea from the net and explain its design. Provide a picture of the design. please mention also the advantages and disadvantages of the design you choose it
(Javascript) /* * USER HAS ALREADY BEEN IMPLEMENTED FOR YOU: * User has the following properties:...
(Javascript) /* * USER HAS ALREADY BEEN IMPLEMENTED FOR YOU: * User has the following properties: * name: string * birthday: Date * * User has the following method: * getDayBorn: Returns the day of the week that the user was born * example: Wednesday */ function User(name, birthday) { this.name = name; this.birthday = birthday; this.getDayBorn = function() { var days = [`Sunday`,`Monday`,`Tuesday`, `Wednesday`,`Thursday`,`Friday`,`Saturday`]; return days[this.birthday.getDay()]; } } /* * YOUR TASK IS TO IMPLEMENT CHIRP: * Chirp has...
In 6A, you created an object class encapsulating a Trivia Game which INHERITS from Game. Now...
In 6A, you created an object class encapsulating a Trivia Game which INHERITS from Game. Now that you have successfully created Trivia objects, you will continue 6B by creating a linked list of trivia objects. Add the linked list code to the Trivia class. Your linked list code should include the following: a TriviaNode class with the attributes: 1. trivia game - Trivia object 2. next- TriviaNode 3. write the constructor, accessor, mutator and toString methods. A TriviaLinkedList Class which...
You have already learned that an unbalanced or net force F accelerate an object, but it...
You have already learned that an unbalanced or net force F accelerate an object, but it is also possible for a balanced set of forces to cause motion. To understand this condition it is necessary to realize that when we deal with real objects they have size and the location of where the force is applied matters.  To analyze this motion you must not deal only with the size and direction of F but also where it acts on the object.  An...
there are files called LinkedList.h, and Array.h and all the functionality you need has already been...
there are files called LinkedList.h, and Array.h and all the functionality you need has already been implemented. There is also a file called TimeSupport.h that allows you to measure the running time of code segments. There is also a file called RandomSupport.h, which you can use to generate good random numbers. In your app.cpp , create a demo illustrating a scenario where storing numbers in a linked list is more efficient than an array. Your demo should generate a sufficiently...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT