Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8751785
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T13:06:49+00:00 2026-06-13T13:06:49+00:00

I’m trying to put a try-catch into a procedure type method but I’m 95%

  • 0

I’m trying to put a try-catch into a procedure type method but I’m 95% sure it has to be a function type. What I’m trying to accomplish is to make my code shorter in the main. One of the biggest things I thought of was to put a try-catch into a method and call the method.

The thing is, it will validate the input if it is a integer or not- it even catches the exceptions the problem is that it doesn’t “remember” the validated input once it continues on with the program/calculates. Here’s the part of the code I’m having trouble with.

 public static void tryCatchNum(double value)
 {
    while(true)
    {
    try
    {
        Scanner iConsole = new Scanner(System.in);
        value = Double.parseDouble(iConsole.nextLine());
            System.out.println(" ");
        break;
    }
    catch(NumberFormatException e)
    {
        System.out.println("NumberFormatException error has oocured. Please try again.");
    }
}

}

And here is the entire program:

    import java.util.Scanner;

    public class ch7exercise1
{
public static double compound(double oA, double cI)
{
    return roundCent((oA*(Math.pow((1+(percent(cI))),10))));
}

public static double percent(double interest)
{
    return interest/100.0;
}

public static double roundCent(double amount)
{
    return ((Math.round(amount*100))/100.0); //100.0 is mandatory.
}

public static void tryCatchNum(double value)
{
    while(true)
    {
        try
        {
            Scanner iConsole = new Scanner(System.in);
            value = Double.parseDouble(iConsole.nextLine());
            System.out.println(" ");
            break;
        }
        catch(NumberFormatException e)
        {
            System.out.println("NumberFormatException error has oocured. Please try again.");
        }
    }
}

@SuppressWarnings("unused")
public static void main(String[] args)
{
    boolean f = true;
    boolean f2 = true;
    double origAmount = 0;
    double compInterest = 0;
    double total = 0;

    Scanner iConsole = new Scanner(System.in);

    System.out.println("10 year Compound Interest Claculator\n");

    System.out.println("Input amount of money deposited in the bank");

    tryCatchNum(origAmount);

    System.out.println("Input compouded interest rate. (If the compound interest is 3% input 3)");

    tryCatchNum(compInterest);

    total = compound(origAmount,compInterest);

    System.out.println("$"+total);


}

}

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T13:06:50+00:00Added an answer on June 13, 2026 at 1:06 pm

    Java arguments are passed by value. You’re passing 0 to the tryCatchNum method. A copy of the value is passed to the method. This method assigns a new value to its own copy, and then returns. So the original value is still 0.

    You must not pass anything to the method. Instead, the method must return the value it has validated. Also, consider using a more appropriate method name:

    public double readDoubleValue() {
        ...
        return value;
    }
    

    And in the main method:

    double origAmount = readDoubleValue(); 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Basically, what I'm trying to create is a page of div tags, each has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I want to count how many characters a certain string has in PHP, but
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I have a French site that I want to parse, but am running into
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I want to construct a data frame in an Rcpp function, but when I
I am trying to loop through a bunch of documents I have to put
I am trying to understand how to use SyndicationItem to display feed which is
That's pretty much it. I'm using Nokogiri to scrape a web page what has

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.