Results 1 to 4 of 4

Thread: Hotfix

  1. #1
    zawmbee is offline Member
    Join Date
    Oct 2013
    Posts
    3
    Rep Power
    0

    Default Hotfix

    I've not got a clue what's wrong here, any help at all would be greatly appreciated.
    Java Code:
    import java.util.Scanner;
    import java.util.InputMismatchException;
    
    public class p1 {
        public static void main (String[] args) {
    		Scanner input = new Scanner(System.in);
    		double amt;
    		double ins = amt * rate;
    		System.out.println("Please enter amount invested.");
    		try {
    			amt = input.nextDouble();
    			if (amt < 2500 && amt > 0) {
    				double rate = .08;
    			} else if (amt >= 2500) {
    				double rate = .1;
    			} else if (amt < 0) {
    				System.err.println("You cannot invest a negative amount!");
    			}
    		} catch (InputMismatchException ex) {
    			System.err.println("Please input a number.");
    		}
    		System.out.println("The interest on $"+amt+"at a rate of $"+rate+"is $"+ins+".");
    		input.close();
    	}
    }
    I constantly get the following error:
    Java Code:
    $javac p1.java 2>&1
    p1.java:8: error: cannot find symbol
    double ins = amt * rate;
    ^
    symbol: variable rate
    location: class p1
    p1.java:22: error: cannot find symbol
    System.out.println("The interest on $"+amt+"at a rate of $"+rate+"is $"+ins+".");
    ^
    symbol: variable rate
    location: class p1
    2 errors
    Currently I am using an online compiler (link) because I do not have access to a computer that supports java. Not sure if that might be related, but just in case, y'know? :P

  2. #2
    zawmbee is offline Member
    Join Date
    Oct 2013
    Posts
    3
    Rep Power
    0

    Default Re: Hotfix

    Sorry for the bother if anyone was about to reply. I fixed it.
    Java Code:
    import java.util.Scanner;
    import java.util.InputMismatchException;
    
    public class p1 {
    	public static void main (String[] args) {
    		Scanner input = new Scanner(System.in);
    		double amt;
    		System.out.println("Please enter amount invested.");
    		amt = input.nextDouble();
    		try {
    			if (amt < 2500 && amt > 0) {
    				double ins = amt * .08;
    				String rate = "8%";
    				System.out.println("The interest on $"+amt+" at a rate of "+rate+" is $"+ins+".");
    			} else if (amt >= 2500) {
    				double ins = amt * .10;
    				String rate = "10%";
    				System.out.println("The interest on $"+amt+" at a rate of "+rate+" is $"+ins+".");
    			} else if (amt < 0) {
    				System.err.println("You cannot invest a negative amount!");
    			}
    		} catch (InputMismatchException ex) {
    			System.err.println("Please input a number.");
    		}
    		input.close();
    	}
    }

  3. #3
    zawmbee is offline Member
    Join Date
    Oct 2013
    Posts
    3
    Rep Power
    0

    Default Re: Hotfix

    Well, the InputMismatchException isn't showing my error println...just the actual lengthy error. If anyone's got any pointers for that, that would be helpful.

  4. #4
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,225
    Rep Power
    20

    Default Re: Hotfix

    That lengthy error will show you exactly which line in your code it is being thrown from.
    Which might well be line 9, which is not covered by your try/catch block.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

Posting Permissions

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