Lab 5 Pre-Lab Assignment

Show all work!!!!

  1. Convert the base 10 number 108 to base 2.

     

     

     

  2. Find the 8-bit two's complement representation of each of the following (your answer to #1 will help):

    1. 108     ________________________________________

    2. -108    ________________________________________

     

  3. Convert the base 10 number 470 to base 9 two different ways:
    1. Using the subtraction method

       

       

    2. Using the division method

       

       

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

    1. 11011101

       

       

    2. 01110100

     

     

  5. Convert the base 8 number 32758 to
    1. base 10

       

       

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

       

       

  6. What is the largest positive base 10 integer (unsigned -- all places are used for the number with no sign) that can be represented in four base 3 digits? Write both the 4-digit base 3 number and find its value in base 10.

     

     

     

  7. 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.

       

       

       

  8. 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 void chargeFee()
      {
        
          ____________________________________________________
    
      }
    
      //---------------------------------------------------
      // 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.
    3. Modify chargeFee so that instead of returning no value (type void), it returns the new balance. Note that you will have to make changes in two places -- add a return statement and change the return type.
    4. 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.

  9. The Java program below uses the Account class defined in above. Complete the program 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
    
        ______________________________________________
    
    
        //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
    
        ______________________________________________
    
        ______________________________________________
       
      }
    }