Advertisement
Guest User

Untitled

a guest
Nov 17th, 2019
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 4.06 KB | None | 0 0
  1. package ls223iu_assign1;
  2.  
  3. import java.util.Scanner;
  4.  
  5. public class Vaxel {
  6.     public static void main(String[] args) {
  7.         Scanner sc = new Scanner(System.in);
  8.         System.out.println("Ange varans pris, och sedel du betalar med.");
  9.         System.out.print("Pris: ");
  10.         float price = sc.nextFloat();
  11.         System.out.print("Betalning: ");
  12.         int customerPayment = sc.nextInt();
  13.         int change = Math.round(customerPayment - price);
  14.         System.out.println("Växel: " + change);
  15.  
  16.         int thousand = 0;
  17.         int fivehundred = 0;
  18.         int twohundred = 0;
  19.         int onehundred = 0;
  20.         int fifty = 0;
  21.         int twenty = 0;
  22.         int ten = 0;
  23.         int five = 0;
  24.         int two = 0;
  25.         int one = 0;
  26.  
  27.         if (change >= 1000) {
  28.             change -= 1000;
  29.             thousand++;
  30.         }
  31.         if (change >= 500) {
  32.             change -= 500;
  33.             fivehundred++;
  34.         }
  35.         if (change >= 200) {
  36.             change -= 200;
  37.             twohundred++;
  38.         }
  39.         if (change >= 100) {
  40.             change -= 100;
  41.             onehundred++;
  42.         }
  43.         if (change >= 50) {
  44.             change -= 50;
  45.             fifty++;
  46.         }
  47.         if (change >= 20) {
  48.             change -= 20;
  49.             twenty++;
  50.         }
  51.         if (change >= 10) {
  52.             change -= 10;
  53.             ten++;
  54.         }
  55.         if (change >= 5) {
  56.             change -= 5;
  57.             five++;
  58.         }
  59.         if (change >= 2) {
  60.             change -= 2;
  61.             two++;
  62.         }
  63.         if (change >= 1) {
  64.             change -= 1;
  65.             one++;
  66.         }
  67.         // Andra "loopen"
  68.         if (change >= 1000) {
  69.             change -= 1000;
  70.             thousand++;
  71.         }
  72.         if (change >= 500) {
  73.             change -= 500;
  74.             fivehundred++;
  75.         }
  76.         if (change >= 200) {
  77.             change -= 200;
  78.             twohundred++;
  79.         }
  80.         if (change >= 100) {
  81.             change -= 100;
  82.             onehundred++;
  83.         }
  84.         if (change >= 50) {
  85.             change -= 50;
  86.             fifty++;
  87.         }
  88.         if (change >= 20) {
  89.             change -= 20;
  90.             twenty++;
  91.         }
  92.         if (change >= 10) {
  93.             change -= 10;
  94.             ten++;
  95.         }
  96.         if (change >= 5) {
  97.             change -= 5;
  98.             five++;
  99.         }
  100.         if (change >= 2) {
  101.             change -= 2;
  102.             two++;
  103.         }
  104.         if (change >= 1) {
  105.             change -= 1;
  106.             one++;
  107.         }
  108.         // Tredje loopen
  109.         if (change >= 1000) {
  110.             change -= 1000;
  111.             thousand++;
  112.         }
  113.         if (change >= 500) {
  114.             change -= 500;
  115.             fivehundred++;
  116.         }
  117.         if (change >= 200) {
  118.             change -= 200;
  119.             twohundred++;
  120.         }
  121.         if (change >= 100) {
  122.             change -= 100;
  123.             onehundred++;
  124.         }
  125.         if (change >= 50) {
  126.             change -= 50;
  127.             fifty++;
  128.         }
  129.         if (change >= 20) {
  130.             change -= 20;
  131.             twenty++;
  132.         }
  133.         if (change >= 10) {
  134.             change -= 10;
  135.             ten++;
  136.         }
  137.         if (change >= 5) {
  138.             change -= 5;
  139.             five++;
  140.         }
  141.         if (change >= 2) {
  142.             change -= 2;
  143.             two++;
  144.         }
  145.         if (change >= 1) {
  146.             change -= 1;
  147.             one++;
  148.         }
  149.         // Skriv ut resultat
  150.         System.out.println("1000 kr-sedlar: " + thousand);
  151.         System.out.println("500 kr-sedlar: " + fivehundred);
  152.         System.out.println("200 kr-sedlar: " + twohundred);
  153.         System.out.println("100 kr-sedlar: " + onehundred);
  154.         System.out.println("50 kr-sedlar: " + fifty);
  155.         System.out.println("20 kr-sedlar: " + twenty);
  156.         System.out.println("10 kr-sedlar: " + ten);
  157.         System.out.println("5 kr-sedlar: " + five);
  158.         System.out.println("2 kr-sedlar: " + two);
  159.         System.out.println("1 kr-sedlar: " + one);
  160.     }
  161. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement