• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Rob Spoor
  • Tim Cooke
  • Junilu Lacar
Sheriffs:
  • Henry Wong
  • Liutauras Vilda
  • Jeanne Boyarsky
Saloon Keepers:
  • Jesse Silverman
  • Tim Holloway
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Mikalai Zaikin
  • Piet Souris

Need help on passing values from one method to another

 
Ranch Hand
Posts: 67
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi,
i have twomethod in a java class named polynomail.I wanted to pass the value generated in constructPolynomial()method to displaySelf()method.
How do i do that.Below is the prigram i have written so far.. and even i wanted to findout the value of ax^2+ bx + c in a method named functionvalue().Thank you very much in adavnce

import java.util.Scanner;


class Polynomial {

private double quadratic_co;
private double linear_co;
private double constant;
public Polynomial(){
}
public void constructPolynomial(){
Scanner scan = new Scanner(System.in);
System.out.println("Enter the coefficient of the quadratic term:");
quadratic_co = scan.nextDouble();
System.out.println();
System.out.println("Enter the coefficient of the linear term:");
linear_co = scan.nextDouble();
System.out.println();
System.out.println("Enter the coefficient of the constant term:");
constant = scan.nextDouble();
}
/*public double functionValue(double x,double value, double constant){

value =( (x*x)*quadratic_co) + (x* linear_co)+ constant;
return value;

}*/

public void displaySelf(double quadratic_co, double linear_co, double constant ){

String s = quadratic_co + "x^2 + " + linear_co + "x + " + constant;

System.out.println("Entered Polynomial:f(x)= " + s);

}

}
public class Assi3
{
public static void main(String args[])
{
Polynomial p = new Polynomial();
p.constructPolynomial();
//p.functionValue(4.0);
p.displaySelf();
}
}
 
Ranch Hand
Posts: 148
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
 
You showed up just in time for the waffles! And this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic