Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Purpose Purpose of this lab is for you to develop a program where many objects a

ID: 3685247 • Letter: P

Question

Purpose Purpose of this lab is for you to develop a program where many objects are created from a class. Primitives and objects are passed as parameters to class methods. Problem specification Your new wallet class implements a wallet that contains banknotes. A banknote is represented as an int for simplicity, l for a $1 bill, 5 for a $5 bill, and so on. You are required to use just a simple array of int to hold the banknotes. You may NOT use an array list. Here are some example wallets printed out: Wallet [5, 50, 10, 5] Wallet [] Wallet[1, 5, 10, 50, 5] Here's the outline of the wallet class. You will implement each method as described below. public class Wallet {//max possible # of banknotes in a wallet private static final int MAX = 10; private int contents[]; private int count;//number of banknotes stored in contents[] public Wallet()//your code goes here public Wallet(int a[])//your code goes here public String toStringO//your code goes here public int value()//your code goes here

Explanation / Answer

package com.dq.thematrix.main.java.test;

import org.apache.commons.lang.ArrayUtils;

public class Wallet {

   private static final int MAX=10;
   private int contents[];
   private int count;

   public Wallet()
   {
       count=0;
   }
   public Wallet(int[] a)
   {
       contents=a;
   }
   public int value()
   {
       return contents[count];

   }
   public String tostring()
   {
       return null;

   }
   public void reverse()
   {
       // Please explain what is required here
   }
   public void add(int banknote)
   {
       contents[count]=banknote;
       count++;
   }
   public void transfer(Wallet donor)
   {

   }
   public void sort()
   {
       for (int i = 0; i < contents.length - 1; i++)
       {
           int index = i;
           for (int j = i + 1; j < contents.length; j++)
               if (contents[j] < contents[index])
                   index = j;

           int smallerNumber = contents[index];
           contents[index] = contents[i];
           contents[i] = smallerNumber;
       }

   }

   public boolean remove(int banknote)
   {
       for(int i=0;i<contents.length;i++)
       {
           if(contents[i]==banknote)
               contents = ArrayUtils.remove(contents, i);
       }
       return false;

   }
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at drjack9650@gmail.com
Chat Now And Get Quote