Hw1 (Simple I/O and Arithmetic Operations)

Total Page:16

File Type:pdf, Size:1020Kb

Hw1 (Simple I/O and Arithmetic Operations)

HRS2422 Hw1 (Simple I/O and arithmetic operations) Directions:  Using WinZip or a similar program, Pack (compress) all of the assignment files into an archive called FirstName_LastNameHw1.zip. Make sure you take a snapshot of your output run on the command prompt window (use Alt+PrintScreen for PCs) and (Apple+Shift-3 for MACs) and save into a document called YourNameOutputRun.doc. Include the document in your Hw1 folder before you compress it.  Submit the zipped/compressed package/archive by using the computer science department submission server, as follows: a) Open My Computer and type the following URL in the Address box ftp:// cs.pitt.edu/khalifa/hrs2422/Hw1 b) To complete the submission, click and drag your compressed folder then release the mouse in the submission window.

 Submission must be before the due date (by 11:59pm), otherwise, it will be considered late.

To compress your assignment: - Store all files in a folder called First_LastNameHw1 - Using windows XP do (Vista or the Mac could be slightly different): [Right-Click on the folder | Send To | Compressed (zipped) Folder] This will create First_LastNameHw1.zip inside your assignment folder.

See Hw-1 grading sheet for details on grading this hw (no need to submit the grading sheet—it will be handed to you with your hw grade recorded on it).

Programming Problem Part-1) Write a program that plays a word game with the user. The program should ask the user to enter the following:  Name, Age, City, College, and Profession After the user has entered these items, the program should display the following story, inserting the user’s input (should be entered in lower case letters then converted/displayed in upper case letters) into the appropriate locations: There once was a person named NAME who lived in CITY. At the age of AGE, NAME went to college at COLLEGE. NAME graduated and went to work as a PROFESSION. Hint-1:The String class has an API method called toUpperCase( );

Going back and forth to work, involved the following: Part-2) In the same pogram code, assume that the user works a certain number of hours each week with a fixed wage-rate, and travels a certain distance to work every day). Ask the user for the following information: - Pay per hour

- No. of work hours per week

- Distance travelled to work

Then compute the weekly salary of the user: Salary = Pay per hour * No. of work hours per week Now output all of this information to the screen (Weekly Salary and Distance travelled to work each day) Hint-2: Use appropriate datatypes for each variable, for example: ‘Name’ which is a sequence of characters would use the ‘string’ datatype, Salary would be of ‘float’ datatype, and Distance would be of datatype ‘double’)

1 Here’s also the skeleton code for the program: import java.util.Scanner;

// Name of the public class is the same as that of the program public class Hw1

{

public static void main(String args[])

{

// Declare your variables here, name is given as an example

String name;

// Read input using java's Scanner class

Scanner scan = new Scanner(System.in);

System.out.println ("Enter your name: ");

name = scan.next();

//Scan other variables here

// Compute Salary

// Output results to screen, similar to the example below

System.out.println ("Hello " + name);

}

}

2 HRS2422: Hw1

Recommended publications