Guest User

Untitled

a guest
Jan 6th, 2018
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.47 KB | None | 0 0
  1. package helloworld;
  2.  
  3. /**
  4.  *
  5.  * @author Joshua George
  6.  */
  7. public class PrintRelevantOutput {
  8.  
  9.     /**
  10.      * @param args the command line arguments
  11.      */
  12.     public static void main(String[] args) {
  13.         // TODO code application logic here
  14.         PrintRelevantOutput printRelevantOutput = new PrintRelevantOutput();
  15.         printRelevantOutput.printItemDescription("Avenger", 0);
  16.     }
  17.    
  18.     /**
  19.      *
  20.      * @param item The item is what the description will be about.
  21.      * @param amount The amount refers to how many of the item there are.
  22.      *
  23.      * This method will print a short description to the console about the item depending on the amount.
  24.      */
  25.     public void printItemDescription(String item, int amount){
  26.         String v, n, p;
  27.        
  28.         // Main differences in the end description depend on the base cases of 0 and 1, everything else will have the same description.
  29.         switch(amount){
  30.             case 0:
  31.                 v = "are";
  32.                 n = "no";
  33.                 p = "s";
  34.                 break;
  35.             case 1:
  36.                 v = "is";
  37.                 n = "1";
  38.                 p = "";
  39.                 break;
  40.             default:
  41.                 v = "are";
  42.                 n = "" + amount;
  43.                 p = "s";
  44.                 break;
  45.         }
  46.        
  47.         // Printing the final description to the console.
  48.         System.out.println("There " + v + " " + n + " " + item + p);      
  49.     }
  50. }
Advertisement
Add Comment
Please, Sign In to add comment