Skip to main content

Lab5:

public static void createmenu5(){
   
    int ch ;
    long a , b ;
   
   System.out.print("|No.\t\t| Unit         \t\t| Description        |\n");
   System.out.print("-------------------------------------------------------------|\n");
   System.out.print("| 1-\t | Kilobyte (KB)\t\t| 1 KB = 1024 Bytes  |\n");
   System.out.print("| 2-\t | Megabyte (MB)\t\t| 1 MB = 1024 KB     |\n");
   System.out.print("| 3-\t | Gigabyte (GB)\t\t| 1 GB = 1024 MB     |\n");
   System.out.print("| 4-\t | Terabyte (TB)\t\t| 1 TB = 1024 MB     |\n");
   System.out.print("| 5-\t | Petabyte (PB)\t\t| 1 PB = 1024 TB     |\n");
  
   System.out.print("\nMenu that you need to choose:");
   System.out.println("1.\tByte:");
   System.out.println("2.\tKilobyte:");
   System.out.println("3.\tMegabyte:");
   System.out.println("4.\tGigabyte:");
   System.out.println("5.\tTerabyte:");
   System.out.println("6.\tPetabyte:");
   System.out.print("You can choose 1 to 6:");
   Scanner inputch = new Scanner (System.in);// Create a Scanner object
    ch = inputch.nextInt(); // ch is choose
      switch(ch) {
        case 1:
             
 StorageConverter convertBytes = new StorageConverter() ;
 StorageConverter valueByte = new StorageConverter ();//Creating Objects
  System.out.print("Enter Bytes = ");
   Scanner Byte = new Scanner(System.in);
      a = Byte.nextLong(); convertBytes.setA(a);//setter/mutator method    
       valueByte.setB(1024);
   System.out.println("1.\tConvert from Byte to KiloByte = "+(convertBytes.getA()/valueByte.getB())+"KB");//out result of Bytes/1024
   System.out.println("2.\tConvert from Byte to MegaByte = "+(convertBytes.getA()/valueByte.getB()/valueByte.getB())+"MB");//out result of Bytes/(1024*1024)
   System.out.println("3.\tConvert from Byte to GigaByte = "+(convertBytes.getA()/valueByte.getB()/valueByte.getB()/valueByte.getB())+"GB");//out result of Bytes/(1024*1024*1024)
   System.out.println("4.\tConvert from Byte to TeraByte ="+(convertBytes.getA()/valueByte.getB()/valueByte.getB()/valueByte.getB()/valueByte.getB())+"TB");//out result of Bytes/(1024*1024*1024*1024)
   System.out.println("5.\tConvert from Byte to PetaByte = "+(convertBytes.getA()/valueByte.getB()/valueByte.getB()/valueByte.getB()/valueByte.getB()/valueByte.getB())+"PB");//out result of Bytes/(1024*1024*1024*1024*1024)
    break;
        
        case 2:
 StorageConverter convertKilobyte = new StorageConverter() ;
 StorageConverter valueKilobyte = new StorageConverter ();//Creating Objects
  System.out.print("Enter Kilobyte = ");
   Scanner Kilobyte = new Scanner(System.in);
      a = Kilobyte.nextLong(); convertKilobyte.setA(a);//setter/mutator method    
       valueKilobyte.setB(1024);          
   System.out.println("1.\tConvert from Kilobyte to Byte = "+(convertKilobyte.getA()*valueKilobyte.getB())+"B"
           + "");//out result of Bytes*1024
   System.out.println("2.\tConvert from Kilobyte to Megabyte = "+(convertKilobyte.getA()*valueKilobyte.getB())+"MB");//out result of Bytes*1024)
   System.out.println("3.\tConvert from Kilobyte to Gigabyte = "+(convertKilobyte.getA()*valueKilobyte.getB()*valueKilobyte.getB())+"GB");//out result of Bytes*(1024*1024)
   System.out.println("4.\tConvert from Kilobyte to TeraByte ="+(convertKilobyte.getA()*valueKilobyte.getB()*valueKilobyte.getB()*valueKilobyte.getB())+"TB");//out result of Bytes*(1024*1024*1024)
   System.out.println("5.\tConvert from Kilobyte to PetaByte = "+(convertKilobyte.getA()*valueKilobyte.getB()*valueKilobyte.getB()*valueKilobyte.getB()*valueKilobyte.getB())+"PB");//out result of Bytes*(1024*1024*1024*1024)
    break;
   
         case 3:
 StorageConverter convertMegabyte = new StorageConverter() ;
 StorageConverter valueMegabyte = new StorageConverter ();//Creating Objects
  System.out.print("Enter Megabyte = ");
   Scanner Megabyte = new Scanner(System.in);
      a = Megabyte.nextLong(); convertMegabyte.setA(a);//setter/mutator method    
       valueMegabyte.setB(1024);          
   System.out.println("1.\tConvert from Megabyte to Byte = "+(convertMegabyte.getA()*valueMegabyte.getB()*valueMegabyte.getB())+"B");//out result of Bytes*(1024*1024)
   System.out.println("2.\tConvert from Megabyte to Kilobyte = "+(convertMegabyte.getA()*valueMegabyte.getB())+"KB");//out result of Bytes*1024
   System.out.println("3.\tConvert from Megabyte to Gigabyte = "+(convertMegabyte.getA()*valueMegabyte.getB())+"GB");//out result of Bytes*(1024*1024)
   System.out.println("4.\tConvert from Megabyte to TeraByte ="+(convertMegabyte.getA()*valueMegabyte.getB()*valueMegabyte.getB())+"TB");//out result of Bytes*(1024*1024)
   System.out.println("5.\tConvert from Megabyte to PetaByte = "+(convertMegabyte.getA()*valueMegabyte.getB()*valueMegabyte.getB()*valueMegabyte.getB())+"PB");//out result of Bytes*(1024*1024*1024)
    break;
   
         case 4:
 StorageConverter convertGigabyte = new StorageConverter() ;
 StorageConverter valueGigabyte = new StorageConverter ();//Creating Objects
  System.out.print("Enter Gigabyte = ");
   Scanner Gigabyte = new Scanner(System.in);
      a = Gigabyte.nextLong(); convertGigabyte.setA(a);//setter/mutator method    
       valueGigabyte.setB(1024);
   System.out.println("1.\tConvert from Gigabyte to Byte = "+(convertGigabyte.getA()*valueGigabyte.getB()*valueGigabyte.getB()*valueGigabyte.getB())+"B");//out result of Bytes*(1024*1024*1024)
   System.out.println("2.\tConvert from Gigabyte to Kilobyte = "+(convertGigabyte.getA()*valueGigabyte.getB()*valueGigabyte.getB())+"KB");//out result of Bytes*(1024*1024)
   System.out.println("3.\tConvert from Gigabyte to Megabyte = "+(convertGigabyte.getA()*valueGigabyte.getB())+"MB");//out result of Bytes*1024
   System.out.println("4.\tConvert from Gigabyte to TeraByte ="+(convertGigabyte.getA()*valueGigabyte.getB())+"TB");//out result of Bytes*1024
   System.out.println("5.\tConvert from Gigabyte to PetaByte = "+(convertGigabyte.getA()*valueGigabyte.getB()*valueGigabyte.getB())+"PB");//out result of Bytes*(1024*1024) 
    break;    
        
         case 5:
 StorageConverter convertTerabyte = new StorageConverter() ;
 StorageConverter valueTerabyte = new StorageConverter ();//Creating Objects
  System.out.print("Enter Terabyte = ");
   Scanner Terabyte = new Scanner(System.in);
      a = Terabyte.nextLong(); convertTerabyte.setA(a);//setter/mutator method    
       valueTerabyte.setB(1024);
   System.out.println("1.\tConvert from Terabyte to Byte = "+(convertTerabyte.getA()*valueTerabyte.getB()*valueTerabyte.getB()*valueTerabyte.getB()*valueTerabyte.getB())+"B");//out result of Bytes*(1024*1024*1024*1024)
   System.out.println("2.\tConvert from Terabyte to Kilobyte = "+(convertTerabyte.getA()*valueTerabyte.getB()*valueTerabyte.getB()*valueTerabyte.getB())+"KB");//out result of Bytes*(1024*1024*1024)
   System.out.println("3.\tConvert from Terabyte to Megabyte = "+(convertTerabyte.getA()*valueTerabyte.getB()*valueTerabyte.getB())+"MB");//out result of Bytes*(1024*1024)
   System.out.println("4.\tConvert from Terabyte to Gigabyte ="+(convertTerabyte.getA()*valueTerabyte.getB())+"GB");//out result of Bytes*1024
   System.out.println("5.\tConvert from Terabyte to PetaByte = "+(convertTerabyte.getA()*valueTerabyte.getB())+"PB");//out result of Bytes*1024     
    break;
        
         case 6:
 StorageConverter convertPetabyte = new StorageConverter() ;
 StorageConverter valuePetabyte = new StorageConverter ();//Creating Objects
  System.out.print("Enter Petabyte = ");
   Scanner Petabyte = new Scanner(System.in);
      a = Petabyte.nextLong(); convertPetabyte.setA(a);//setter/mutator method    
       valuePetabyte.setB(1024);
   System.out.println("1.\tConvert from Petabyte to Byte = "+(convertPetabyte.getA()*valuePetabyte.getB()*valuePetabyte.getB()*valuePetabyte.getB()*valuePetabyte.getB()*valuePetabyte.getB())+"B");//out result of Bytes*(1024*1024*1024*1024*1024)
   System.out.println("2.\tConvert from Petabyte to Kilobyte = "+(convertPetabyte.getA()*valuePetabyte.getB()*valuePetabyte.getB()*valuePetabyte.getB()*valuePetabyte.getB())+"KB");//out result of Bytes*(1024*1024*1024*1024)
   System.out.println("3.\tConvert from Petabyte to Megabyte = "+(convertPetabyte.getA()*valuePetabyte.getB()*valuePetabyte.getB()*valuePetabyte.getB())+"MB");//out result of Bytes*(1024*1024*1024)
   System.out.println("4.\tConvert from Petabyte to Terabyte ="+(convertPetabyte.getA()*valuePetabyte.getB()*valuePetabyte.getB())+"TB");//out result of Bytes*(1024*1024)
   System.out.println("5.\tConvert from Petabyte to Gigabyte = "+(convertPetabyte.getA()*valuePetabyte.getB())+"GB");//out result of Bytes*1024     
    break;
     
      }
}



 private long A,B;// can only be accessed through getter and setter methods
   
  public void setA (long a) {
      A = a; //getA = setX(int a)
  }
  public long getA() {
       return A ;    // Recall A from setA
  }

  public void setB(long b) {
     
      B = b; //getB = setY(int b)    
  }
  public long getB() {
       return B ;    // Recall B from setB
  }

Comments

Popular posts from this blog

The laws of set algebra & Laws derivable >> in the table 5.1 & 5.2 :

Ans :       Commutative laws                             Ans:          Associative laws Ans:         Distributive laws       Ans:            Identity laws Ans:         Complement laws Ans:          Absorption laws Ans:         Minimization laws Ans:         De Morgan’s laws

Exercise Chapter7 : Vectors

VECTORS AND SCALARS: BASIC CONCEPTS Exercise 7.2 Solution : 1. For the arbitrary points A, B, C, D and E, and a single  vector which is equivalent to A:   DC + CB    = DB B:  CE + DC   = DE 2.  shows a cube. Let p =  AB, q =  AD and  r =  AE . Express the vectors representing  BD,  AC and  AG in terms of p, q and r. Consider the triangle ABD shown in Figure. We note that  BD represents the third  side of the triangle formed when AD are placed head to tail. Using the triangle law we find :                      AB + BD = AD               => BD = AD - AB                             = q - p Consider the triangle  ADC  shown in Figure. We note that  AD  represe...

Matrix algebra

                 Matrices provide a means of storing large quantities of information in such a way that each piece can be easily identified and manipulated. They permit the solution of large systems of linear equations to be carried out in a logical and formal way so that computer implementation follows naturally. Applications of matrices extend over many areas of engineering including electrical network analysis and robotics. 1-BASIC DEFINITIONS                  Matrix is a rectangular pattern or array of numbers.      For example:                    are all matrices. Note that we usually use a capital letter to denote a matrix, and enclose the array of numbers in brackets. To describe the size of a matrix we quote its number of rows and columns in that order so, for example, an r × s matrix has r rows and s colu...