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 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.
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...
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...
I need it in java. Write a program that will print if n numbers that the...
I need it in java. Write a program that will print if n numbers that the user will input are or not within a range of numbers. For that, your program needs to ask first for an integer number called N that will represent the number of times that will ask for other integer numbers. Right after, it should ask for two numbers that will represent the Min and Max for a range. Lastly. it will iterate N number times...
I need to make JAVA program that calculates the area of a brick of a specific...
I need to make JAVA program that calculates the area of a brick of a specific color. I have class Brick with the following UML: String color int number int length int width I made methods: getColor(), getNumber(), getLength(), getWidth() in the class Brick So it starts like this: ##### public Brick(String color, int number, int length, int width) { this.color = color; this.number = number; this.length = length; this.width = width;    }   public String toString() {   return number...
I only need to update this JAVA program to be able to : 1 ) Exit...
I only need to update this JAVA program to be able to : 1 ) Exit cleanly after creating the chart 2 ) change the pie chart to a perfect circle rather than an oval 3 ) provide a separate class driver import java.awt.Color; import java.awt.Graphics; import java.awt.Graphics2D; import java.awt.Rectangle; import java.util.Scanner; import javax.swing.JComponent; import javax.swing.JFrame; // class to store the value and color mapping of the // pie segment(slices) class Segment { double value; Color color; // constructor public...
Write a java program that will ask for a Star Date and then convert it into...
Write a java program that will ask for a Star Date and then convert it into the corresponding Calendar date. without using array and methods.
PYTHON ONLY NO JAVA! PLEASE INCLUDE PSEUDOCODE AS WELL! Program 4: Design (pseudocode) and implement (source...
PYTHON ONLY NO JAVA! PLEASE INCLUDE PSEUDOCODE AS WELL! Program 4: Design (pseudocode) and implement (source code) a program (name it LargestOccurenceCount) that read from the user positive non-zero integer values, finds the largest value, and counts it occurrences. Assume that the input ends with number 0 (as sentinel value to stop the loop). The program should ignore any negative input and should continue to read user inputs until 0 is entered. The program should display the largest value and...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT