Click here to Skip to main content
15,896,269 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
C#
import java.util.Scanner;
import static java.lang.Math;
public class Root1
{
	int a;
	int b;
	int c;
	double root1;
	public Root1(int a, int b, int c)
	{
		this.a=a;
		this.b=b;
		this.c=c;
	}
	public double calculateRoot1()
	{
		int d=calculateDeterminant();
		this.root1=(-b+Math.sqrt(d))/2*a;
		return root1;
	}
	public int calculateDeterminant()
	{
		int d= b*b-(4*a*c);
		return d;
	}
}
public class Root2
{
	int a;
	int b;
	int c;
	double root2;
	public Root2(int a, int b, int c)
	{
		this.a=a;
		this.b=b;
		this.c=c;
	}
	public double calculateRoot2()
	{
		int d=calculateDeterminant();
		this.root2=(-b+Math.sqrt(d))/2*a;
		return root2;
	}
	public int calculateDeterminant()
	{
		int d= b*b-(4*a*c);
		return d;
	}
}
public class RootMain
{
	Scanner input=new Scanner(System.in);
	System.out.println("Enter value of a");
	int a=input.nextInt();
	System.out.println("Enter value of b");
	int b=input.nextInt();
	System.out.println("Enter value of c");
	int c=input.nextInt();	
	public static void main(String args[])
	{
		Root1 r1= new Root1(a,b,c);
		System.out.println(r1.calculateRoot1);
		Root2 r2=new Root2(a,b,c);
		System.out.println(r1.calculateRoot2);
	}
}


What I have tried:

i am creating a program of finding roots of quadratic equation but getting error in main class. please solve it. tomorrow i have to present this program in my class.
Posted
Updated 26-Sep-16 22:40pm
v2
Comments
Patrice T 26-Sep-16 6:44am    
And you have plan to tell us which error message and where ?
OriginalGriff 26-Sep-16 6:47am    
What? And spoil the surprise? :OMG:
Patrice T 26-Sep-16 6:51am    
lol
[no name] 26-Sep-16 8:23am    
You should probably tell your teacher that they need to incorporate "how to use the debugger" into your class.
Member 12759772 27-Sep-16 1:33am    
actually two classes and two constructor are must requirement to build this program. if any solution please help.

You do not need the extra classes in there and you have code outside your main method, so this is never going to build, let alone run. See The Java™ Tutorials[^] for information on creating a java program.
 
Share this answer
 
Comments
Member 12759772 27-Sep-16 1:33am    
actually two classes and two constructor are must requirement to build this program. if any solution please help.
Richard MacCutchan 27-Sep-16 2:46am    
No, that is not at all true. You only need a single class to make this program work. If your assignment insists that you create multiple classes then you need to learn about nested classes: see http://docs.oracle.com/javase/tutorial/java/javaOO/nested.html[^].
Member 12759772 27-Sep-16 4:40am    
Yes you are right but i have solved all of this errors and posting the solution, and also a hearty thanks for all of your suggestion. Thank you every one.
Richard MacCutchan 27-Sep-16 8:44am    
Have you actually tried to run it? Even after correcting the syntax errors it does not give an answer.
C#
import java.util.Scanner;
import java.lang.Math;
class Root1
{
	int a;
	int b;
	int c;
	double root1;
	
	Root1(int x, int y, int z)
	{
		a=x;
		b=y;
		c=z;
	}
	public double calculateRoot1()
	{
		int d= b*b-(4*a*c);
		root1=(-b+Math.sqrt(d))/2*a;
		return root1;
	}
	
}
class Root2
{
	int a;
	int b;
	int c;
	double root2;
	Root2(int x, int y, int z)
	{
		a=x;
		b=y;
		c=z;
	}
	public double calculateRoot2()
	{
		int d= b*b-(4*a*c);
		root2=(-b-Math.sqrt(d))/2*a;
		return root2;
	}
	
}
public class RootMain
{
		
	public static void main(String args[])
	{
		Scanner input=new Scanner(System.in);
		System.out.println("Enter value of a");
		int a=input.nextInt();
		System.out.println("Enter value of b");
		int b=input.nextInt();
		System.out.println("Enter value of c");
		int c=input.nextInt();
			
		Root1 r1= new Root1(a,b,c);
		System.out.println("Value of Root 1 is:"r1.calculateRoot1());
		Root2 r2=new Root2(a,b,c);
		System.out.println("Value of Root 2 is:"r2.calculateRoot2());
	}
}
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900