
Explanation of Solution
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...

Want to see the full answer?
Check out a sample textbook solution
Chapter 4 Solutions
Java: An Introduction to Problem Solving and Programming plus MyProgrammingLab with Pearson eText -- Access Card Package (7th Edition)
- List down the strenghts and weaknesses of your team project for Capsim Simulation? Explan.arrow_forwardCapsim Team PowerPoint Presentations - Slide Title: Key LearningsWhat were the key learnings that you discovered as a team through your Capsim simulation?arrow_forwardWrite the SQL code that permits to implement the tables: Student and Transcript. NB: Add the constraints on the attributes – keys and other.arrow_forward
- Draw an ERD that will involve the entity types: Professor, Student, Department and Course. Be sure to add relationship types, key attributes, attributes and multiplicity on the ERD.arrow_forwardDraw an ERD that represents a book in a library system. Be sure to add relationship types, key attributes, attributes and multiplicity on the ERD.arrow_forward2:21 m Ο 21% AlmaNet WE ARE HIRING Experienced Freshers Salesforce Platform Developer APPLY NOW SEND YOUR CV: Email: hr.almanet@gmail.com Contact: +91 6264643660 Visit: www.almanet.in Locations: India, USA, UK, Vietnam (Remote & Hybrid Options Available)arrow_forward
- Provide a detailed explanation of the architecture on the diagramarrow_forwardhello please explain the architecture in the diagram below. thanks youarrow_forwardComplete the JavaScript function addPixels () to calculate the sum of pixelAmount and the given element's cssProperty value, and return the new "px" value. Ex: If helloElem's width is 150px, then calling addPixels (hello Elem, "width", 50) should return 150px + 50px = "200px". SHOW EXPECTED HTML JavaScript 1 function addPixels (element, cssProperty, pixelAmount) { 2 3 /* Your solution goes here *1 4 } 5 6 const helloElem = document.querySelector("# helloMessage"); 7 const newVal = addPixels (helloElem, "width", 50); 8 helloElem.style.setProperty("width", newVal); [arrow_forward
- C++ for Engineers and ScientistsComputer ScienceISBN:9781133187844Author:Bronson, Gary J.Publisher:Course Technology PtrEBK JAVA PROGRAMMINGComputer ScienceISBN:9781337671385Author:FARRELLPublisher:CENGAGE LEARNING - CONSIGNMENTC++ Programming: From Problem Analysis to Program...Computer ScienceISBN:9781337102087Author:D. S. MalikPublisher:Cengage Learning
- Microsoft Visual C#Computer ScienceISBN:9781337102100Author:Joyce, Farrell.Publisher:Cengage Learning,Programming Logic & Design ComprehensiveComputer ScienceISBN:9781337669405Author:FARRELLPublisher:CengageProgramming with Microsoft Visual Basic 2017Computer ScienceISBN:9781337102124Author:Diane ZakPublisher:Cengage Learning




