Expert Solution & Answer
Book Icon
Chapter 4, Problem 16E

Explanation of Solution

Algorithm:

Step 1: First get the number of free block and store it in a variable "blocks".

Step 2: Assign "true" to a Boolean variable "flag".

Step 3: WHILE "flag".

Step 4: Get the size of the file in bytes and store it in a variable "size".

Step 5: Calculate the compressed size of the file and store it in a variable "compress".

Step 6: Calculate number of blocks required for the file and store it in a variable "blocksNeeded". This is done by dividing "compress" by 512.

Step 7: Check if the "blocksNeeded" is less than "blocks".

Step 8: If the condition is true then reduce the number of free blocks. This is done by subtracting "blocksNeeded" from "blocks".

Step 9: If the condition is false then assign "false" to the variable "flag".

Complete program:

//Import required packages

import static java.lang.Math.round;

import java.util.*;

//Define the main class

public class FileSize

{

//Define the main method

public static void main(String[] args)

{

//Declare required variables

double blocks, size;

boolean flag = true;

//Create an object for scanner class

Scanner sc = new Scanner(System.in);

//Get the number of free blocks

System.out.print("Enter the number of free blocks: ");

blocks = sc.nextInt();

//While true

while(flag)

{

//Declare required variables

double compress = 0, blocksNeeded = 0;

//Get the size of the file

System.out.print("\nEnter the size of file in bytes: ");

size = sc...

Blurred answer
Students have asked these similar questions
Draw out an example of 3 systems using Lamport’s logical clock and explain the steps in words.
"Systems have become very powerful and sophisticated, providing quality information fordecisions that enable the firm to coordinate both internally and externally."With reference to the above statement compare the operations of any three data gatheringsystems today’s organisations use to aid decision making.
labmas Course Home XDocument courses/13810469/menu/a2c41aca-b4d9-4809-ac2e-eef29897ce04 There are three ionizable groups (weak acids and/or bases) in glutamic acid. Label them on the structure below Drag the appropriate labels to their respective targets. OOH [] CH3N CH CH2 CH2 IC HO Reset Help

Chapter 4 Solutions

Java: An Introduction to Problem Solving and Programming (8th Edition)

Chapter 4.1, Problem 11STQ Chapter 4.1, Problem 12STQ Chapter 4.1, Problem 13STQ Chapter 4.2, Problem 14STQ Chapter 4.2, Problem 15STQ Chapter 4.2, Problem 16STQ Chapter 4.2, Problem 17STQ Chapter 4.2, Problem 18STQ Chapter 4.2, Problem 19STQ Chapter 4.2, Problem 20STQ Chapter 4.2, Problem 21STQ Chapter 4.2, Problem 22STQ Chapter 4.2, Problem 23STQ Chapter 4.2, Problem 24STQ Chapter 4.2, Problem 25STQ Chapter 4.3, Problem 26STQ Chapter 4, Problem 1E Chapter 4, Problem 2E Chapter 4, Problem 3E Chapter 4, Problem 4E Chapter 4, Problem 5E Chapter 4, Problem 6E Chapter 4, Problem 7E Chapter 4, Problem 8E Chapter 4, Problem 9E Chapter 4, Problem 10E Chapter 4, Problem 11E Chapter 4, Problem 12E Chapter 4, Problem 13E Chapter 4, Problem 14E Chapter 4, Problem 15E Chapter 4, Problem 16E Chapter 4, Problem 17E Chapter 4, Problem 18E Chapter 4, Problem 19E Chapter 4, Problem 1P Chapter 4, Problem 2P Chapter 4, Problem 3P Chapter 4, Problem 5P Chapter 4, Problem 6P Chapter 4, Problem 7P Chapter 4, Problem 8P Chapter 4, Problem 9P Chapter 4, Problem 1PP Chapter 4, Problem 2PP Chapter 4, Problem 3PP Chapter 4, Problem 4PP Chapter 4, Problem 6PP Chapter 4, Problem 7PP Chapter 4, Problem 8PP Chapter 4, Problem 9PP Chapter 4, Problem 10PP Chapter 4, Problem 11PP Chapter 4, Problem 12PP Chapter 4, Problem 13PP Chapter 4, Problem 14PP Chapter 4, Problem 15PP Chapter 4, Problem 16PP
Knowledge Booster
Background pattern image
Similar questions
    SEE MORE QUESTIONS
    Recommended textbooks for you
    Text book image
    C++ for Engineers and Scientists
    Computer Science
    ISBN:9781133187844
    Author:Bronson, Gary J.
    Publisher:Course Technology Ptr
    Text book image
    EBK JAVA PROGRAMMING
    Computer Science
    ISBN:9781337671385
    Author:FARRELL
    Publisher:CENGAGE LEARNING - CONSIGNMENT
    Text book image
    C++ Programming: From Problem Analysis to Program...
    Computer Science
    ISBN:9781337102087
    Author:D. S. Malik
    Publisher:Cengage Learning
    Text book image
    Microsoft Visual C#
    Computer Science
    ISBN:9781337102100
    Author:Joyce, Farrell.
    Publisher:Cengage Learning,
    Text book image
    Programming Logic & Design Comprehensive
    Computer Science
    ISBN:9781337669405
    Author:FARRELL
    Publisher:Cengage
    Text book image
    Programming with Microsoft Visual Basic 2017
    Computer Science
    ISBN:9781337102124
    Author:Diane Zak
    Publisher:Cengage Learning