Question

In: Computer Science

i need a pseudocode for a program in java that will convert dollars into euros and...

i need a pseudocode for a program in java that will convert dollars into euros and japanese yen
using the print and prinln methods
an if, if -else, statement
a switch statement
a while statement
utilizes the file class
uses the random class and random number generator
and uses at least three methods other than main

Solutions

Expert Solution

import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.Random;
import java.util.Scanner;

/**
* This program converts Dollars to Euros and Japanese Yen
* Firstly, it generates 10 random Dollar amounts between 10 and 500, and writes them to a .txt file
* Then, it reads from the .txt file and converts the amounts to their respective Euro and Yen values
* @author USER
*/
public class CurrencyConverter {
  
public static void main(String[] args)
{
Scanner sc = new Scanner(System.in);
System.out.print("Enter the input filename: ");
String fileName = sc.nextLine().trim();
  
// generate 10 dollar amounts and write them to the file
generateDollarAmounts(fileName, 10);
  
System.out.println();
  
// read the dollars from file, line-by-line and display the euro and yen values
readAndConvert(fileName);
}
  
private static void generateDollarAmounts(String fileName, int n)
{
System.out.println("Generating " + n + " random dollar amounts and writing them to " + fileName + "..");
FileWriter fw;
PrintWriter pw;
try {
fw = new FileWriter(new File(fileName));
pw = new PrintWriter(fw);
  
// generate 10 random values and write them to the file
for(int i = 0; i < n; i++)
{
if(i == n - 1)
pw.write(generateRandomValues() + "");
else
pw.write(generateRandomValues() + System.lineSeparator());
}
  
pw.flush();
fw.close();
pw.close();
  
System.out.println(n + " random dollar values generated and written successfully!");
} catch (IOException ex) {
System.out.println("Error while writing dollars to file: " + fileName);
System.exit(-1);
}
}
  
private static void readAndConvert(String fileName)
{
System.out.println("Reading the dollar amounts from " + fileName + "..");
Scanner fileReader;
try
{
fileReader = new Scanner(new File(fileName));
while(fileReader.hasNextLine())
{
double dollarRead = Double.parseDouble(fileReader.nextLine().trim());
System.out.println("$" + String.format("%.2f", dollarRead) + " = "
+ String.format("%.2f", dollarToEuro(dollarRead)) + " Euro.");
System.out.println("$" + String.format("%.2f", dollarRead) + " = "
+ String.format("%.2f", dollarToYen(dollarRead)) + " Japanese Yen.\n");
}
fileReader.close();
System.out.println("Exiting...");
}catch(FileNotFoundException fnfe){
System.out.println(fileName + " could not be found!");
System.exit(-1);
}
}
  
private static double generateRandomValues()
{
Random rand = new Random();
return(10 + (500 - 10) * rand.nextDouble());
}
  
private static double dollarToEuro(double dollar)
{
return(dollar * 0.91);
}
  
private static double dollarToYen(double dollar)
{
return(dollar * 108.64);
}
}

***************************************************************** SCREENSHOT **********************************************************


Related Solutions

JAVA JAVA JAVA . I need to convert a string input to int array, for example...
JAVA JAVA JAVA . I need to convert a string input to int array, for example if user enters 12 / 27 / 2020 , I want to store each value in a separate array and add them afterwards.
I need assistance on this problem in Pseudocode and in C++ Program Program 3: Give a...
I need assistance on this problem in Pseudocode and in C++ Program Program 3: Give a baby $5,000! Did you know that, over the last century, the stock market has returned an average of 10%? You may not care, but you’d better pay attention to this one. If you were to give a newborn baby $5000, put that money in the stock market and NOT add any additional money per year, that money would grow to over $2.9 million by...
I need assistance on this problem in Pseudocode and in C++ Program 1: Stay on the...
I need assistance on this problem in Pseudocode and in C++ Program 1: Stay on the Screen! Animation in video games is just like animation in movies – it’s drawn image by image (called “frames”). Before the game can draw a frame, it needs to update the position of the objects based on their velocities (among other things). To do that is relatively simple: add the velocity to the position of the object each frame. For this program, imagine we...
Hello, I need some assistance on completing this program in Pseudocode and in C++ Program 2:...
Hello, I need some assistance on completing this program in Pseudocode and in C++ Program 2: Buh-RING IT! For this assignment, you’re going to simulate a text-based Role-Playing Game (RPG). Design (pseudocode) and implement (source) for a program that reads in 1) the hero’s Hit Points (HP – or health), 2) the maximum damage the hero does per attack, 3) the monster’s HP and 4) the maximum monster’s damage per attack. When the player attacks, it will pick a random...
I need an idea of Java code that will convert an integer (1 to 3,999) into...
I need an idea of Java code that will convert an integer (1 to 3,999) into roman numerals using if statements; arrays and loops sadly aren't allowed and that's all I can come up with.
Hello, I need to convert this java array into an array list as I am having...
Hello, I need to convert this java array into an array list as I am having trouble please. import java.util.Random; import java.util.Scanner; public class TestCode { public static void main(String[] args) { String choice = "Yes"; Random random = new Random(); Scanner scanner = new Scanner(System.in); int[] data = new int[1000]; int count = 0; while (!choice.equals("No")) { int randomInt = 2 * (random.nextInt(5) + 1); System.out.println(randomInt); data[count++] = randomInt; System.out.print("Want another random number (Yes / No)? "); choice =...
I need a pseudocode and UML for this program. import java.util.Random; public class SortandSwapCount {   ...
I need a pseudocode and UML for this program. import java.util.Random; public class SortandSwapCount {    public static void main(String[] args) {        //Generate random array for test and copy that into 3 arrays        int[] arr1=new int[20];        int[] arr2=new int[20];        int[] arr3=new int[20];        int[] arr4=new int[20];        Random rand = new Random();        for (int i = 0; i < arr1.length; i++) {            //Generate random array...
i need the pseudocode and python program for the following problem. Besides the user entering the...
i need the pseudocode and python program for the following problem. Besides the user entering the number of books purchased this order, they are asked for the number of points earned for the year before this order and the number of books ordered this year before this order. There are bonus points awarded based on the number of books previously ordered and number ordered now. These points should be added to the variable points: Current order: 0 Previous Orders >...
Make a java program of Mickey I have the starter program but I need to add...
Make a java program of Mickey I have the starter program but I need to add eyes and a smile to it. import java.awt.Canvas; import java.awt.Color; import java.awt.Graphics; import java.awt.Rectangle; import javax.swing.JFrame; public class Mickey extends Canvas { public static void main(String[] args) { JFrame frame = new JFrame("Mickey Mouse"); Canvas canvas = new Mickey(); canvas.setSize(400, 400); canvas.setBackground(Color.white); frame.add(canvas); frame.pack(); frame.setVisible(true); } public void paint(Graphics g) { Rectangle bb = new Rectangle(100, 100, 200, 200); mickey(g, bb); } public void...
Using java, I need to make a program that reverses a file. The program will read...
Using java, I need to make a program that reverses a file. The program will read the text file character by character, push the characters into a stack, then pop the characters into a new text file (with each character in revers order) EX: Hello World                       eyB       Bye            becomes    dlroW olleH I have the Stack and the Linked List part of this taken care of, I'm just having trouble connecting the stack and the text file together and...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT