rendered paste bodyimport java.util.*;
public class Wk06Exercise3
{
public static void main(String[] args)
{
double[] pricesInPounds = new double[5];
double exchangeRate = 0;
double[] pricesInDollars = new double[5];
pricesInPounds = enterPrice(pricesInPounds);
exchangeRate = enterExchangeRate(exchangeRate);
pricesInDollars = convertMethod(pricesInPounds, exchangeRate, pricesInDollars);
displayInPrices(pricesInPounds, pricesInDollars);
}
// Enter price of 5 Products
private static double[] enterPrice(double[] pricesInPoundsIn)
{
Scanner sc = new Scanner(System.in);
for (int i=0; i < pricesInPoundsIn.length; i++)
{
System.out.print("Please enter price: ");
pricesInPoundsIn[i] = sc.nextDouble();
}
System.out.println();
return pricesInPoundsIn;
}
// Enter exchange rate
private static double enterExchangeRate(double exchangeRateIn)
{
Scanner sc = new Scanner(System.in);
System.out.print("Please enter exchange rate: ");
exchangeRateIn = sc.nextDouble();
System.out.println();
return exchangeRateIn;
}
// Converts Pounds to US Dollars
private static double[] convertMethod(double[] pricesInPoundsIn, double exchangeRateIn, double[] pricesInDollarsIn)
{
for (int i=0; i < pricesInPoundsIn.length; i++)
{
pricesInDollarsIn[i] = pricesInPoundsIn[i] * exchangeRateIn;
}
return pricesInDollarsIn;
}
// Displays prices in Pounds and US Dollars
private static void displayInPrices(double[] pricesInPoundsIn, double[] pricesInDollarsIn)
{
for (int i=0; i<pricesInPoundsIn.length; i++)
{
System.out.println("Prices in Pounds were: " + pricesInPoundsIn[i]);
}
System.out.println();
for (int i=0; i<pricesInDollarsIn.length; i++)
{
System.out.println("Prices in US Dollars are: " + pricesInDollarsIn[i]);
}
}
}