Advertisement
Adumb_Copper

FileStub

Sep 4th, 2015
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.83 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3.  
  4. public class FileStub {
  5.    
  6.     //establishing universal input
  7.     public static final Scanner keyboard = new Scanner(System.in).useDelimiter("\\s");
  8.  
  9.    
  10.    
  11.    
  12.     public static void main(String[] args)
  13.     {
  14.         while (true) //creates loop to allow for multiple creations, sets class fields equal to inputs, asks to go again
  15.         {  
  16.             printClass(getClassName(), getUserName(), getEstimatedTime());
  17.             if (!requestRepeat())
  18.                 break;
  19.         }
  20.     } //end main method
  21.    
  22.    
  23.    
  24.    
  25.     /**
  26.      * Receives user input for class name
  27.      * @return the desired class name as a string
  28.      */
  29.     private static String getClassName()
  30.     {
  31.         System.out.print("What would you like the Class name to be? ");
  32.         return keyboard.nextLine();
  33.     }//end method
  34.    
  35.    
  36.    
  37.    
  38.     /**
  39.      * Receives user input for user name
  40.      * @return the desired user name as a string
  41.      */
  42.     private static String getUserName()
  43.     {
  44.         System.out.print("\nWhat is your username? ");
  45.         return keyboard.nextLine();
  46.     }//end method
  47.    
  48.    
  49.    
  50.    
  51.     /**
  52.      * Receives user input for estimated time
  53.      * @TODO: @throws any non-integers
  54.      * @return estimated completion time as an integer array
  55.      */
  56.     private static int[] getEstimatedTime()
  57.     {
  58.         int returnTime[] = new int[3];
  59.        
  60.         System.out.println("\nHow much time do you think it will take to create this?");
  61.        
  62.         System.out.print("Days: ");
  63.         returnTime[0] = keyboard.nextInt();
  64.         System.out.print("Hours: ");
  65.         returnTime[1] = keyboard.nextInt();
  66.         System.out.print("Minutes: ");
  67.         returnTime[2] = keyboard.nextInt();
  68.        
  69.         return returnTime;
  70.     }//end method
  71.    
  72.    
  73.  
  74.    
  75.     /**
  76.      * prints full class start
  77.      * @param className
  78.      * @param userName
  79.      * @param estimatedTime - estimated time of completion
  80.      */
  81.     private static void printClass(String className, String userName, int[] estimatedTime)
  82.     {
  83.         printClassComment(className, userName, estimatedTime);
  84.         printClassDeclaration(className);
  85.     }//end method
  86.    
  87.    
  88.    
  89.    
  90.     /**
  91.      * Generates and prints a class comment for a java program
  92.      * @param className
  93.      * @param userName
  94.      * @param estimatedTime - Estimated time of completion
  95.      */
  96.     private static void printClassComment(String className, String userName, int[] estimatedTime)
  97.     {
  98.         System.out.println("\nGenerating class... \n\n");
  99.        
  100.         System.out.println("/**\n*\n*@author " + userName + "\n*@version \n*\n* Estimated Completion Time: " + convertedTime(estimatedTime) +
  101.                 "\n* Actual Completion Time: \n*\n*Notes: \n*/");
  102.     }//end method
  103.    
  104.    
  105.    
  106.    
  107.     /**
  108.      * Generates and prints a class declaration for a java program
  109.      * @param n - the previously decided class name
  110.      */
  111.     private static void printClassDeclaration(String name)
  112.     {
  113.         System.out.println("\npublic class " + name + "\n{\n    \n  public static void main(String[] args)\n    {\n     \n  }//end main method\n\n}//end class");
  114.     }//end method
  115.    
  116.    
  117.    
  118.    
  119.     /**
  120.      * Asks the user if they would like to start over
  121.      * @return true if the user would like to start over, false otherwise
  122.      */
  123.     private static boolean requestRepeat()
  124.     {
  125.         while (true)
  126.         {
  127.             System.out.print("\n\nWould you like to make another? ");
  128.             if (keyboard.nextLine().toUpperCase().equals("Y"))
  129.                 return true;
  130.             else if (keyboard.nextLine().toUpperCase().equals("N"))
  131.                 return false;
  132.         }
  133.     }//end method
  134.    
  135.    
  136.    
  137.    
  138.     /**
  139.      * Converts estimated time into a more readable string
  140.      * @param time
  141.      * @return time in days, hours, minutes
  142.      */
  143.     private static String convertedTime(int[] time)
  144.     {
  145.         String dayString = "";
  146.         String hourString = "";
  147.         String minString = "";
  148.        
  149.         //putting given time values into strings
  150.         if (time[0] > 0)
  151.             dayString += time[0] + " days ";
  152.         if (time[1] > 0)
  153.             hourString += time[1] + " hours ";
  154.         if (time[2] > 0)
  155.             minString += time[2] + " minutes";
  156.        
  157.         return dayString + hourString + minString;
  158.     }//end method
  159.    
  160.    
  161.    
  162. }//end class
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement