Monday 27 September 2010

Chapter 3 Test- Jonathan

public void getChange()
{
    int changeInCents = converter.convert();
     numDollars=new NumberOfDollars(changeInCents);
     System.out.println("" +numDollars.getDollars() + " dollar(s)" );

    changeInCents = numDollars.getChange();
     numQuarters = new NumberOfQuarters(changeInCents);
     System.out.println("" +numQuarters.getQuarters() + " quarter(s)");
  
     changeInCents = numQuarters.getChange();
  
     numDimes = new NumberOfDimes(changeInCents);
     System.out.println("" +numDimes.getDimes() + " dimes(s)");
  
     changeInCents = numDimes.getChange();
  
     numNickels = new NumberOfNickels(changeInCents);
     System.out.println("" +numNickels.getNickels() + " nickels(s)");
  
     changeInCents = numNickels.getChange();
  
     System.out.println("" + changeInCents + " cent(s)");
}//getChange






5. Place a check to make sure that the cash tendered by the customer is more than the cost of the goods.


DONE



6. In what way does this project exemplify abstraction and modularization.

In complex software and programming it is easier to divide everything into subcomponents. Instead of using one giant, long and complex class for the money transaction, we divided it into parts. Each part in charge of something else. The abstraction and modularization are used to "divide and conquer" and make this programming a lot more simple. the abstraction and modulazation method resembles a conveyor belt, or the system used to build cars. 

7. Give one example, from this project, of each of the following.

a. an object reference.

b. the use of a primitive type other than int.

primitive type : DOUBLE
Transaction (double totalPrice, double amountGiven)


c. an object creation.

public class Transaction
{
    private double totalPrice;
    private double amountGiven;
    private ConvertToCents converter;
    private NumberOfDollars numDollars;
    private NumberOfQuarters numQuarters;
    private NumberOfDimes numDimes;
    private NumberOfNickels numNickels;

Transaction (double totalPrice, double amountGiven)
{
    this.totalPrice=totalPrice;
    this.amountGiven=amountGiven;
    converter =new ConvertToCents(amountGiven-totalPrice);
}//constructor







d. overloading.

e. an internal method call.

  changeInCents = numDollars.getChange(); it invokes the get change method it is internal since it is in the same class as the method

f. an external method call.

8. Draw an object diagram for one moment in the execution of method getChange() on a Transaction instance that was initialized with..
total price = 5.29
amount of cash = 10.00
You should use the BlueJ 
debugger to halt the execution at line..    changeInCents = numDollars.getChange();

No comments:

Post a Comment