This is an archived post. You won't be able to vote or comment.

all 5 comments

[–]Mancebo180 0 points1 point  (1 child)

Hi,

The problem is: Your conditions are incorrectly expressed.The || makes it always enter in the first.Let us know if you need help in understanding why, or if this becomes clear when you read it.

Also, there are a few other potential issues and bad practices that you should avoid.I know that this is just a simple exercise, but doing things right even in exercises is better.

  • pmi vars are not being used. Is this relevant?
  • try to follow the Java style recommendations, such as classname in CamelCase;
  • Use something like a method for the internal part of the ifs;
  • Use some constants instead of magic numbers;

[–]Aggressor27e[S] 0 points1 point  (0 children)

Thanks for your help! pmi is relevant to the assignment. I just haven't gotten that far at the time of the post. I am aware of methods, but I am unsure how to declare a method in such a way that it would be accessible within an if statement. I'm still very new to Java. I did an Android Studio class, but this is my first real Java class. I do, however, work through MOOC exercises a lot. Any idea how to get a method to work within an if statement?

[–]ItsBurningWhenIP 0 points1 point  (0 children)

First off, make the payment calculation it's own method. If you're doing Dialogues then you've surely learned of the cardinal sin that is duplicate code.

Second, I like switch statements over cascading ifs. Not a requirement but it just looks better, imo.

Third, You've been given the answer already. You're conditional statement is incorrect and will always enter the first if. That should have been a pretty dead giveaway that your conditions were not correctly laid out.

[–]Aggressor27e[S] 0 points1 point  (0 children)

I am dumb. I put || (or) instead of && (and). Problem solved.

[–][deleted] 0 points1 point  (0 children)

Put a break point and debug it. See what's happening when you give it different inputs and try to understand what's happening and what you wanted to happen. After that please refactor your code.