| | |
Need help with program
Thread Solved |
•
•
Join Date: Feb 2008
Posts: 29
Reputation:
Solved Threads: 0
I am getting an error saying NumberOperations can't be instantiated. Here is the code.
Java Syntax (Toggle Plain Text)
<ol style="list-style-type: decimal"><li>public static void main(String[] args) {</li> <li> // TODO Auto-generated method stub</li> <li> // declare variables</li> <li> int num1, num2, sum, diff, product, average, absolute, max, min, adjusted1, adjusted2, adjustedSum;</li> <li> // Display Program Title and Directions</li> <li> ProgramDisplay.displayGreeting();</li> <li> int option = 0;</li> <li> do {</li> <li> // Collect User Input and Create NumberOperattions Object</li> <li> num1 = UserInput.getNum("Enter first integer number: ");</li> <li> num2 = UserInput.getNum("Enter second integer number: ");</li> <li> NumberOperations numOper = new NumberOperations(num1, num2);</li> <li> // Calculate Sum</li> <li> sum = numOper.calcSum();</li> <li> ProgramDisplay.displayResult("The sum of " + num1+ " and " + num2 + " is: ", sum);</li> <li> // Calculate Difference</li> <li> diff = numOper.calcDifference();</li> <li> ProgramDisplay.displayResult("The difference of " + num1+ " and " + num2 + " is: ", diff);</li> <li> // Calculate Product</li> <li> product = numOper.calcProduct();</li> <li> ProgramDisplay.displayResult("The product of " + num1+ " and " + num2 + " is: ", product);</li> <li> // Calculate Average</li> <li> average = numOper.calcAverage();</li> <li> ProgramDisplay.displayResult("The average of " + num1+ " and " + num2 + " is: ", average);</li> <li> NumberOperations NumberOper;</li> <li> // Calculate Absolute Value of Difference -- note that calcAbsolute is a static (class) method and is invoked using the class name</li> <li> absolute = NumberOper.calcAbsolute(diff);</li> <li> ProgramDisplay.displayResult("The absolute of " + diff + " is: ", absolute);</li> <li> // if both numbers are greater than 100, then subtract 100 from each.</li> <li> if (InputValidation.bothMoreThan100(num1, num2)) {</li> <li> adjusted1 = num1 - 100;</li> <li> adjusted2 = num2 - 100;</li> <li> ProgramDisplay.displayResult("The adjusted value of " + num1+ " is: ", adjusted1);</li> <li> ProgramDisplay.displayResult("The adjusted value of " + num2+ " is: ", adjusted2);</li> <li> }</li> <li> // if both numbers are negative, then add 200 to their sum.</li> <li> if (InputValidation.bothLessThanZero(num1, num2)) {</li> <li> adjustedSum = sum + 200;</li> <li> ProgramDisplay.displayResult("The adjusted sum is: ", adjustedSum);</li> <li> }</li> <li> } while (ProgramDisplay.terminateApplication());</li> <li> }</li> <li> }</li> </ol>
•
•
Join Date: Nov 2007
Posts: 84
Reputation:
Solved Threads: 0
•
•
•
•
I am getting an error saying NumberOperations can't be instantiated. Here is the code.
can you post the code of the NumberOperations contructor!
so that we can c what possibly prevent the creation,
one more Q, the error is runtime error, is not it?]
•
•
•
•
••••do { // Collect User Input and Create NumberOperattions Object num1 = UserInput.getNum("Enter first integer number: "); num2 = UserInput.getNum("Enter second integer number: "); NumberOperations numOper = new NumberOperations(num1, num2);
may would be better if you create it with an empty contructor , then use set methods to change the variable each time inside thte loop,
unless the goal of your program requires what you've wrote
if that was not clear hope you send back
Good Luck
Last edited by knowledgelover; Apr 13th, 2009 at 5:47 am.
there's always something to learn
![]() |
Similar Threads
- Playing .Wav/MIDI files in a Visual Basic Program (Visual Basic 4 / 5 / 6)
- What's the HARDEST program you've written? (Computer Science)
- Cool little Program to disable startup programs (Windows NT / 2000 / XP)
- Program is shutting down right after program is executed (C++)
- 3d Program (Game Development)
Other Threads in the Java Forum
- Previous Thread: another ActionListener question
- Next Thread: java - mySql connection
| Thread Tools | Search this Thread |
911 addball addressbook android api append applet application apps array arrays automation binary bluetooth businessintelligence button card character class client code collision component crashcourse css csv database eclipse ee error fractal free game gis givemetehcodez graphics gui html ide image integer integration j2me japplet java javaarraylist javadoc javafx javaprojects jni jpanel julia jvm linux list loan machine map method methods migrate mobile netbeans newbie objects oriented output panel phone physics problem program programming project projects radio recursion replaydirector reporting researchinmotion scanner se server service set sms software sort sql string swing test textfield threads transfer tree trolltech ubuntu utility windows





