Here is what I have made so far. Applications http://pastebin.com/embed_js.php?i
ID: 3540466 • Letter: H
Question
Here is what I have made so far.
Applications http://pastebin.com/embed_js.php?i=n6mGg9fR
Currency main http://pastebin.com/embed_js.php?i=CrtW1gX8
Currency class http://pastebin.com/embed_js.php?i=funTT18T
Fractions main http://pastebin.com/embed_js.php?i=4P1a8QKj
Fractions class http://pastebin.com/embed_js.php?i=0qMBD4C8
Temperature http://pastebin.com/embed_js.php?i=7aqNarBf
What I want to do is combine all of these together. So that they are communicating with each other. I havent been able to hit the head on the nail just yet. Also in the applications file I want the user to put in a number so that it will go to that designated program (would I use switch statements??) Im finishing this up for my final project. I have a majority of the work done, I just need to peice them togerher. Please and thank you for the help.
Explanation / Answer
// keep FractionsToDecimals.java and CurrencyExchange.java as is
/// change remaining programs as follows.
//This program has applications that the user may use to interact.
import java.util.Scanner;
public class Applications
{
public static void main(String[] args)
{
Scanner in = new Scanner(System.in);
System.out.println("Enter the number for your choice of command");
System.out.println("Enter the number one for simplifying fractions");
System.out.println("Enter the number two for temperature conversions");
System.out.println("Enter the number three for currency converter ");
int choice = in.nextInt();
switch(choice)
{
case 1:
{
FractionsToDecimalsTest.simplify_fration();
}
break;
case 2:
{
Temperature.temp_converter();
}
break;
case 3:
{
CurrencyConversionMain.currency_converter();
}
break;
default: // some thing gone wrong here stop.
System.exit(0);
}
}
}
// CurrencyConversionMain.java should be as follows.
import java.util.Scanner;
public class CurrencyConversionMain
{
public static void currency_converter()
{
Scanner scan = new Scanner(System.in);
System.out.print("Enter a dollar amount (do not include $): ");
double dollars = scan.nextDouble();
System.out.println("Enter the currency to convert to [1] Chinese Yuan [2] Euro [3] Pound [4] Taka [5] Yen");
System.out.println("[6] Rupees [7] Pesos [8] Dong [9] Real [10] Ruble");
int command = scan.nextInt();
CurrencyExchange currencyExchange = new CurrencyExchange(dollars);
switch (command)
{
case 1: currencyExchange.setRenminbi(dollars);
System.out.println(currencyExchange.getRenminbi() + " Renminbi");
break;
case 2: // modified here to get the exact results as you need.
currencyExchange.setEuro(dollars); // this will convert the entered dollar into euros
System.out.println(currencyExchange.getEuro() + " Euro");// this will display the result
break;
case 3: currencyExchange.setPound(dollars);
System.out.println(currencyExchange.getPound() + " Pound");
break;
case 4: currencyExchange.setTaka(dollars);
System.out.println(currencyExchange.getTaka() + " Taka");
break;
case 5: currencyExchange.setYen(dollars);
System.out.println(currencyExchange.getYen() + " Yen");
break;
case 6:currencyExchange.setRupees(dollars);
System.out.println(currencyExchange.getRupees() + " Rupees");
break;
case 7:currencyExchange.setPesos(dollars);
System.out.println(currencyExchange.getPesos() + " Pesos");
break;
case 8:currencyExchange.setDong(dollars);
System.out.println(currencyExchange.getDong() + " Dong");
break;
case 9:currencyExchange.setReal(dollars);
System.out.println(currencyExchange.getReal() + " Real");
break;
case 10:currencyExchange.setRuble(dollars);
System.out.println(currencyExchange.getRuble() + " Ruble");
break;
default: System.out.println("Try again");
}
}
}
//FractionsToDecimalsTest.java should be as follows.
import java.util.Scanner;
public class FractionsToDecimalsTest {
public static void simplify_fration()
{
int Numerator, Denominator;
Scanner input = new Scanner (System.in);
System.out.println("Please enter two numbers for numerator and denominator");
System.out.println("Denominator can not equal zero!");
Numerator = input.nextInt();
Denominator = input.nextInt();
FractionsToDecimals fd = new FractionsToDecimals(Numerator, Denominator);
System.out.println("The fraction as a double value: " + fd.getValue());
System.out.println("The simplified fraction in the form a/b: " + fd.toString());
}
}
//Temperatur.java should be as follows.
import java.util.Scanner;
public class Temperature
{
public static void temp_converter(){
System.out.println("Enter the temperature");
Scanner scanner = new Scanner (System.in);
int num = Integer.parseInt(scanner.next());
System.out.println("Enter C (for celsius to fahrenheit) or F (for fahrenheit to celsius): ");
String temp = scanner.next();
if (temp.equals ("C") || temp.equals("c"))//celsius to fahrenheit conversion
{
double degreeF = (9* (num) / 5) + 32;//calculating fahrenheit
System.out.println("The Fahrenheit temperature is: " + degreeF + "F");
}
else if (temp.equals("F") || temp.equals("f"))//Fahrenheit to celsius conversion
{
double degreeC = 5 * (num - 32) / 9;//calculating celsius
System.out.println("The celsius temperature is:" + degreeC + "C");
}
else
System.out.println("An error has occured");
System.exit(0); //stops system
}
}