Advertisement
parkerlreed

Untitled

Sep 25th, 2012
56
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 4.19 KB | None | 0 0
  1. /**
  2.  * ---------------------------------------------------------------------------
  3.  * File name: Project1.java
  4.  * Project name: Project1
  5.  * ---------------------------------------------------------------------------
  6.  * Author’s name and email: Parker Reed parker.l.reed@gmail.com
  7.  * Course-Section: 002
  8.  * Creation Date: 9/25/2012
  9.  * Last modified: (Parker, 9/25/2012, parker.l.reed@gmail.com)
  10.  * ---------------------------------------------------------------------------
  11.  */
  12. import java.util.Scanner; //import to get input from the keyboard
  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, parker.l.reed@gmail.com, 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,     //initializing the variables
  49.                hoursTotal,
  50.                daysTotal,
  51.                yearsTotal; 
  52.         double years = 10;                                  //allowing for the number of years to be changed
  53.         String name;                                        //creating the variable for the user's name
  54.        
  55.         //-----------------------------------------------------------------------------
  56.         // introduce myself and prompt for the user's name
  57.         //-----------------------------------------------------------------------------
  58.         System.out.println("\n\n********************************************************\n");
  59.         System.out.print("Hello, my name is Parker! What is your name? ");  //prompt the user for their name
  60.         name = kb.nextLine();                                               //store their name to the variable name
  61.        
  62.         //-----------------------------------------------------------------------------
  63.         // ask the user for the number of hours they watch TV and store it to hoursTV
  64.         //-----------------------------------------------------------------------------
  65.         System.out.print("\nHello, " + name + "! How many hours of TV do you watch per day (on avg)? ");    //prompt for number of hours
  66.         hoursTV = kb.nextInt();                                                                             //store the number of hours to hoursTV
  67.        
  68.         System.out.println("\n\n********************************************************");
  69.         System.out.print("\n");
  70.        
  71.         //-----------------------------------------------------------------------------
  72.         // calculate and tell the user the number of hours, days, and years they will
  73.         // watch TV in the next 10 years
  74.         //-----------------------------------------------------------------------------
  75.         System.out.println("I bet you didn't realize that in the next " + years + " years\n"
  76.                             + "you could potentially spend a total of...\n");   //print some text with variable years
  77.         hoursTotal = hoursTV * (365 * years);                                   //calculate total hours in 10 years
  78.         System.out.println("\n        " + hoursTotal + " hours, or\n");         //print the total hours in 10 years
  79.         daysTotal = hoursTotal / 24;                                            //calculate total days in 10 years
  80.         System.out.println("        " + daysTotal + " days, or\n");             //print the total days in 10 years
  81.         yearsTotal = hoursTotal / 8760;                                         //calculate total years in 10 years
  82.         System.out.println("        " + yearsTotal + " years watching TV!\n");  //print the total years in 10 years
  83.         System.out.println("That's eye opening isn't it, " + name + "?!\n");    //print some text with their name
  84.         System.out.println("********************************************************\n");
  85.     } //end main
  86. } //end Project1
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement