Advertisement
mrScarlett

FileSizeEstimation

Sep 12th, 2017
182
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.54 KB | None | 0 0
  1. import java.util.*;
  2.  
  3. public class fileSizeCal
  4. {
  5.    
  6.     public static void main (String args []){
  7.         String text;
  8.         int textSize=0;
  9.         int numImages=0;
  10.         int imgWidth=0;
  11.         int imgLength=0;
  12.         int totalPixels=0;
  13.         int imgSize=0;
  14.         int colourDepth=0;
  15.         String imgFileType;
  16.         int totalFileSize=0;
  17.         int ConstFileHeaderSize=0000;//1.  15 bytes is needed, what is that in bits?
  18.         Scanner input = new Scanner(System.in).useDelimiter("\\n");
  19.         System.out.println("Enter text for the word file");
  20.         text=input.next();
  21.         //2.  use the .length() function to calculate the length of the text file.
  22.         // 3.we are using Extended ASCII for text, how many bytes are required for each character, how many bits are needed
  23.             //for the text in our file?
  24.         // textSize=textSize*
  25.         totalFileSize+=textSize;
  26.         System.out.println("Enter number of images");
  27.         numImages=input.nextInt();
  28.         for (int x=0; x<numImages;x++){
  29.             System.out.println("Enter width of image "+(x+1));
  30.             imgWidth=input.nextInt();
  31.             System.out.println("Enter length of image "+(x+1));
  32.             imgLength=input.nextInt();
  33.             //4.  enter formulas to calculate total number of pixels
  34.             System.out.println("Enter colour depth of image: 8 bit or 24 bit "+(x+1));
  35.             colourDepth=input.nextInt();
  36.             /*
  37.              * 5.  Construct an IF/ELSE IF statement to calculate
  38.              * if colourDepth is 8 then insert a formula to calculate the total number of pixels for 8 bit colour depth
  39.              * else if colourDepth is 24 then insert a formula to calculate the total number of pixels for 24 bit colour depth
  40.              * else if colourDepth is 32 (alpha) then insert a formula to calculate the total number of pixels for 36 bit colour depth
  41.              */
  42.            
  43.  
  44.             System.out.println("What is the file type of image "+(x+1)+".raw or .jpeg");
  45.             imgFileType=input.next();
  46.             /*
  47.              * 6.  Construct an IF/ELSE IF statement to calculate
  48.              * IF imgFileType is .raw THEN imgSize remains the same
  49.              * ELSE IF imgFileType is .JPEG then reduce image size by a factor of 10
  50.             */
  51.            
  52.             totalFileSize+=imgSize;
  53.         }
  54.         totalFileSize+=ConstFileHeaderSize;
  55.     System.out.println(totalFileSize);
  56.     //7.  Output the final fileSize as
  57.     //bits, bytes , kilobytes, megabytes or gigabytes
  58.    
  59. }
  60. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement