Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.*;
- public class fileSizeCal
- {
- public static void main (String args []){
- String text;
- int textSize=0;
- int numImages=0;
- int imgWidth=0;
- int imgLength=0;
- int totalPixels=0;
- int imgSize=0;
- int colourDepth=0;
- String imgFileType;
- int totalFileSize=0;
- int ConstFileHeaderSize=0000;//1. 15 bytes is needed, what is that in bits?
- Scanner input = new Scanner(System.in).useDelimiter("\\n");
- System.out.println("Enter text for the word file");
- text=input.next();
- //2. use the .length() function to calculate the length of the text file.
- // 3.we are using Extended ASCII for text, how many bytes are required for each character, how many bits are needed
- //for the text in our file?
- // textSize=textSize*
- totalFileSize+=textSize;
- System.out.println("Enter number of images");
- numImages=input.nextInt();
- for (int x=0; x<numImages;x++){
- System.out.println("Enter width of image "+(x+1));
- imgWidth=input.nextInt();
- System.out.println("Enter length of image "+(x+1));
- imgLength=input.nextInt();
- //4. enter formulas to calculate total number of pixels
- System.out.println("Enter colour depth of image: 8 bit or 24 bit "+(x+1));
- colourDepth=input.nextInt();
- /*
- * 5. Construct an IF/ELSE IF statement to calculate
- * if colourDepth is 8 then insert a formula to calculate the total number of pixels for 8 bit colour depth
- * else if colourDepth is 24 then insert a formula to calculate the total number of pixels for 24 bit colour depth
- * else if colourDepth is 32 (alpha) then insert a formula to calculate the total number of pixels for 36 bit colour depth
- */
- System.out.println("What is the file type of image "+(x+1)+".raw or .jpeg");
- imgFileType=input.next();
- /*
- * 6. Construct an IF/ELSE IF statement to calculate
- * IF imgFileType is .raw THEN imgSize remains the same
- * ELSE IF imgFileType is .JPEG then reduce image size by a factor of 10
- */
- totalFileSize+=imgSize;
- }
- totalFileSize+=ConstFileHeaderSize;
- System.out.println(totalFileSize);
- //7. Output the final fileSize as
- //bits, bytes , kilobytes, megabytes or gigabytes
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment