reset password
Author Message
Anonymous
Posts: 166
Posted 21:44 Oct 26, 2013 |

//not sure how to use the if else statement this is what i have so far

import java.util.Scanner;

public class integerTester2
{
   private int integer;
   
   public int getInput()
   {
       return integer;
    }
    
    public integerTester2(int interger)
    {
        this.integer = integer;
    }
    
    public int determinSign()
    {
        if (integer > 0)
        {
            System.out.print("positive");
        }
        else if (integer < 0)
        {
            System.out.print(" is negative");
        }
        else if (integer == 0)
        {
            System.out.print(" is equal to zero");
        }
        return integer;
    }
}

Echoofdeath
Posts: 28
Posted 02:42 Oct 27, 2013 |

i didnt use the "Else if" statement on this one (are we supposed to?), but make sure to have a object file and a tester for your program if you dont have it for in case.(its much easier without the object file but we are required to have it lol)

make a new scanner class that prompts the user for an integer in the tester,

Scanner in= new Scanner(System.in)

......

.......

Objectname numberIdentifier= new Objectname(number)

If ( number>0) 

....

If (number<0)

......

If (number==0)

.......

etc etc.

im not really good at explaining but hopefully i helped. and dont over think or overexert yourself on this problem because its really straight forward.

Last edited by Echoofdeath at 02:44 Oct 27, 2013.
Anonymous
Posts: 166
Posted 11:40 Oct 27, 2013 |
Echoofdeath wrote:

i didnt use the "Else if" statement on this one (are we supposed to?), but make sure to have a object file and a tester for your program if you dont have it for in case.(its much easier without the object file but we are required to have it lol)

Is this true? do we really need an object file and a tester. For past exercises, we were asked to use them. Take  E5.13 on this week's hw, this one specifically asks for a Time class implying we would be using such object and also a tester to make sure everything is good. I don't think we are required to do it for the other problems in the hw. Like Echoofdeath said, it is much easier, but i believe the intended lesson here is to learn how to properly use the if/else statements. 

Last edited by Anonymous at 11:40 Oct 27, 2013.