Lab 5 Pre-Lab Assignment

    

Name ___________________________________

Show all work!!!!

  1. Find the base 10 value of each of the following 8-bit two's complement numbers:

    1. 11011101

       

       

    2. 01110100

     

     

  2. Convert the base 16 number 3C7F16 to
    1. base 2 (using the special relationship between base 16 and base 2)

       

       

    2. base 8 (using the special relationship between base 8 and base 2)

       

       

  3. What is the largest positive integer of type int (that is, the largest positive integer that can be represented in 32 bits)? Write the formula (in terms of powers of 2) and find its value in base 10.

     

     

     

  4. The 8-bit two's complement representation of 107 is 01101011 and the representation of 52 is 00110100.
    1. Find the 8-bit sum (two's complement) of 107 and 52.
                 0 1 1 0 1 0 1 1
               + 0 0 1 1 0 1 0 0
               ------------------
      					<---- your answer
               __________________
      
      
    2. Convert the two's complement answer to base 10.

       

       

       

    3. Did overflow occur? Explain.

       

       

       

  5. In class we talked about the bank account class described below:
    //*****************************************************
    // Account.java
    //
    // A class representing a bank account; allows deposits,
    // withdrawals, balance inquiries, etc.
    //*****************************************************
    public class Account
    {
      private double balance;
      private String name;
      private long acctNum;
    
      //---------------------------------------------------
      // Constructor -- initializes instance data
      //---------------------------------------------------
      public Account(double initBal, String owner, long number)
      {
        balance = initBal;
        name = owner;
        acctNum = number;
      }
    
      //---------------------------------------------------
      // Simple withdrawal -- deducts amount from balance
      //---------------------------------------------------
      public void withdraw(double amount)
      {
          balance -= amount;
      }
    
      //---------------------------------------------------
      // Simple deposit -- adds amount to balance.
      //---------------------------------------------------
      public void deposit(double amount)
      {
        balance += amount;
      }
    
      //---------------------------------------------------
      // Returns balance.
      //---------------------------------------------------
      public double getBalance()
      {
        return balance;
      }
    
      //---------------------------------------------------
      // Prints name, account number, and balance
      //---------------------------------------------------
      public void printSummary()
    
      {
        //print name
    
        _____________________________
    
        //print acct number
    
        _____________________________
    
        //print balance
    
        _____________________________
      }
    
      //---------------------------
      // Deducts $10 service fee
      //---------------------------
      public double chargeFee()
      {
          // deduct the fee
    
          ____________________________________________________
    
    
          // return the updated balance
    
    
          ____________________________________________________
      }
    
      //---------------------------------------------------
      // Changes the name on the account to newName.
      //---------------------------------------------------
      public void changeName(String newName)
      {
        
          ___________________________________________________
      }
    
    }
    
    1. Fill in the code for method printSummary, which should print the name, account number, and balance for the account.
    2. Fill in the code for method chargeFee, which should deduct a service fee of $10 from the account, and then return the balance.
    3. In the last space, fill in the body for method changeName that takes a string as a parameter and changes the name on the account to be that string.

  6. The Java program below uses the Account class defined in above. Complete the program, using method calls, as indicated by the comments.
    //*****************************************************
    // ManageAccounts.java
    //
    // A program that uses the Account class to create and
    // manipulate bank accounts for Sally and Joe.
    //*****************************************************
    public class ManageAccounts
    {
      public static void main(String[] args)
      {
        Account account1, account2;
     
        //create account1 for Sally for $1000
        account1 = new Account(1000, "Sally", 12345);
    
        //create account2 for Joe with $500 and account number 11229
    
        ______________________________________________
    
    
        //deposit $100 to Joe's account
    
        ______________________________________________
    
        //withdraw $50 from Sally's account
    
        ______________________________________________
    
        //charge fees to both accounts
    
        ______________________________________________
    
        ______________________________________________
    
    
        //change name on Joe's account to Joseph
    
        ______________________________________________
    
        //print summary for both accounts
    
        ______________________________________________
    
        ______________________________________________
       
      }
    }