PolynomialCalculator.java - package hw5 import...

This preview shows page 1 - 2 out of 2 pages.

package hw5; import java.util.Scanner; /** * driver for the RPN calculator on polynomials; see comments below * */ public class PolynomialCalculator { /** * Drives the RPN (postfix) calculator for polynomials with integer coefficients. * The user can enter a monomial as two space-separate decimal integers * coefficient and degree (degree must be nonnegative), * which gets passed to the calculator as an operand, * the operations "+", "-" and "*", which also get passed to the calculator, * or "q", which quits the calculator * * Direct entry of polynomials other than monomials is not supported; however, * it is easy to enter the monomials and then add them up using the appropriate * number of "+" operations, thus getting the desired polynomial * * @param args ignored */ public static void main (String [] args) { Scanner scan = new Scanner (System.in); RPNCalculator<Polynomial> calc = new RPNCalculator<Polynomial>(); while(true) { boolean printStack = true; if (scan.hasNextInt()) { // If the next input is an operand int coeff = scan.nextInt(); // the first integer is the coefficient int degree; while(true) { // keep trying to get the second integer,

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture