Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- import cs1.Keyboard;
- public class foreign
- {
- private static int choice;
- private static int count;
- private String country;
- private double dollars, cvalue, camount;
- public foreign() //set everything to null
- {
- choice = 0;
- country = "";
- dollars = 0;
- cvalue = 0;
- camount = 0;
- count = 0;
- }
- public static void title()
- {
- System.out.println("Foreign Exchange\n");
- }
- public static void menu()
- {
- System.out.println("\nChoose your currency:\n");
- System.out.println("1. US to Canada");
- System.out.println("2. US to Mexico");
- System.out.println("3. US to Japan");
- System.out.println("4. US to Euro");
- System.out.println("0. Quit\n");
- }
- public static int choice()
- {
- Scanner read = new Scanner(System.in);
- System.out.print("\nEnter your choice: ");
- choice = read.nextInt(); //input choice
- return choice;
- }
- public void amount()
- {
- switch (choice) //use the choice to define the values
- {
- case 1: country = "Canada";
- cvalue = 1.0267;
- break;
- case 2: country = "Mexico";
- cvalue = 12.5484;
- break;
- case 3: country = "Japan";
- cvalue = 123.78;
- break;
- default: country = "Euro";
- cvalue = 0.7424;
- }
- Scanner read = new Scanner(System.in);
- System.out.print("Enter Dollar amount: ");
- dollars = read.nextDouble();
- }
- public void calculate () //calculate the conversion
- {
- camount = dollars * cvalue;
- count++;
- }
- public void vertical () //create vertical output
- {
- System.out.println("Country = " + country);
- System.out.println("Rate = " + cvalue);
- System.out.println("Dollars = " + dollars);
- System.out.println("Value = " + camount);
- }
- public String toString()
- {
- String s; //create horizontal output
- s = country + " " + cvalue + " " + dollars + " " + camount + " ";
- return s;
- }
- public static int count()
- {
- return count;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement