/* This program illustrates getting user input from the keyboard * using the Scanner class and writing output to a console window using * System.out.println() and System.out.print(). * * The exercise involves creating simple java objects and writing some object methods * Notes reference: * 1.4 Getting User Input * 1.5 Using Objects in Java * 2.1 Object Constructors * 2.4 Defining Methods * * This demonstration program asks you for your name and student number and writes it to the * console window along with today's date. * * This program requires at least Java version 1.5 to run */ import java.util.*; public class Problem1Main{ public static void main(String[] args){ //define the variables that will be used and their type Scanner keyboard; //for reading from the keyboard Date today; Person p = new Person(); String songTitle; //create a Date object representing today's date today = new Date(); //create scanner for reading user input from keyboard keyboard = new Scanner(System.in); //obtain user's name and userid by prompting them and then //reading their keyboard reponse System.out.print("Enter your name and ENTER: "); //prompt user p.name = keyboard.nextLine(); //read user input as a String System.out.print("Enter your .connect userID and ENTER: "); //prompt user p.userID = keyboard.nextLine(); //read user input as a String String input = ""; songTitle = null; System.out.print("Enter a song title and ENTER (ENTER to Quit): "); //prompt user //Loop collecting song names from user until they enter //a blank song while(!(input = keyboard.nextLine().trim() ).isEmpty()){ songTitle = input; System.out.println(input); System.out.print("Enter title of a favourite song: "); //prompt user } //output the data collected System.out.println(""); //output a blank line System.out.println("Data Collected"); System.out.println("=============="); System.out.println("Today: " + today); p.print(); } } //end class UserInputOutput