LinkedList help
Posted on
16th Feb 2014 07:03 pm by
admin
Ok so I just learned quickly about lists, so I have a not too hard project I think, but am having a few issues:
Here is the project. Create a lovely polynomial calculator, that takes the equation from the user, and a number for x.
Then solve it, but I have to use lists. As well as that I have to printout the equation with x at the end. And I will also have to have to add a method for finding the derivative of the equation.
Did you know?Explore Trending and Topic pages for more stories like this.
I'll worry about the printout and the derivative at the end, except I have a problem right now... I'll show my code first
Here is the lovely main
Code: import java.util.*;public class PolyDriver { public static void main(String[] args) { boolean isrunning = true; String userinput="no"; String no="no"; String yes="yes"; double whatisx=0; Scanner scan = new Scanner(System.in); System.out.println("What is X?"); whatisx =scan.nextDouble(); while(userinput.equals(no)) { System.out.println("Enter the first integer"); double d = scan.nextDouble(); System.out.println("Enter the exponent"); int e = scan.nextInt(); Poly m = new Poly(d, e, whatisx); System.out.println("Done?"); String j = scan.next(); if(j.equals(yes)) { System.exit(0); } } // System.out.println("Enter the number for x"); // Scanner scan = new Scanner(System.in); }}
Then here is the Poly class
Code: import java.util.*;/* * To change this template, choose Tools | Templates * and open the template in the editor. *//** * * @author JigglyWiggly-laptop */public class Poly { double integer=0; int exponent=0; double variable=0; double vrz=0; double whatisx=0; LinkedList linkedlist = new LinkedList(); public Poly(double d, int e, double x) { integer=d; exponent=e; whatisx=x; calculations(); // calculations(); } public double calculations() { double v = Math.pow(whatisx, exponent); double j = v*integer; linkedlist.add(j); printout(); return j; } public double printout() { for(int i=0; i
When I run it:
Code: run:What is X?2Enter the first integer2Enter the exponent2---18.0Done?noEnter the first integer2Enter the exponent2---18.0Done?noEnter the first integer2Enter the exponent2---18.0Done? Why does it not make the list bigger? And the numbers should be adding up. Any ideas?
(Also ignore the funky way of getting the user input, this is the way we were told to do so)
No comments posted yet
Your Answer:
Login to answer
318
44
Other forums
GET vs SUBMIT Button to show sections on one index.php page?
Just curious if one of these ways is better (i.e. more efficient) than the other.
I have a
Slashes
Have a small problem and I'm not able to understand why I'm getting the results I'm getting... and i
Save cookie to DB
I'm working on a pixel tracking script for an incentive website and I need to use an ASP script to s
unexpected T_VARIABLE error
Hey all! I'm getting an unexpected T_VARIABLE with the following function:
function getHighes
isset undefined variable
Hi all,
Hope someone can point out the obvious. I've a log in script, if you dont enter a use
this code is strange !
Hi i got this code from the web.. It checks for live and dead socks
It is working perfectly on my
Multiple if statements
Ok so seems basic but for some reason I'm not doing it right. What I want is to be able to have 2 se
PHP login form help (Done Most of It)
Hi i am having a problem, when i try logging in it is always saying "Invalid Login" im not
Passing vars to the DB
I have 3 small testing tables:
ID TYPE
1 pepperoni
2 C. bacon
3 taco
ID TY
What am I missing here? Help!
Hello all!. I can't seem to get this working right. Well - it renders right, but something is goin