Advertisement
advictoriam

Untitled

Dec 7th, 2018
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.16 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. /**
  4.    This program reads information about coins and
  5.    prints the value of the coins.
  6. */
  7. public class Coins
  8. {
  9.    public static void main(String[] args)
  10.    {
  11.       // Define constants
  12.       final String P_TYPE = "P";
  13.       final String N_TYPE = "N";
  14.       final String D_TYPE = "D";
  15.       final String Q_TYPE = "Q";
  16.  
  17.       // Read a number and type of coin
  18.       System.out.println("Enter number and type of coins: ");
  19.  
  20.       Scanner in = new Scanner(System.in);
  21.       int numCoins = in.nextInt();
  22.       String typCoin = in.next();
  23.  
  24.       // Determine and print worth of coin pile
  25.  
  26.       // Use output statements
  27.       double value;
  28.       switch(typCoin)
  29.       {
  30.          case "P":
  31.             value = 0.01d * numCoins;
  32.             break;
  33.          case "N":
  34.             value = 0.05d * numCoins;
  35.             break;
  36.          case "D":
  37.             value = 0.10d * numCoins;
  38.             break;
  39.          case "Q":
  40.             value = 0.25d * numCoins;
  41.             break;
  42.          default:
  43.             System.out.println("Error");
  44.             return;
  45.       }
  46.      
  47.       System.out.printf("%.2f\n", value);
  48.    }
  49. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement