Created
December 8, 2020 23:58
-
-
Save mrmemmo/72be71cfee6e37aa9e4c61076b6acfb0 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* the MonthlyBudget class will be provided a limit (example, $200), | |
* a string array of items (netflix, gym membership, spotify premium, etc) | |
* a parallel int array of prices for each item (15, 50, 8, etc) | |
* | |
* The monthlyBudget class should also keep track of a current budget | |
* and | |
* a myItems arraylist that tracks items that fit in your budget | |
* | |
* You will create the entire MonthlyBudget class | |
* which will include three methods | |
* 1) the constructor method | |
* 2) the ArrayList<String> assignRandomItems() method - this method continues to assign | |
* random items from the items array to your myItems list until the limit is exceeded | |
* The items that exceeds the item should not be added to the list | |
* If all items are added the method should end and return the myItems arraylist | |
* | |
* 3) a method that returns the budget value | |
* | |
BELOW is the Runner Class that should be used as a separate class (in it's own file) to test out your | |
MonthlyBudget class | |
*/ | |
import java.util.*; | |
public class MBRunner | |
{ | |
public static void main(String[] args) | |
{ | |
String[] i = {"netflix", "gym membership", "spotify premium", "Amazon Prime", "Wall Street Journal", "tennis"}; | |
int[] p = {15, 50, 8, 10, 15, 35}; | |
int l = 75; | |
MonthlyBudget mb = new MonthlyBudget(l,i,p); | |
System.out.println(mb.getBudget()); | |
ArrayList<String> mi = mb.assignRandomItems(); | |
for(String s : mi){ | |
System.out.print(s + " : " ); | |
} | |
System.out.println(); | |
System.out.print(mb.getBudget()); | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment