Question: Problem Description You are to write a program in which a number is stored in an IntegerSign object. You can then ask this object if
Problem Description
You are to write a program in which a number is stored in an IntegerSign object. You can then ask this object if the number is zero, positive, or negative and print the results.
Hints:
- For this assignment, you can consider Zero to be positive.
Getting Started
Using the techniques shown on the web page titled "How to Start Every Project in this Class" create a source file called IntegerSign.java as well as a file called Program.java. We are going to do this exercise by writing the object that solves the problem first (in a source file called IntegerSign.java) and then testing it using code we write into Program.java.
Open up the IntegerSign.java file and replace the code with the code contained in the box below:
package edu.sbcc.cs105; public class IntegerSign { public IntegerSign(int numberToStore) { } public boolean isZero() { } public boolean isPositive() { } } This is some of what is needed in the class but you will need to add some more code. Note which attributes and methods are missing and add them to the source code. You will also need to add comments to the code.
In Program.java. This is where your test code will go. Replace the code in that file with the code in the grey box below:
package edu.sbcc.cs105; public class Program { public static void main(String[] args) { // TODO: create a IntegerSign object for several different numbers // and test out its methods, print out the results System.out.printf("Enter an integer: "); Scanner consoleReader = new Scanner(System.in); int n = consoleReader.nextInt(); IntegerSign myIS = new IntegerSign(n); if (myIS.isZero()) { System.out.printf("%d is zero", n); } else if (myIS.isPositive()) { System.out.printf("%d is positive.", n); } else { System.out.printf("%d is negative", n); } consoleReader.close(); } } Go through this code and add comments as well as code to test your solution that is captured in IntegerSign.java. Use the numbers 0, 10, -10 as test cases for example.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
