jdog2u 0 Newbie Poster

Hello World. Thanks for any help in advance. I am in a basic java class. One of our first assignments is to develop this currency calculator. I have completed the code and it works fine. My only concern is that i could loose points if I have too much code in the main method. He wants us to;

"....minimize the code in the "Main" method and put as much as possible into methods which are called from Main"

Have I satisfied this request? Any suggestions? Thank You

package foreigncurrency2;

import java.math.*;
import java.text.NumberFormat;
import java.util.Scanner;

/*****************************************
 * This class Calculator that calculates the current United States value of 5
 * currency types.
 * @version
 *
 *
 * @author James Evans
 *****************************************/
public class ForeignCurrency2 {

    static double rGBP, rCAD, rEUR, rYEN, rRUB, Total;
    static Scanner sc = new Scanner(System.in);

    public static void main(String[] args) {


        int userChoice;
        String currency = null;

        System.out.println("Welcome To The Currency Calculator!\n");

        System.out.println("Please Enter The Currency Rate Per US $ For The Following currencies. Press enter after each entry\n");
        getCurrencyRates(); //Method that will ask for exchange rates

        // doValuation();//Do loop that will ask user for choice, opt 9 or quit

        System.out.print("Please select currency for valuation (1=CAD, 2=GBP, 3=EUR, 4=YEN, 5=RUB, 9=New Rates, 0=Quit): \n");
        userChoice = sc.nextInt();

        while (userChoice != 0) {
            switch (userChoice) {
                case 1:
                    currency = ""
                            + "Canadian Dollars";
                    doValuation(rCAD, currency);
                    break;
                case 2:
                    currency = "Pounds Sterling";
                    doValuation(rGBP, currency);
                    break;
                case 3:
                    currency = "Euros";
                    doValuation(rEUR, currency);
                    break;
                case 4:
                    currency = "Yen";
                    doValuation(rYEN, currency);
                    break;
                case 5:
                    currency = "Russian Rubles";
                    doValuation(rRUB, currency);
                    break;
                case 9:
                    getCurrencyRates();
                    break;

            }

            System.out.print("Currency (1=CAD, 2=GBP, 3=EUR, 4=JPY, 5=RUB, 9=New Rates, 0=Quit): ");
            userChoice = sc.nextInt();


        }

        System.out.println("Thanks For Using The Currency Calculator!");
        BigDecimal newTotal = new BigDecimal(Double.toString(Total));
        newTotal = newTotal.setScale(2, RoundingMode.UNNECESSARY);
        NumberFormat g = NumberFormat.getCurrencyInstance();
        System.out.println("The Total Value Of The Proposed Currency Purchases Is: " + g.format(Total) + " USD");
        Total = 0;
    }

    private static void getCurrencyRates() {

        System.out.print("Enter Canadian Dollars (CAD): ");
        rCAD = sc.nextDouble();
        System.out.print("Enter British Pounds (GBP): ");
        rGBP = sc.nextDouble();
        System.out.print("Enter European Dollars (EUR): ");
        rEUR = sc.nextDouble();
        System.out.print("Enter Japanese Yen (YEN): ");
        rYEN = sc.nextDouble();
        System.out.print("Enter Russian Rubles (RUB): ");
        rRUB = sc.nextDouble();
    }

    private static void doValuation(double rate, String currency) {

        System.out.print("How many " + currency + " are you buying? ");
        int units = sc.nextInt();

        double value = rate * units;
        Total += value;
        BigDecimal newValue = new BigDecimal(Double.toString(value));
        newValue = newValue.setScale(2, RoundingMode.HALF_UP);
        NumberFormat f = NumberFormat.getCurrencyInstance();
        System.out.println("That will have a current value of " + f.format(value) + " USD.");

    }
}