fubarable

bad code: nested methods

Oct 28th, 2018
178
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.Scanner;
  2.  
  3. class Main {
  4.  
  5.     public static void main(String[] args) {
  6.         new Main().run();
  7.     }
  8.  
  9.     public void run() {
  10.         final int FINE_AMOUNT = 3;
  11.         String userInput = ask("What sentence shall I analyze?");
  12.         int numCharacter = analyzer(userInput);
  13.         Scanner keyboard = new Scanner(System.in);
  14.     }
  15.  
  16.     private String ask (String question) {
  17.         System.out.print(question);
  18.         String input = keyboard.nextLine();
  19.         String finalInput = input.toUpperCase();
  20.         return finalInput;
  21.     }
  22.  
  23.     private int analyzer(String userInput) {
  24.         int letterAnalyzer = userInput.indexOf("S");
  25.         if( letterAnalyzer >= 0 ) {
  26.             int characters = userInput.length();
  27.             return characters;
  28.         } else {
  29.         }
  30.  
  31.         private void calculator(int numCharacter) {
  32.             int totalFine = numCharacter;
  33.             if(totalFine <= 12) {
  34.                 int fine;
  35.                 int fine = 14;
  36.                 System.out.print("That sentence contains a bad word.The fine: 14 zorkmids.");
  37.             } else if(totalFine > 12){
  38.                 int fine;
  39.                 int fine = totalFine * FINE_AMOUNT;
  40.                 System.out.print("That sentence contains a bad word. The fine: " + fine$ +"zorkmids.");
  41.             } else {
  42.                 System.out.print("No bad words found.");
  43.             }
  44.         }
  45.  
  46.     }
  47. }
Add Comment
Please, Sign In to add comment