Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package helloworld;
- /**
- *
- * @author Joshua George
- */
- public class PrintRelevantOutput {
- /**
- * @param args the command line arguments
- */
- public static void main(String[] args) {
- // TODO code application logic here
- PrintRelevantOutput printRelevantOutput = new PrintRelevantOutput();
- printRelevantOutput.printItemDescription("Avenger", 0);
- }
- /**
- *
- * @param item The item is what the description will be about.
- * @param amount The amount refers to how many of the item there are.
- *
- * This method will print a short description to the console about the item depending on the amount.
- */
- public void printItemDescription(String item, int amount){
- String v, n, p;
- // Main differences in the end description depend on the base cases of 0 and 1, everything else will have the same description.
- switch(amount){
- case 0:
- v = "are";
- n = "no";
- p = "s";
- break;
- case 1:
- v = "is";
- n = "1";
- p = "";
- break;
- default:
- v = "are";
- n = "" + amount;
- p = "s";
- break;
- }
- // Printing the final description to the console.
- System.out.println("There " + v + " " + n + " " + item + p);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment