Advertisement
Guest User

Untitled

a guest
Jan 23rd, 2017
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.17 KB | None | 0 0
  1. import java.util.stream.IntStream;
  2.  
  3. public class MoneyCounter {
  4.  
  5.   private static final int NOTE_VALUE = 0;
  6.   private static final int NOTE_AMOUNT = 1;
  7.   private static final int NUMBER_OF_AVAILABLE_NOTES = 9;
  8.  
  9.   public static void main(String[] args) {
  10.   int[][] noteArray = new int[][] { {500,200,100,50,20,10,5,2,1}, {0,0,0,0,0,0,0,0,0} };
  11.  
  12.   // Textuelle Repraesentation der Banknotenwerte
  13.   String[] noteNames = new String[] { "500$", "200$", "100$", "50$", "20$", "10$", "5$", "2$", "1$" };
  14.  
  15.   // an dieser Stelle wuerde eine Eingabe erfolgen.
  16.   int amountToBeSplit = 999;
  17.  
  18.   // Splitte den Betrag auf die einzelnen Banknoten um
  19.   int currIndex = 0;
  20.   for (int currNoteValue : noteArray[NOTE_VALUE]) {
  21.     noteArray[NOTE_AMOUNT][currIndex++] += amountToBeSplit / currNoteValue;
  22.     amountToBeSplit %= currNoteValue;
  23.   }
  24.  
  25.   // Hier wird ausgegeben
  26.   IntStream.range(0, NUMBER_OF_AVAILABLE_NOTES - 1).forEach(currIndex ->
  27.     System.out.println(noteNames[currIndex] + ": "
  28.     + '\t' + noteArray[NOTE_AMOUNT][currIndex]));
  29.  
  30.   System.out.println("\n" + "Es wurden in Summe "
  31.     + IntStream.of(noteArray[NOTE_AMOUNT]).sum()
  32.     + " Scheine benoetigt");
  33.     }
  34. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement