Question
Create a java file called clsCurrencyConversion.java. DO not add a main() method. conversion Rates; dollar-1, pund-0.0091, peso-0.054, euro-1.09, bitcoin-9874.44. Creat 6 constant variables of type
Create a java file called clsCurrencyConversion.java. DO not add a main() method.
conversion Rates; dollar-1, pund-0.0091, peso-0.054, euro-1.09, bitcoin-9874.44. Creat 6 constant variables of type double named YENTODOLLAR, POUNDTODOLLAR, PESOTODOLLAR, EUROTODOLLAR, BITCOINTODOLLAR. Assing th conversion rate.
Create two private instance variables of type String named stroriginalCurrency and strconvertedCurrency.
Create two private instance variables of type double named dbloriginalValue and dblconvertedValue.
Creat a method with the signature public void currencyToDollar(). This method will not take any parameter and will not return anything. This method will be used to convert a given amount in some currency to US Dollars and stored in the instance variable dblconvertedValue.
int the body of the method do the following: Use a switch statement to determine the value of th string stored in stroriginalCurrency.. In the body of the switch statement, use the 6 cases for currency values "us dollar", "yen", "pound", "peso", "euro", and "bitcoin". For each case stop th result of dbloriginalValue multiplied by the appropriate conversion constant created. Store the result in the variable dblconvertedValue. Add a default case and print "Currency < original currency > is not supported." Set the value of stroriginalCurrency to "error"'
Add a javaDoc comment before the method signature with an explanation of you choice. the JavaDoc must be a complete sentence and explain what the method does. The parameters and return value must be explained.
Create a method with the signature public void dollarToCurrency(). This method will not take any parameters and will not return anything. This method will be used to convert a stored amount in US Dollars and convert to a different currency stored in the instance variable strconvertedCurrency. In th body of th method do the following:
Call the currencyToDollar() and dollarToCurrency() methods. Use an if....else decision structure to determine if the value stored in strconvertedCurrency or strotiginalCurrency equals "error". if either value is "error" return 0 otherwise, return the value stored in dblconvertedValued.
Add a JavaDoc comment before the method signature with an explanation. Create a method with the signature private String sanitize(String steward). this method will take one parameter of type String names steward and will return a string which is the result of removing whitespace, converting to lowercase and remove and "s" form the end of plural words. In the body fo the method, do the following: Use .trim() to remove whitespace. Use .toLowerCase() to convert string to lowercase. Us and if decision structure to determine if the string strword end with an "s". If i ens in "s" use.substring() to remove the last letter from strword. HINT: Strings are immutable, you need to overwrite the variable when calling a method on a string. Return the sanitized string.
Add a JavaDoc comment before the method signature with an explanation. Create a method with the signature public void commandParser(String strcommand). This method will parse a string and store the value of th original currency, the name of the original currency adnthe name of the currency to convert to. Assume the string will be of the form '< numerical amount > < currency name > to < currency name>"
In th body of the method do the following: Create a local variable of type int named firstSpaceLocation and store the location of the first space character in strcommand. Create a local variable of type int named seconSpaceLocation and store the location of th second space character in strcomnand. HINT: Since index() only finds the location of the first occurrence, consider using a substring() of strcommand starting th substring after the first space character.
Create a local variable of type int named lastSpaceLocation and store the location of the last space character in strcommand.
create a local variable fo type double named amount and store the result of the Double class method .parseDouble() to parse the substring of the String strcommand from the first space character to the location before the second space character.
Creat a local variable of type String name newCurrency and store the result of the substring form the location of the last space character to the end of the string. Assign the instance variable dblorigninalValue to the local variable amount. Assign the instance variable stroriginalCurrency to the result of using sanitize() on the String originalCurrency. Assign the instance variable strconvertedCurrency to the result of using sanitize() on the String newCurrency. Add a JavaDoc comment to explain.
Create a java file named clsCurrencyconversionCalculater. java in the same project folder as clscurrencyconversion.java. Add a main() method to clscurrencyconversioncalculator.java. In the main method do the following: Creat a variable to type Scanner named scnUserInput using System.in inputStream. Create a variable of type clsCurrencyCOnversion names currencyObj. Create a variable of type String named sturserCommand andassign the empty string to struserCommand. Print the string literal "Welcome's toe CS110 Currency Conversion Calculator" to the console.
Use a sentinel-controlled loop that executes until strUserCommand is the string literal "quit". In the body of the loop do the following: Print the string literal '>>" to the console Use the .nestLine() method of the scanner object and store the result in struserCommand. use the .commandParser() method of the clsCurrencyConversion object with the struserCommand as the argument. Print the result of the .getConvertedValue() method of the clsCurrencyConversion object to the console. Print the string literal " Thank you for using CS110 Currency Conversion Calculator" to the console. Close the scanner object.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started