When the following code is executed with the

This preview shows page 12 - 16 out of 16 pages.

When the following code is executed with the completed arrangeNums() method: int[] array1 = {2, 3, 6, 8, 1, 9, 6, 8, 1}; int[] array2 = arrangeNums(array1); System.out.print("array1: "); printArray(array1); System.out.print("array2: "); printArray(array2); the output is: array1: 2 3 6 8 1 9 6 8 1 array2: 2 6 8 6 8 3 1 9 1 private static arrangeNums( ){ } (10 marks)
Image of page 12

Subscribe to view the full document.

Question/Answer Sheet - Page 13 - COMPSCI 101 S2 SURNAME: ...................................................... FORENAMES: ........................................................... Question 9 (15 marks) Complete the MoneyBalance class definition. This class stores the current balance for an account and a list of all the transactions made on that account. Each transaction is represented by an integer, positive for a deposit and negative for a withdrawal from the account. The balance and all the transactions are integer values. When the following code is executed with the completed MoneyBalance class: MoneyBalance moneyB1 = new MoneyBalance("Jim Bags",560); MoneyBalance moneyB2 = new MoneyBalance("Jena Pots",230); moneyB1.doTransaction(60); moneyB1.doTransaction(-20); moneyB1.doTransaction(200); moneyB1.doTransaction(-40); int amount = moneyB1.getBalance(); System.out.println(); System.out.println(moneyB1.getName()+" has $"+amount+" in bank."); for(int i=0; i<7; i++) moneyB2.doTransaction(100); moneyB2.doTransaction(-250); System.out.println(); System.out.println(moneyB1.toString()); System.out.println(); System.out.println(moneyB2.toString()); System.out.println(); if (moneyB2.balanceIsBigger(moneyB1)) System.out.println(moneyB2.getName()+" has more money."); else if (moneyB1.balanceIsBigger(moneyB2)) System.out.println(moneyB1.getName()+" has more money."); else System.out.println(moneyB1.getName()+","+moneyB2.getName()+ " has the same money"); the output is: Jim Bags has $760 in bank. Jim Bags 4 transactions so far: 60 -20 200 -40 Current Balance: $760 Jena Pots 8 transactions so far: 100 100 100 100 100 100 100 -250 Current Balance: $680 Jim Bags has more money.
Image of page 13
Question/Answer Sheet - Page 14 - COMPSCI 101 S2 SURNAME: ...................................................... FORENAMES: ........................................................... /** * Class which stores the current balance and a * list of transactions made on an account. * The balance can be adjusted by deposits and * withdrawals made on the account. * * Name: Adriana Ferraro * 2003 */ public class MoneyBalance{ private static final int MAX_TRANSACTIONS = 800; //name of the account private String name; //current balance of the account private int currentBalance; //number of transactions made so far private int upToInArray; //store an integer for each transaction private int[] transactions; public MoneyBalance(String name, int currBal){ } public void doTransaction(int trans){ } public String getName(){ } public int getBalance(){ }
Image of page 14

Subscribe to view the full document.

Question/Answer Sheet - Page 15 - COMPSCI 101 S2 SURNAME: ...................................................... FORENAMES: ........................................................... public balanceIsBigger( ){ } public String toString(){ String str; } }
Image of page 15
Question/Answer Sheet - Page 16 - COMPSCI 101 S2 SURNAME: ...................................................... FORENAMES: ........................................................... OVERFLOW PAGE (If you have used this page, please indicate clearly under the relevant question that you have overflowed to this page)
Image of page 16
You've reached the end of this preview.
  • Summer '12
  • AdrianaFerraro
  • Computer Science, English-language films, Subroutine, ........., Equals sign, ASCII

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern