Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

how am i supposed to show a diferent currency in my program...im not too sure of

ID: 3654104 • Letter: H

Question

how am i supposed to show a diferent currency in my program...im not too sure of how to do it so here's my program and help pls. import java.util.Scanner; /** This program prints the price per ounce for a six-pack of cans. */ public class R5_7 { public static void main(String[] args) { // Read price per pack Scanner in = new Scanner(System.in); System.out.print("Please enter the price for a six-pack: "); double packPrice = in.nextDouble(); // Read can volume System.out.print("Please enter the volume for each can (in ounces): "); double canVolume = in.nextDouble(); //ask for the currency System.out.print("Please enter the currency used: "); double currency = in.nextDouble(); // Compute pack volume final double CANS_PER_PACK = 6; double packVolume = canVolume * CANS_PER_PACK; //call method to print out the price per ounce double cost = 1; cost = costPerOunce (packPrice, packVolume, currency); } public static double costPerOunce (double packPrice, double packVolume, double currency) { // Compute and print price per ounce double pricePerOunce = packPrice / packVolume; System.out.printf("Price per ounce:" + currency+ " %8.2f", pricePerOunce); System.out.println(); return pricePerOunce; } }

Explanation / Answer

package oct29; import java.io.InputStreamReader; import java.io.Reader; import java.net.URL; import java.util.Scanner; /** This program prints the price per ounce for a six-pack of cans. */ public class R5_7 { public static void main(String[] args) { // Read price per pack Scanner in = new Scanner(System.in); System.out.println("Enter the cuurency being used: "); String currencyFrom = in.next(); //Enter Strings like USD(United stated dollar) or GBP(Great britan pounds) //Refer to google Currency Calculator for Strings. System.out.print("Please enter the price for a six-pack: "); double packPrice = in.nextDouble(); // Read can volume System.out.print("Please enter the volume for each can (in ounces): "); double canVolume = in.nextDouble(); // Compute pack volume final double CANS_PER_PACK = 6; double packVolume = canVolume * CANS_PER_PACK; //call method to print out the price per ounce double costPerOunce = packPrice/packVolume; String currencyTo = ""; try { //ask for the currency System.out.print("Please enter the currency to be converted: "); currencyTo = in.next(); convert(currencyFrom,currencyTo,costPerOunce); } catch(Exception e) { System.err.println(currencyFrom + " Cannot be converted to " + currencyTo); } } public static void convert(String currencyFrom, String currencyTo, double cost) throws Exception { String google = "http://www.google.com/ig/calculator?hl=en&q="; URL url = new URL(google + cost + currencyFrom.toUpperCase() + "=?" + currencyTo.toUpperCase()); Scanner input = new Scanner(new InputStreamReader(url.openStream())); String result = input.nextLine(); String tokens = result.split("rhs: "")[1]; double amount = Double.parseDouble(tokens.split(" ")[0]); System.out.printf("Cost per Ounce : %,.2f %s",amount, currencyTo); } }