Description
Part A: These questions are to be submitted to the instructor in the form of a Word (or Open Office) document containing the Java code and appropriate screen capture(s) of the output. Put both questions in the same word file. The file name must be in the form ASSIGN7A_YourName where ‘YourName’ is your last name followed by your first name with no space. Upload the file to CMS.
Problem 7.3, page 277 Show your program working with the data in the question plus the following set of numbers: 8 6 2 4 6 3 6 8 7 2 3 4 5 9 0 8 and 18 39 37 8 28 27 18 4 30 37 38 39 18 28.
Special Problem 1: Strings with the Same Letters A professor assigned a program to his class for which the output is a string of lower-case letters. Unfortunately, he did not specify an ordering of the characters in the string, so he is having difficulty grading student submissions. Because of that, he has requested your help by writing a program that inputs pairs of strings and determines whether or not the strings have the same letters, though possibly in different orders. Note that repeated letters are important; the string “abc” and “aabbbcccc” are not viewed as having the same letters since the second one has more copies of each letter.
The input to be processed will consist of a pair of strings entered by the user. Each string will need to be converted to lower case – just in case some of the input has upper case letters. If the first string is the word “end” (in any case), the terminate the program – otherwise keep looping.
If all the characters in the first string match all the characters in the second string, then indicate that the two strings are the SAME – otherwise indicate that they are DIFFERENT.
Hint: Use an array to keep track of how many of each letter you have in the string.
COSC 1046 (F15) – Introduction to Computer Science
Enter the first string: testing Enter the second string: intestg They are the same.
Enter the first string: aBc Enter the second string: aabBBCCcc They are different.
Enter the first string: AbcaBcbcc Enter the second string: aabbbCCcc They are the same.
Enter the first string: EnD Goodbye.
Provide screen shots showing 3 examples of matches (at least 5 characters and not identical) and 3 non-matching examples.
Part B: Write code and test the solutions for the following problems from the textbook. Submit the .java files for each question to CMS. The answers are due on November 21st and the programs are to be demonstrated to the Teaching Assistant (Tim) by November 24th. He will ask questions to make sure you understand the material.
Special Problem 2: What Do I Need to get on the Final Exam One typical question that students ask professors right before the final exam in a course is what score they need on the final exam in order to get a grade that they want. Your task is to write a program that automates the answer to this question.
Your program must be able to handle multiple situations – and therefore loop. The input for each situation will consist of nonnegative integers that are all at most 100 since we are assuming any test score will be at least 0 and at most 100. a) The first integer will be the desired average, d, which will be assumed to be greater than zero and less than 100. If the integer is negative, then exit the program. b) The next integer will be the number of tests (including the final exam) – let us call this k. You may assume that k is at least 2 and at most 10.
COSC 1046 (F15) – Introduction to Computer Science
c) Then, there will be k integers giving the percentage weights for the tests. You may assume that the sum of the weights is 100 – that is, you do not need to check for this condition. d) Finally, the scores on the k – 1 tests before the final are given as input. In other words, you will provide the grade for all the tests except the final exam and they will be out of 100. e) Assuming, again, that a final exam grade is at least 0 and at most 100, determine if there is a final exam grade that will achieve the desired result. If there is such a grade, the smallest such is the answer for the case and you will report this. If there is no valid solution (the answer is 100) then indicate “It is impossible”. f) You must use at least one array (more likely two arrays) for this question.
What average do you want from the course? 90 How many tests, including the final, are there? 4 Please provide the test weights: 25 25 25 25 Please provide the test grades out of 100: 85 87 91 You can achieve an average of 90 with a final exam grade of: 97
What average do you want from the course? 90 How many tests, including the final, are there? 5 Please provide the test weights: 15 25 15 25 20 Please provide the test grades out of 100: 87 62 47 91 It is impossible to achieve an average of 90.
What average do you want from the course? -1 Goodbye
Problem 8.5, [15] page 306-307: Modify the program so that it performs subtraction as well. The output would be the same as the addition – only using a subtraction sign. Print the subtraction results right after the addition results.