Java程序辅导

C C++ Java Python Processing编程在线培训 程序编写 软件开发 视频讲解

客服在线QQ:2653320439 微信:ittutor Email:itutor@qq.com
wx: cjtutor
QQ: 2653320439
Assignment 2 Assignment #2 Due: Tuesday, February 12th. We are going to get some practice using conditional and repetition statements. Using if statements: Task 1 Prompt the user to enter a value between 1 and 10. Print out the equivalent Roman numerals. Please name the file: ConditionEx1.java Sample run 1: (user input underlined) Please enter a number (1 - 10): 7 7 : VII Sample run 2: (user input underlined) Please enter a number (1 - 10): 11 The value you entered is not valid. Sample run 3: (user input underlined) Please enter a number (1 - 10): 10 10 : X Task 2 Write a program that converts Celsius temperature to Fahrenheit temperature (F = 9/5C+32) or Fahrenheit temperature to Celsius temperature (C = 5/9(F-32)). Prompt the user to determine which conversion to do and to obtain the temperature. Please name the file: ConditionEx2.java Sample run 1: (user input underlined) F - Convert Celsius to Fahrenheit. C - Convert Fahrenheit to Celsius. > F Enter temperature: 32.89 32.89C equals 91.20F. Thank you, good bye! Sample run 2: (user input underlined) F - Convert Celsius to Fahrenheit. C - Convert Fahrenheit to Celsius. > c Enter temperature: 91.20 91.20F equals 32.89C. Thank you, good bye! Sample run 3: (user input underlined) F - Convert Celsius to Fahrenheit. C - Convert Fahrenheit to Celsius. > a Unknown selection. Thank you, good bye! Note: We've used the Scanner class so far to enter numbers, but in this program, the user will need to enter a character (into a character variable). However, note that the Scanner class does not have a nextChar method. Instead, here's the easiest way to get a single character with a Scanner: The method next() will return the next token (by default this is a "word", with white space). It will come back to you as a String You can use a method from the String class library to get the first letter of this string. The method is called charAt(), and to get the first letter, pass in the index 0 Example: (Suppose sc is a Scanner object) int x = sc.nextInt(); // this reads an int double y = sc.nextDouble(); // this reads a double String s = sc.next(); // this reads a single word as a string char c = s.charAt(0); // stores the first letter of the string // into a character variable c Task 3 Write a program that converts total seconds (given by the user through a prompt) into days, hours, minutes, seconds. Some numbers: 60 seconds in a minute. 3,600 seconds in an hour. 86,400 second in a day. Please name the file: ConditionEx3.java Sample run 1: (user input underlined) Enter total number of seconds: 102548 1d:4h:29m:8s Sample run 2: (user input underlined) Enter total number of seconds: 56890 0d:15h:48m:10s Using the while and for Loop statements Task 2 Write a program that displays a conversion table for Celsius temperatures. The user should be prompted for the range of the table. The program should then loop through and print out the table. Fahrenheit temperatures should be printed to two decimal places. Please name the file: RepetitionEx1.java Sample run 1: (user input underlined) Where should the table start? > 10 Where should the table end? > 20 10C equals 50.00F 11C equals 51.80F 12C equals 53.60F 13C equals 55.40F 14C equals 57.20F 15C equals 59.00F 16C equals 60.80F 17C equals 62.60F 18C equals 64.40F 19C equals 66.20F Sample run 2: (user input underlined) Where should the table start? > 20 Where should the table end? > 10 The start value has to be less than the end value. Task 1 Write a program that prompts the user for input a number of iterations a loop should run. For each iteration the user should be prompted to enter an integer number. This number should be added to a running total of the entered values. At the end of the iteration the total should be printed as well as the average of the total (to two decimal places). Please name the file: RepetitionEx2.java Sample run 1: (user input underlined) Number of iterations: 10 Enter number 1: 1 Enter number 2: 34 Enter number 3: 23 Enter number 4: 54 Enter number 5: 67 Enter number 6: 3 Enter number 7: 21 Enter number 8: 14 Enter number 9: 15 Enter number 10: 56 Total: 288 Ave : 28.80 Sample run 2: (user input underlined) Number of iterations: 7 Enter number 1: 4 Enter number 2: 67 Enter number 3: 89 Enter number 4: 23 Enter number 5: 12 Enter number 6: 4 Enter number 7: 43 Total: 242 Ave : 34.57 General Requirements When you write source code, it should be readable and well-documented. See the link Style Guidelines for further instructions on this topic Compiling and testing Compilation instructions for various environments are on the course web site, under the heading "Compilers and Compiling Help". These include instructions for building projects in both NetBeans and Eclipse, as well as compiling from the command line on your CS account or from the DOS prompt. Make sure to test your program with a variety of different inputs. The Sample Runs above are just that -- examples, only. Never hard-code your programs to work for only one or two test cases. Your program should work and calculate the correct results for any set of valid inputs. Submitting: Program submissions should be done by using the web site http://cgs3416.swzinc.org. Add the file(s) ConditionEx1.java, ConditionEx2.java, ConditionEx3.java, RepetitionEx1.java, and RepetitionEx2.java to your submission. Do not send program submissions through e-mail -- e-mail attachments will not be accepted as valid submissions. General Advice - always keep an untouched copy of your finished homework files on your computer science account, or e-mail a copy of your finished files (before the due date) to your own FSU e-mail account. This way, these files will have a time-stamp which will show when they were last worked on (a timestamp from the CS servers, or a time stamp on the FSU e-mail) and will serve as a backup in case you ever have problems with submitting files. My advice is to do this for ALL programs. For HW #2, submit only the following file: ConditionEx1.java ConditionEx2.java ConditionEx3.java RepetitionEx1.java RepetitionEx2.java Make sure your filenames are these exact name(s), and do not submit the Driver.java file (or any other main program you might create for testing purposes).