Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

The project name of this exercise is IntegerSign . The purpose of this assignmen

ID: 3579191 • Letter: T

Question

The project name of this exercise is IntegerSign.

The purpose of this assignment is to apply what you have learned about decisions with if statements and multiple alternatives.

Problem Description

The detailed description of this problem comes from the Programming Exercise P3.1 that is in the book (page 126).

This problem should be solved by writing all your code in public static void main. You will want to implement the algorithm inside of the main method.

Using the test input, your output should look like:

Enter a number: -1 negative

Getting Started

Like our last exercise, WE are going to do this exercise by writing the source code that solves the problem first in IntegerSign.java. Using the techniques shown on the web page titled How to Start Every Project in this Classcreate a source file called IntegerSign.java. This is where your code will go. Replace the code in that file with the code in the grey box below:

Now go through IntegerSign.java, add the proper headers, as in past assignments, and then change the [CHANGE THIS TO YOUR INFORMATION] text to the proper items. There are two items to be changed. Don't forget to add comments to the beginning of your methods, as well.

For your code, get a number from the user using the Scanner class as in past assignments, then output the words negative, positive or zero only. The unit test will test for exactly these words.

Once you've written your code run the code by single clicking on IntegerSign.java in the package explorer and selecting Run->Run from the menu or using the keyboard shortcut. Examine the output. Does it do what you want? If not, how can you modify the code to do what you want?

Explanation / Answer

IntegerSign.java

import java.util.Scanner;


public class IntegerSign {

public static String determineSign(int integer) {
// Put code here to determine sign of value and return string representation
   if(integer < 0){
       return "negative";
   }
   else if(integer > 0){
       return "positive";
   }
   else{
       return "zero";
   }
}
  
public static void main(String[] args) {
// Put code here to get input from user, then call determineSign
   Scanner scan = new Scanner(System.in);
   System.out.print("Enter a number: ");
   int n = scan.nextInt();
   System.out.println(determineSign(n));
}

}

Output:

Enter a number: -5
negative