0% found this document useful (0 votes)
4 views5 pages

Lab 33 B

The document outlines an assignment for an AP Computer Science I Java lab focused on creating a program to evaluate polynomial functions using a linked list. It includes two versions of the assignment: an 80-point version that displays polynomial terms without mathematical formatting, and a 100-point version that adheres to mathematical conventions. The document provides details on the required methods, class structure, and sample outputs for both versions.

Uploaded by

emailao031
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views5 pages

Lab 33 B

The document outlines an assignment for an AP Computer Science I Java lab focused on creating a program to evaluate polynomial functions using a linked list. It includes two versions of the assignment: an 80-point version that displays polynomial terms without mathematical formatting, and a 100-point version that adheres to mathematical conventions. The document provides details on the required methods, class structure, and sample outputs for both versions.

Uploaded by

emailao031
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 5

AP Computer Science I Java Unit Lab Assignment # 33b

The "Polynomial" program 80 & 100 Point Versions

Assignment Purpose:
The purpose of this program is to demonstrate knowledge of the Java syntax that is required to
create and traverse a simple linked list, which is created with dynamic memory allocation.

Write a program that will evaluate polynomial functions of the following type:

Y = a1Xn + a2Xn-1 + a3Xn-2 + . . . an-1X2 + anX1 + a0X0


where X, the coefficients ai, and n are to be given.

This program has to be written, such that each term of the polynomial is stored in a linked list node.
You are expected to create nodes for each polynomial term and store the term information. These
nodes need to be linked to each previously created node. The result is that the linked list will access in
a LIFO sequence. When you display the polynomial, it will be displayed in reverse order from the
keyboard entry sequence.

80 Point Version

This program has a 80 point and a 100-point version. The 80-point version displays the contents of
each polynomial term, and is not concerned with normal mathematical appearance. The result is a
polynomial display like:

Y = 1X^0 + 0X^1 + 0X^2 + 1X^3

100 Point Version

The 100-point version makes the display follow mathematical conventions and does not display terms
with zero coefficients, nor powers of 1 or 0. The polynomial example, above, is shown again as it would
appear with the 100-point version.

Y = 1 + X^3

Exposure Java 2008 Lab 33b Page 1 07-26-08


Normal polynomials should work with real number coefficients. For the sake of this program, assume
that you are strictly dealing with integers and that the result of the polynomial is an integer as well. You
will be provided with a special PolyNode class. The PolyNode class is very similar to the ListNode
class that you learned about in chapter 33 and in class. The ListNode class is more general and works
with object data members. Such a class is very practical for many different situations. For this
assignment, early in your linked list learning, a class has been created strictly for working with a linked
list that will store the coefficient and the degree of each term in the polynomial..

// Lab33bst.java
// The student version of the Lab33b assignment.

import java.io.*;

public class Lab33bst


{
public static void main (String args[]) throws IOException
{
}
}

class PolyNode
{

private int coeff; // coefficient of each term


private int degree; // degree of each term
private PolyNode next; // link to the next term node

public PolyNode (int c, int d, PolyNode initNext)


{
coeff = c;
degree = d;
next = initNext;
}

public int getCoeff()


{
return coeff;
}

public int getDegree()


{
return degree;
}

public PolyNode getNext()


{
return next;
}

public void setCoeff (int newCoeff)


{
coeff = newCoeff;
}

public void setDegree (int newDegree)


{
degree = newDegree;
}

public void setNext (PolyNode newNext)


{
next = newNext;
}
}

Exposure Java 2008 Lab 33b Page 2 07-26-08


You are expected to add various methods that are not provided in the student version. The sample
execution will indicate which methods you need to write. Everything could be finished in the main
method of the program, but hopefully you realize by now that such an approach is rather poor
program design.

Lab33b 80 Point Version One Required Output

Lab33b 80 Point Version

##### ENTER-POLY METHOD #####

Enter the degree of the polynomial ===>> 4

Enter coefficient for X^4 If no term exists, enter 0 ===>> 1


Enter coefficient for X^3 If no term exists, enter 0 ===>> 2
Enter coefficient for X^2 If no term exists, enter 0 ===>> 3
Enter coefficient for X^1 If no term exists, enter 0 ===>> 4
Enter coefficient for X^0 If no term exists, enter 0 ===>> 5

##### ENTER-XVALUE METHOD #####

Enter X value of the polynomial ====>> 2

##### DISPLAY-POLY METHOD #####

Y = 5X^0 + 4X^1 + 3X^2 + 2X^3 + 1X^4

##### COMPUTE-POLY METHOD #####

##### DISPLAY-VALUE METHOD #####

Y(2) = 57

Exposure Java 2008 Lab 33b Page 3 07-26-08


Lab33b 100 Point Version Two Required Outputs
Lab33b 100 Point Version

##### ENTER-POLY METHOD #####

Enter the degree of the polynomial ===>> 4

Enter coefficient for X^4 If no term exists, enter 0 ===>> 1


Enter coefficient for X^3 If no term exists, enter 0 ===>> 2
Enter coefficient for X^2 If no term exists, enter 0 ===>> 3
Enter coefficient for X^1 If no term exists, enter 0 ===>> 4
Enter coefficient for X^0 If no term exists, enter 0 ===>> 5

##### ENTER-XVALUE METHOD #####

Enter X value of the polynomial ====>> 2

##### DISPLAY-POLY METHOD #####

Y = 5 + 4X + 3X^2 + 2X^3 + X^4

##### COMPUTE-POLY METHOD #####

##### DISPLAY-VALUE METHOD #####

Y(2) = 57

Lab33b 100 Point Version

##### ENTER-POLY METHOD #####

Enter the degree of the polynomial ===>> 4

Enter coefficient for X^4 If no term exists, enter 0 ===>> 1


Enter coefficient for X^3 If no term exists, enter 0 ===>> 0
Enter coefficient for X^2 If no term exists, enter 0 ===>> 0
Enter coefficient for X^1 If no term exists, enter 0 ===>> 0
Enter coefficient for X^0 If no term exists, enter 0 ===>> 5

##### ENTER-XVALUE METHOD #####

Enter X value of the polynomial ====>> 2

##### DISPLAY-POLY METHOD #####

Y = 5 + X^4

Exposure Java 2008 Lab 33b Page 4 07-26-08


##### COMPUTE-POLY METHOD #####

##### DISPLAY-VALUE METHOD #####

Y(2) = 21

Exposure Java 2008 Lab 33b Page 5 07-26-08

You might also like