IntroToJava_FinalProject_copy

docx

School

Western Governors University *

*We aren’t endorsed by this school

Course

0062

Subject

Computer Science

Date

Jan 9, 2024

Type

docx

Pages

10

Uploaded by DeanMoleMaster632

Report
Java Journal Template Directions: Follow the directions for each part of the journal template. Include in your response all the elements listed under the Requirements section. Prompts in the Inspiration section are not required; however, they may help you to fully think through your response. Remember to review the Touchstone page for entry requirements, examples, and grading specifics. Name: X Date: Final Replit Program Join Link: Complete the following template. Fill out all entries using complete sentences.
PART 1: Defining Your Problem Task State the problem you are planning to solve. Requirements Describe the problem you are trying to solve. Describe any input data you expect to use. Describe what the program will do to solve the problem. Describe any outputs or results the program will provide. Inspiration When writing your entry below, ask yourself the following questions: Is your problem clearly defined? Why do you want to solve this particular problem? What source(s) of data do you believe you will need? Will the user need to supply that data, or will you get it from an external file or another source? Will you need to interact with the user throughout the program? Will users continually need to enter data in and see something to continue? What are your expected results or what will be the end product? What will you need to tell a user of your program when it is complete? A currency converter is a tool that will take a value in one currency, and return the value in another currency. The problem to solve is helping the user to understand the value of another currency if they only know one. This could help in scenarios where users are traveling and need to use another form of currency other than the one they are familiar with. When executed, the program will ask the user which of the four most traded global currencies they will be inputting. Second, the program will ask the user to input the amount of the currency. The program will then use the provided currency and value, compare it to the valued conversion rate of the three other currencies, and output the respective values in the other currencies.
PART 2: Working Through Specific Examples Task Write down clear and specific steps to solve a simple version of your problem you identified in Part 1. Requirements Complete the three steps below for at least two distinct examples/scenarios. State any necessary input data for your simplified problem. Write clear and specific steps in English (not Java) detailing what the program will do to solve the problem. Describe the specific result of your example/scenario. Inspiration When writing your entry below, ask yourself the following questions: Are there any steps that you don’t fully understand? These are places to spend more time working out the details. Consider adding additional smaller steps in these spots. Remember that a computer program is very literal. Are there any steps that are unclear? Try giving the steps of your example/scenario to a friend or family member to read through and ask you questions about parts they don’t understand. Rewrite these parts as clearly as you can. Are there interesting edge cases for your program? Try to start one of your examples/scenarios with input that matches this edge case. How does it change how your program might work? Scenario 1: User begins with the ‘USD’ currency Program will prompt the user to choose a currency User will input the number ‘1’ which corresponds to the USD currency Program will prompt the user to enter the amount of the previously selected currency User will input the amount (Example: $1) Program will compare the input amount with the conversion rate for the other three currencies Program will then print the estimated amounts for each currency Example Output: 1 USD = .92 EUR 1 USD = 151.15 JPY 1 USD = .80 GBP Scenario 2: User begins with the ‘EUR’ currency Program will prompt the user to choose a currency User will input the number ‘2’ which corresponds to the EUR currency
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
  • Access to all documents
  • Unlimited textbook solutions
  • 24/7 expert homework help
Program will prompt the user to enter the amount of the previously selected currency User will input the amount (Example: €10) Program will compare the inpu t amount with the conversion rate for the other three currencies Program will then print the estimated amounts for each currency Example Output: 10 EUR = 10.85 USD 10 EUR = 1511.50 JPY 10 EUR = 8.05 GBP Scenario 3: User begins with the ‘JPY’ currency Program will prompt the user to choose a currency User will input the number ‘3’ which corresponds to the JPY currency Program will prompt the user to enter the amount of the previously selected currency User will input the amount (Example: 2000¥) Program will compare the input amount with the conversion rate for the other three currencies Program will then print the estimated amounts for each currency Example Output: 2000 JPY = 13.22 USD 2000 JPY = 12.19 EUR 2000 JPY = 10.64 GBP Scenario 4: User begins with the ‘GBP’ currency Program will prompt the user to choose a currency User will input the number ‘4’ which corresponds to the GBP currency Program will prompt the user to enter the amount of the previously selected currency User will input the amount (Example: £200) Program will compare the inputed amount with the conversion rate for the other three currencies Program will then print the estimated amounts for each currency Example Output: 200 GBP = 248.28 USD 200 GBP = 228.88 EUR 200 GBP = 37,593.98 JPY PART 3: Generalizing Into Pseudocode
Task Write out the general sequence your program will use, including all specific examples/scenarios you provided in Part 2. Requirements Write pseudocode for the program in English but refer to Java program elements where they are appropriate. The pseudocode should represent the full functionality of the program, not just a simplified version. Pseudocode is broken down enough that the details of the program are no longer in any paragraph form. One statement per line is ideal. Help With Writing Pseudocode Here are a few links that can help you write pseudocode with examples. Remember to check out part 3 of the Example Journal Template Submission if you have not already. Note: everyone will write pseudocode differently. There is no right or wrong way to write it, other than to make sure you write it clearly and in as much detail as you can so that it should be easy to convert to code later. https://www.geeksforgeeks.org/how-to-write-a-pseudo-code/ https://www.wikihow.com/Write-Pseudocode Inspiration When writing your entry below, ask yourself the following questions: Do you see common program elements and patterns in your specific examples/scenarios in Part 2, like variables, conditionals, functions, loops, and classes? These should be part of your pseudocode for the general sequence as well. Are there places where the steps for your examples/scenarios in Part 2 diverged? These may be places where errors may occur later in the project. Make note of them. When you are finished with your pseudocode, does it make sense, even to a person that does not know Java? Aim for the clearest description of the steps, as this will make it easier to convert into program code later. Function main(): Display("1 USD") Display(“2 EUR") Display("3 JPY”) Display("4 GBP”) Display("Choose the currency") Choose case from user input Display("Enter the amount") Set amt from user input Switch choice: Case 1: convertUsdToOther(amount)
break Case 2: convertEurToOther(amount) break Case 3: convertJpyToOther(amount) break Case 4: convertGbpToOther(amount) break Default: display("Invalid choice") Function convertUsdToOther(amt): Display(USD to EUR) Display(USD to JPY) Display(USD to GBP) Function convertEurToOther(amt): Display(EUR to USD) Display(EUR to JPY) Display(EURto GBP) Function convertJpyToOther(amt): Display(JPY to USD) Display(JPY to EUR) Display(JPY to GBP) Function convertGbpToOther(amt): Display(GBP to USD) Display(GBP to EUR) Display(GBP to JPY) PART 4: Testing Your Program Task While writing and testing your program code, describe your tests, record any errors, and state your approach to fixing the errors. Requirements For at least one of your test cases, describe how your choices for the test helped you understand whether the program was running correctly or not. For each error that occurs while writing and testing your code: Record the details of the error from Replit. A screenshot or copy- and-paste of the text into the journal entry is acceptable.
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
  • Access to all documents
  • Unlimited textbook solutions
  • 24/7 expert homework help
Describe what you attempted in order to fix the error. Clearly identify which approach was the one that worked. Inspiration When writing your entry below, ask yourself the following questions: Have you tested edge cases and special cases for the inputs of your program code? Often these unexpected values can cause errors in the operation of your program. Have you tested opportunities for user error? If a user is asked to provide an input, what happens when they give the wrong type of input, like a letter instead of a number, or vice versa? Did the outcome look the way you expected? Was it formatted correctly? Does your output align with the solution to the problem you coded for? The first version of my code was based off of my pseudocode. I decided to test only the USD case first to eliminate any repetitive errors that could be in the other functions. I set a breakpoint after the usdToOther function, and attempted to compile the code. This was the first error I got: For some reason it classified the quotations as special characters rather than double quotation marks. I replaced them with double quotation marks and the error was resolved. Then I got an error during the switch that stated “cannot find symbol”: When looking further into this error, I found that it was a simple syntax error with Java. Instead of naming the function “Jpy_to_other”, it should start with a lower-case letter like “jpyToOther”. So I replaced each function to begin with a lowercase letter. This portion of the code compiled and ran without any issues. I then moved onto the rest of the currencies, being careful to stay consistent with the naming conventions and getting each conversion rate correct. After compiling again, I was met with another error: This was yet another simple syntax error I overlooked. I added an additional parentheses where I should have had the semicolon “;”. After compiling one last time, the program runs as intended. I ran the code and double checked that the program was returning the correct values. PART 5: Commenting Your Program Task Submit your full program code, including thorough comments describing what each portion of the program should do when working correctly. Requirements The purpose of the program and each of its parts should be clear to
a reader that does not know the Java programming language. Inspiration When writing your entry, you are encouraged to consider the following: Is each section or sub-section of your code commented to describe what the code is doing? Give your code with comments to a friend or family member to review. Add additional comments to spots that confuse them to make it clearer. // import scanner class to get user input of int, doubles, strings, etc. import java.util.Scanner; // CurrencyConverter: a simple program used to convert currency based on user input public class CurrencyConverter { public static void main(String[] args) { // display currency options for the user System.out.println("1 USD"); System.out.println("2 EUR"); System.out.println("3 JPY"); System.out.println("4 GBP"); // take input from the user Scanner sc = new Scanner(System.in); System. out.println("Choose the currency (1, 2, 3, or 4)"); int choice = sc.nextInt(); System.out.println("Enter the amount"); double amount = sc.nextDouble(); // convert the amount to other currencies based on the user's choice switch (choice) { case 1: usdToOther(amount); break; case 2: eurToOther(amount); break; case 3: jpyToOther(amount); break; case 4: gbpToOther(amount); break; // if user enters anything other than 1,2,3,4, return invalid choice default: System.out.println("Invalid choice"); } } // *note: conversion rates were set manually on 11/15/23 and will not update on their own
// convert USD to other currencies public static void usdToOther(double amt) { System.out.println("$" + amt + " = " + "€" + (amt * 0.92)); System.out.println(); // print blank space for aesthetics System.out.println("$" + amt + " = " + (amt * 151.32) + "¥"); System.out.println(); // print blank space System.out.println("$" + amt + " = " + "£" + (amt * 0.81)); System.out.println(); } // convert EUR to other currencies public static void eurToOther(double amt) { System.out.println("€" + amt + " = " + "$" + (amt * 1.08)); System.out.println(); System.out.println("€" + amt + " = " + (amt * 164.09) + "¥"); System.out.println(); System.out.println("€" + amt + " = " + "£" + (amt * 0.87)); System.out.println(); } // convert JPY to other currencies public static void jpyToOther(double amt){ System.out.println(amt + "¥" + " = " + "$" + (amt * 0.0066)); System.out.println(); System.out.println(amt + "¥" + " = " + "€" + (amt * 0.0061)); System.out.println(); System.out.println(amt + "¥" + " = " + "£" + (amt * 0.0053)); System.out.println(); } // convert GBP to other currencies public static void gbpToOther(double amt){ System.out.println("£" + amt + " = " + "$" + (amt * 1.24)); System.out.println(); System.out.println("£" + amt + " = " + "€" + (amt * 1.14)); System.out.println(); System.out.println("£" + amt + " = " + (amt * 187.81) + "¥"); System.out.println(); } }
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
  • Access to all documents
  • Unlimited textbook solutions
  • 24/7 expert homework help
PART 6: Your Completed Program Task Provide the Replit link to your full program code. Requirements The program must work correctly with all the comments included in the program. Inspiration Check before submitting your Touchstone that your final version of the program is running successfully.