Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 2 of 2

Thread: Boolean help

  1. #1
    Member
    Join Date
    Feb 2013
    Posts
    30
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Boolean help

    Hey, I'm stuck on my current code, interest calculator, to solve for simple, monthly compounded, and daily compounded interest.
    If one error occurs I need it to state the error, if two errors occur I need it to state them both, and so on..
    Right now if I have an error on any of them my last error is the one that pops up.. Any help would be great!!
    import java.util.Scanner;
    public class InterestCalculator2{
    	public static void main(String[] args )
    	{
    		Scanner input = new Scanner(System.in);
     
    		//Prompt user to enter loan amount
    		System.out.print("Enter Loan Amount: ");
    	    int principle = input.nextInt();
     
    	    //Prompt user to enter interest rate
    		System.out.print("Enter Yearly Interest Rate (1 to 100 percent): ");
    	    double interest = input.nextDouble(); 
     
    	    //Prompt user to enter term 
    	    System.out.print("Enter the Term (in months): ");
    	    int term = input.nextInt(); 
     
     
     
    	    double simple= principle*(interest/100.0)*(term/12.0);
    	    double repaidSimple= simple+principle;
    	    double a = 1.0+((interest/100)/365.0);
    	    double b = (365*(term/12.0));
    	    double daily = Math.pow(a,b);
    	    double dailyCompound = (principle*daily)-principle; 		
    	    double repaidDaily = dailyCompound + principle; 
    	    double c = 1.0+((interest/100)/12.0);
    	    double d = (12*(term/12.0));
    	    double monthly = Math.pow(c, d);
    	    double monthlyCompound = (principle*monthly)-principle;
    	    double repaidMonthly = monthlyCompound + principle;
    	    int type = 0;
     
    	    if (principle > 0) 
    	   {
    	    			if (interest > 0 && interest < 100) 
    	    	{
    	    		if(term > 0)
    	    		{
    	    				switch(type)
    	    		{
    	    		case 1:
    	    			break;
     
    	    		case 2:
    	    			break;
     
    	    		case 3:
    	    			break;
     
    	    		default:
    	    			break;
    	    		}	
    	    	}
    	    	else
    	    	{
    	    		System.out.println("Data Error: Interest rate must be greater than or equal to zero and less than or equal to 100. You entered " +interest);
    	    	}
    	    	}
    	    	else 
    	    	{
    	    		System.out.println("Data Error: Loan amount must be greater than zero. You entered " +principle);
    	    	}
    	   }
    	    			else
    	   {
    		   System.out.println("Data Error: Term must be greater than zero. You entered " +term);
    	   }
     
     
    	  //Prompt user to enter calculation type
    	    System.out.print("Enter Interest Calculation Type (1 – Simple, 2 – Monthly Compounded, 3 – Daily Compounded):");
    	    type = input.nextInt();
     
     
    	   switch(type) 
    	    {
    	    case 1:System.out.println("Total calculated interest: "  +simple);
    		System.out.println("Total amount to be repaid: "  +repaidSimple);
    	    break;
    	    case 2:Sprintln("Total calculated interest: "  +monthlyCompound);
    		System.out.println("Total amount to be repaid: "  +repaidMonthly);
    	    break;
    	    case 3:System.out.println("Total calculated interest: "  +dailyCompound);
    		System.out.println("Total amount to be repaid: "  +repaidDaily);
    	    break;
    	    default: System.out.println("Calculation Type Error: You must select 1, 2 or 3. You entered " +type);
    	    break;
    	    }    	
    	}
     
    	}

    Here is the output I get
    Enter Loan Amount: 0
    Enter Yearly Interest Rate (1 to 100 percent): 100.1
    Enter the Term (in months): 12
    Data Error: Term must be greater than zero. You entered 12
    Enter Interest Calculation Type (1 – Simple, 2 – Monthly Compounded, 3 – Daily Compounded):

    As you can see thats the wrong error I need to be outputted and I cant figure out how to keep it from asking "Enter Interest Calculation Type (1 – Simple, 2 – Monthly Compounded, 3 – Daily Compounded):" when an error has occured!

    This is how the output should look:
    Enter loan amount: 0
    Enter yearly interest rate (0 to 100 percent): 100.1
    Enter the term (in months): 12
    Data Error: Loan amount must be greater than zero. You entered '0'.
    Data Error: Interest rate must be greater than or equal to zero and less than or equal to 100.
    You entered '100.1'.

    Thanks for the help!


  2. #2
    Member
    Join Date
    Feb 2013
    Location
    earth
    Posts
    88
    Thanks
    12
    Thanked 9 Times in 9 Posts

    Default Re: Boolean help

    H
    Last edited by javaiscool; October 26th, 2013 at 03:02 AM. Reason: You can use [noparse] to ignore BBcode parsing

Similar Threads

  1. [SOLVED] Boolean or If?
    By 0ffConstantly in forum What's Wrong With My Code?
    Replies: 3
    Last Post: October 26th, 2012, 11:32 AM
  2. What does '^' do? Is this a boolean?
    By ColeTrain in forum Java Theory & Questions
    Replies: 2
    Last Post: October 19th, 2012, 02:58 PM
  3. Boolean method returning a boolean value
    By Deprogrammer in forum What's Wrong With My Code?
    Replies: 1
    Last Post: November 21st, 2010, 10:56 AM
  4. Some help with boolean
    By JPetroSS in forum Java Theory & Questions
    Replies: 3
    Last Post: November 2nd, 2010, 05:38 AM
  5. [SOLVED] Modification of Boolean function in Java program
    By lotus in forum Java SE APIs
    Replies: 4
    Last Post: July 10th, 2009, 10:15 AM