aspose file tools*
The moose likes Beginning Java and the fly likes If / else statements where should they be used. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "If / else statements where should they be used." Watch "If / else statements where should they be used." New topic
Author

If / else statements where should they be used.

Rachelle Dygowski
Greenhorn

Joined: Mar 12, 2013
Posts: 5
I am trying to figure out how I can fix my code. What I need to do is take a bloodPressure int and use if statements to give a return. What I have is:


Later in code I have


Then I have:


I also have to other parts where I am doing the same for heart rate and blood sugar. It wouldn't compile and I am wondering if it because I did the 'if' statements in the set method. And if so where should I have done the 'if' statements?
James X Peterson
Whizlabs Java Support
Ranch Hand

Joined: Feb 26, 2013
Posts: 158
Hi Rachelle Dygowski,

In which line its giving error. have you declared bloodPressure variable

Regards,
James
Rachelle Dygowski
Greenhorn

Joined: Mar 12, 2013
Posts: 5
Yes I forgot to put that in there. I am just getting ready to leave work. Once I get home I can compile it again and see where the problem is. I had just put the computer away because we are changing shifts. So soon as I get home I will run it again. Thanks for replying so quick.
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 40027
    
  28
Welcome to the Ranch
You should always use code tags; I have added them for you since youare new, and you can see how much better your post looks

You have probably sorted out the compiler error by now, but I can see some logic errors.
  • 1: Why have you got a constructor which sets the blood pressure to 0? That is like starting off with the patient dead
  • 2: When you pass a blood pressure of 59, it is set to 9999, so the patient is not dead … but will be dead in a few seconds
  • Suggest:
  • 1: Get rid of that no‑arguments constructor, or at least change it to set pressure to a reasonable default, not 0.
  • 2: Change that set method to take a different action if 59 is passed.
  • Rachelle Dygowski
    Greenhorn

    Joined: Mar 12, 2013
    Posts: 5
    Here is the whole file. I did the code button so I am hoping I did that right. I am sorry I didn't do it the first time. I am not getting an error for the code. When I run my tester program it is not catching when I put blood pressure of 38. This is only part of my problem. I also have another file that test it and also one that call the Blood class. Again I will get 38 instead of getting the error code of 9999.


    Joanne Neal
    Rancher

    Joined: Aug 05, 2005
    Posts: 3742
        
      16
    Rachelle Dygowski wrote:I am not getting an error for the code.

    Well you should be. Just from a quick glance I can see two problems.
    1. Your class is called Blood but your constructors are called Score. Constructors have to have the same name as the class.
    2. Your getBloodPressure method returns the value of the BloodPressure variable, but there is no such variable. Java is case sensitive.

    If you want help you need to post the actual code.

    Joanne
    Rachelle Dygowski
    Greenhorn

    Joined: Mar 12, 2013
    Posts: 5
    Those are both typos. I didn't cut and paste because I was hoping that typing it out again I might catch something. My problem is that when I run the tester and put a blood pressure of 38 it won't catch it. I have tried putting it every where in the Blood class and that didn't work. Not only that I would like to know what I am doing wrong and not just move things until it works. So that's why I came here. Maybe now I need to look at my BloodTester class.
    Rachelle Dygowski
    Greenhorn

    Joined: Mar 12, 2013
    Posts: 5
    I got it. Needed to put it in my string and that worked. I put the restrictions in the string and that's were it read it in and compared it to the tester input. I always get excited when I get it to work. Thanks for the help. Just making me look at it another way helped.
    Shannon Graham
    Greenhorn

    Joined: Mar 11, 2013
    Posts: 14
    Rachelle Dygowski wrote:I got it. Needed to put it in my string and that worked. I put the restrictions in the string and that's were it read it in and compared it to the tester input. I always get excited when I get it to work. Thanks for the help. Just making me look at it another way helped.


    Rachelle, have you ever tried using test cases? This is the sort of code that would really benefit from a test. For instance, a test for your code would look like this:



    You can see how it checks to make sure all your functions work as you expect them to.

    Assuming you're using eclipse, you can run that as a JUnit test, and you'll get a nice green bar if all the tests pass, and a red one if they fail. That'll tell you exactly where the code is going wrong.
     
    I agree. Here's the link: http://aspose.com/file-tools
     
    subject: If / else statements where should they be used.