Write a program that converts a Roman number such as MCMLXXVIII to its decimal number representation. Hint: First write a method that yields the numeric value of each of the letters. Then use the following
total = 0
str = roman number string
While str is not empty
If str has length 1, or value(first character of str) is at least value(second character of str)
Add value(first character of str) to total.
Remove first character from str.
Else
difference = value(second character of str) - value(first character of str)
Add difference to total.
Remove first character and second character from str.
Want to see the full answer?
Check out a sample textbook solutionChapter 5 Solutions
Big Java Late Objects
Additional Engineering Textbook Solutions
Software Engineering (10th Edition)
Modern Database Management
Starting Out with C++ from Control Structures to Objects (9th Edition)
Concepts Of Programming Languages
C Programming Language
Java: An Introduction to Problem Solving and Programming (7th Edition)
- Q1: Write a program that reads a set of N integers. Then, the program finds and outputs the sum of the even values and the sum of the odd values of them. For example: if the value entered for N=5, and the five integers are 3, 6, 2, 9, 7. Then the sum of even values (6+2 = 8), and the sum of odd values (3+9+7 = 19) Q2: Write a program that reads some numbers until it reaches a specific value (assume -1 is a stop value in this case). The program should find and outputs the average of all of the numbers (between 10...40) except the stop value (-1). For example: If the numbers look like: 12 5 30 48 -1. Then, the average of the numbers: (12+30)/2 = 21.arrow_forwardpublic static String pancakeScramble(String text) This nifty little problem is taken from the excellent Wolfram Challenges problem site where you can also see examples of what the result should be for various arguments. Given a text string, construct a new string by reversing its first two characters, then reversing the first three characters of that, and so on, until the last round where you reverse your entire current stringarrow_forwardIn Python, The function add_char_counts takes three parameters: a string s and two strings of length 1, char1 and char2, and returns the total number of times either char1 or char2 appears in s. For example, the word "scallions" has 2 s's and 1 n, so add_char_counts("scallions", "s", "n") returns 3. Hint: Use a string method to help solve this problem (count). You do not need an accumulator. For example: Test Result print(add_char_counts('Indiana', 'a', 'b')) 2 print(add_char_counts('BAHAMAS', 'A', 'B')) 4 print(add_char_counts('Mississippi', 'i', 'M')) 5 print(add_char_counts("spam spam spam spam", "s", "p")) 8arrow_forward
- in java plarrow_forwardLanguage: Java Write a program that reads a sentence from the keyboard. Depending on the last character of the sentence, print the message identifying the sentence as declarative (ends with a period), interrogative (ends with a question mark), exclamatory (end with an exclamation point), or other. Hint: you can use charAt() method from the String class to extract the last character of the input line. The character of a String str is at str.length()-1 position. For taking a sentence as input use the nextLine() method from the Scanner class. You have to use if/else if selection. Sample input and output: Sample 1 Input: How are you? Output: Interrogative Sample 2 Input: I am good. Output: Declarative Sample 3 Input: That is amazing! Output: Exclamatory Sample 4 Input: Although, Output: Other Answer:arrow_forwardWrite a method that counts the number of letters ina string using the following header:public static int countLetters(String s)Write a test program that prompts the user to enter a string and displays the numberof letters in the string.arrow_forward
- Coding language: Javaarrow_forwardpublic static String pancakeScramble(String text) This nifty little problem is taken from the excellent Wolfram Challenges problem site where you can also see examples of what the result should be for various arguments. Given a text string, construct a new string by reversing its first two characters, then reversing the first three characters of that, and so on, until the last round where you reverse your entire current string.This problem is an exercise in Java string manipulation. For some mysterious reason, the Java String type does not come with a reverse method. The canonical way to reverse a Java string str is to first convert it to mutable StringBuilder, reverse its contents, and convert the result back to an immutable string, that is,str = new StringBuilder(str).reverse().toString(); Here's the tester it must pass: @Test public void testPancakeScramble() throws IOException {// Explicit test casesassertEquals("", P2J3.pancakeScramble(""));assertEquals("alu",…arrow_forwardIn Java code do the following:Write a method that accepts a String as an argument. The method should use recursion to display each individual character in the String:arrow_forward
- Java program:; User's name. Write a program that prompts for and reads the user's first and last name (separately). Then print a string composed of the first letter of the user's first name, followed by the first five characters of the user's last name, followed by a random number in the range 10 to 99. Assume that the name is at least five letters long. Similar algorithms are sometimes used to generate user names for new computer accounts. wwwarrow_forwardLab Activity: In python.arrow_forwardIn pythonarrow_forward
- EBK JAVA PROGRAMMINGComputer ScienceISBN:9781337671385Author:FARRELLPublisher:CENGAGE LEARNING - CONSIGNMENT