Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
Solved

# Learning Java PolynomialTester

Posted on 2008-11-02
Medium Priority
219 Views
I am add method of getDescription to the Polynomial class  Method should return one of the 4 strings from the chart.  This method should take no input parameters.   Then add code to the main class that will prompt the user to enter the number of terms in a polynomial.

Chart is
Number of Terms            Description
1                                  monomial
2                                  binomail
3                                  trinomial
4 or more                    Polynomial(no special name)

How many ters are in the polynomial function?
2
The fucntion is a binomial

Any help would greatly be appreciated.

***********************************
package polynomialtester;
import javax.swing.JOptionPane;
public class PolynomialTester {

public static void main(String[] args)
{
String input;
int numTerms;

input = JOptionPane.showInputDialog("How many terms are in the polyomial funcions?");
numTerms = int.parseInt(input);
}

}
*********************************
package polynomialtester;

public class Polynomial
{
public Polynomial(int initTerms)
{
numTerms = initTerms;
}
public int getTerms()
{
return numTerms;
}
public int getDescription(int numTerms)
{
String monomial;
String binomail;
String trinomial;
String Polynomial;

switch(numTerms)
{
case 1 : return "monomial";
case 2 : return  "binomail";
case 3 : return "trinomial";
default :
if(numTerms >= 4)
{
return "polynomial";
}
}
// HERE BELONGS A return FOR ALL OTHER CASES.
}

private int numTerms;

}

0
Question by:ca1358
[X]
###### Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

• Help others & share knowledge
• Earn cash & points
• 4

LVL 24

Expert Comment

ID: 22865233
The following lines have no purpose and should be deleted:

public Polynomial(int initTerms)
{
numTerms = initTerms;
}
public int getTerms()
{
return numTerms;
}
and:
String monomial;
String binomail;
String trinomial;
String Polynomial;

;JOOP!
0

Author Comment

ID: 22865244
public Polynomial(int initTerms)
{
numTerms = initTerms;
}
public int getTerms()
{
return numTerms;
}
The exercise has this start and must include the above in the class.
0

LVL 24

Expert Comment

ID: 22865255

public static void main(String[] args)
{
String input;
int numTerms;

input = JOptionPane.showInputDialog("How many terms are in the polyomial funcions?");

try // Checking input, prepare for errors:
{
numTerms = int.parseInt(input);
System.out.println("That function is " + Polynomial.getDescription(numTerms);
}
catch(ParseException e)
{
}

the other class changes too:

public static int getDescription(int numTerms)
{
String monomial;
String binomail;
String trinomial;
String Polynomial;

switch(numTerms)
{
case 1 : return "monomial";
case 2 : return  "binomail";
case 3 : return "trinomial";
default :
if(numTerms >= 4)
{
return "polynomial";
}
}
return("Illegal number.");
}

The private int at the bottom can be deleted too.
Unless you insist in creating an object for Polynomial ......................

;JOOP!
0

LVL 24

Expert Comment

ID: 22865263
I was typing while you answered.
You should have listed the exercise first!

Now the code changes a bit.

;JOOP!
0

LVL 24

Accepted Solution

sciuriware earned 2000 total points
ID: 22865286
***********************************
package polynomialtester;
import javax.swing.JOptionPane;
public class PolynomialTester
{
public static void main(String[] args)
{
String input;
int numTerms;

input = JOptionPane.showInputDialog("How many terms are there in the polynomial function?");
try // Checking input, prepare for errors:
{
numTerms = int.parseInt(input);
Polynomial p = new Polynomial(numTerms);
System.out.println("That function is " + p.getDescription();
}
catch(ParseException e)
{
}
}
*********************************
package polynomialtester;

public class Polynomial
{

private int numTerms;  // Declaration on top!!!

public Polynomial(int initTerms)  // Constructor
{
numTerms = initTerms;
}
public int getTerms()     // Unused now.
{
return numTerms;
}

public int getDescription()  // No argument, it was already given!
{
switch(numTerms)
{
case 1 : return "monomial";
case 2 : return  "binomail";
case 3 : return "trinomial";
default :
if(numTerms >= 4)
{
return "polynomial";
}
}
return("Illegal number.");
}
}

;JOOP!
0

## Featured Post

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

If you haven’t already, I encourage you to read the first article (http://www.experts-exchange.com/articles/18680/An-Introduction-to-R-Programming-and-R-Studio.html) in my series to gain a basic foundation of R and R Studio.  You will also find the …
In this post we will learn different types of Android Layout and some basics of an Android App.
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.
###### Suggested Courses
Course of the Month8 days, 10 hours left to enroll