parkerlreed

Untitled

Sep 25th, 2012
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.65 KB | None | 0 0
  1. /**
  2.  * ---------------------------------------------------------------------------
  3.  * File name: Project1.java
  4.  * Project name: Project1
  5.  * ---------------------------------------------------------------------------
  6.  * Author’s name and email: Parker Reed [email protected]
  7.  * Course-Section: 002
  8.  * Creation Date: 9/25/2012
  9.  * Last modified: (Parker, 9/25/2012, [email protected])
  10.  * ---------------------------------------------------------------------------
  11.  */
  12. import java.util.Scanner;
  13.  
  14. /**
  15.  * Class Name: Project1 <br>
  16.  * Class Purpose: Project1 <br>
  17.  *
  18.  * <hr>
  19.  * Date created: 9/25/2012
  20.  * Last modified: Parker Reed, [email protected], 9/25/2012
  21.  * @author Parker Reed
  22.  */
  23. public class Project1
  24. {
  25.     /**
  26.      * Method Name: main <br>
  27.      * Method Purpose: To develop a simple program in Java that will interact with the
  28.      *      user through some dialog. It will ask the user for their name and the
  29.      *      and the number of hours of TV they watch per day. The program will then
  30.      *      display the total hours, days, years in 10 years they will have watched.
  31.      *     
  32.      * <hr>
  33.      * Date created: 9/25/2012 <br>
  34.      * Last modified: 9/25/2012 <br>
  35.      *
  36.      * <hr>
  37.      * Notes on specifications, special algorithms, and assumptions:
  38.      * There are 24 hours in a day, 365 days in a year. Does not account for leap years.
  39.      *
  40.      * <hr>
  41.      *   @param  String[] args - Command Line Arguments
  42.      */
  43.     public static void main(String[] args)
  44.     {
  45.         //***************************VARIABLE DECLARATIONS*****************************
  46.        
  47.         Scanner kb = new Scanner(System.in);                //to get input from keyboard
  48.         double hoursTV, hoursTotal, daysTotal, yearsTotal;  //initializing the variables
  49.         double years = 10;                                  //allowing for the number of years to be changed
  50.         String name;                                        //creating the variable for the user's name
  51.        
  52.         //-----------------------------------------------------------------------------
  53.         // introduce myself and prompt for the user's name
  54.         //-----------------------------------------------------------------------------
  55.         System.out.println("\n\n********************************************************\n");
  56.         System.out.print("Hello, my name is Parker! What is your name? ");
  57.         name = kb.nextLine();
  58.        
  59.         //-----------------------------------------------------------------------------
  60.         // ask the user for the number of hours they watch TV and store it to hoursTV
  61.         //-----------------------------------------------------------------------------
  62.         System.out.print("\nHello, " + name + "! How many hours of TV do you watch per day (on avg)? ");
  63.         hoursTV = kb.nextInt();
  64.        
  65.         System.out.println("\n\n********************************************************");
  66.         System.out.print("\n");
  67.        
  68.         //-----------------------------------------------------------------------------
  69.         // calculate and tell the user the number of hours, days, and years they will
  70.         // watch TV in the next 10 years
  71.         //-----------------------------------------------------------------------------
  72.         System.out.println("I bet you didn't realize that in the next " + years + " years\n"
  73.                             + "you could potentially spend a total of...\n");
  74.         hoursTotal = hoursTV * (365 * years);
  75.         System.out.println("\n        " + hoursTotal + " hours, or\n");
  76.         daysTotal = hoursTotal / 24;
  77.         System.out.println("        " + daysTotal + " days, or\n");
  78.         yearsTotal = hoursTotal / 8760;
  79.         System.out.println("        " + yearsTotal + " years watching TV!\n");
  80.         System.out.println("That's eye opening isn't it, " + name + "?!\n");
  81.         System.out.println("********************************************************\n");
  82.     } //end main
  83. } //end Project1
Advertisement
Add Comment
Please, Sign In to add comment