Results 1 to 5 of 5
  1. #1
    JDAWG is offline Member
    Join Date
    Feb 2009
    Posts
    22
    Rep Power
    0

    Default [SOLVED] Cant figure out why its erroring

    Below I have to sets of code. My first code called Lab6 should use the second set of code called Foreign. When I compile Lab6 it errors out and I cant figure out why. Please help

    Java Code:
    import java.util.Scanner;
    import java.text.NumberFormat;
    
    public class Lab6
    {
    	public static void main(String[] args)
    	{
    		String more = "Y";
    	   Foreign exchange = new Foreign();
    			
    	
    	do
    		{	
    		exchange.menu();	
    		exchange.choice();
    		exchange.dollars();
    		exchange.vertical();
    		System.out.println("\n" + exchange);
    				
    		System.out.print("\nWould you like to enter another exchange? Y/N ");
    		more = Keyboard.nextLine();
    		}
    	while (Character.toUpperCase(more.charAt(0)) == 'Y'); 
    	
    	
    	}
    }
    Java Code:
    import java.util.Scanner;
    import java.text.NumberFormat;
    
     public class Foreign
    {
    	private int choice;
    	private String country;
    	private double dollars, rate, amount;
    	Scanner Keyboard = new Scanner(System.in);
       NumberFormat dollarFormat = NumberFormat.getCurrencyInstance();
    
    	public Foreign()
    	{
    				dollars = 0.0;
    				rate = 0.0;
    				amount = 0.0;
    				country = "null";
    	}
     		
    	public void menu()
    	{
    		System.out.println("======================================================");
    		System.out.println("                  Foreign Exchange Menu");
    		System.out.println("======================================================\n\n");
    		System.out.println("1. U.S. to Canada");
    		System.out.println("2. U.S. to Mexico");
    		System.out.println("3. U.S. to Japan");
    		System.out.println("4. U.S. to Euro");
    		System.out.println("0. Quit\n");
    		System.out.print("\nPlease enter your choice:");
    
     	}
    	
    	public void choice()
    	{
    	choice = Keyboard.nextInt();
    	}
    		
    	public int getchoice()
    	{
    		return choice;
    	}
    
    	public void dollars()
    	{
    		System.out.print("\nEnter the amount of U.S. Dollars you want to convert: ");
    	 	dollars = Keyboard.nextDouble();
    	 	
    		if (choice >= 1 && choice < 5)
    	 
    		switch (choice)
    		{
    	 		case 1: 
    				rate = 1.2418;
    				country = "Canadian Dollars";
    			break;
    		
    	 		case 2:
    	 			rate = 14.5436;
    				country = "Mexican Pesos";
    			break;
    		
    	 		case 3:
    	 			rate = 88.9183;
    				country = "Japanese Yen";
    			break;
    		
    			 case 4:
    	 			rate =  0.774078;
    				country = "Euros";
    			break;
    			
    			default:
    				System.out.println("======================================================");
    				System.out.println("       Please select 1 through 4 or 0 to quit: ");
    				System.out.println("======================================================\n\n\n");
    
    
    		}
    			amount = dollars * rate;
    	 }		
    	 	
    	public void vertical()
    	{
    	System.out.println("\nCountry = " + country);
    	System.out.println("Rate = " + rate);
    	System.out.println("Dollars = " + dollarFormat.format(dollars));
    	System.out.println("Value = " + amount);
    	}
    	
    	public String toString()
    	{
    		String line;
    		line = country + " " + rate + " " + dollars + " " + amount;
    		return line;
    	}
    }
    Last edited by JDAWG; 03-09-2009 at 02:06 AM.

  2. #2
    JDAWG is offline Member
    Join Date
    Feb 2009
    Posts
    22
    Rep Power
    0

    Default

    I figured it out thanks

  3. #3
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,371
    Blog Entries
    1
    Rep Power
    20

    Default

    When you comes with an error please send that error message to see for others as well. So they can comment on your code so easily. Running your code and see not make sense always.

    And also you have working on the same code here, post in another thread. Much better to stick with the same thread unless they are different.

    Anyway, you have solved the problem yourself. Really nice. So this is time to mark the thread solved.

  4. #4
    JDAWG is offline Member
    Join Date
    Feb 2009
    Posts
    22
    Rep Power
    0

    Default

    how do u post it solved

  5. #5
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,371
    Blog Entries
    1
    Rep Power
    20

Similar Threads

  1. I couldn’t figure out how to do this please help!
    By afrttoh in forum New To Java
    Replies: 5
    Last Post: 11-19-2008, 09:21 PM
  2. Replies: 2
    Last Post: 11-08-2008, 05:58 AM
  3. Replies: 2
    Last Post: 07-11-2008, 10:41 AM
  4. Seems so simple yet I can't figure it out!
    By adamhaviland in forum New To Java
    Replies: 1
    Last Post: 11-03-2007, 07:26 PM
  5. I can't figure this out
    By silvia in forum New To Java
    Replies: 3
    Last Post: 07-20-2007, 05:38 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •