Show DevBest [Java] Quadratic Equation Solver

Would you like to see coded in C++?


  • Total voters
    3
Status
Not open for further replies.

Jeisa

Member
May 4, 2011
112
2
READ ENTIRE POST (please)

I've posted about this before, but I just demonstrated how the program worked, I also have this in Python but I am releasing the Java version. If you want the one coded in Python let me know. Anyways here's the source code, if you could compile this into an executable jar and post here, that would be great. Thanks!
Pastebin source code :
Actual source :
Code:
    package quadratics;
    import java.io.*;
    import java.util.*;
    public class Quadratics {
        public static void main(String[] args) {
            Scanner scan = new Scanner(System.in);
            double a,b,c,twoa;
            double discriminant;
            System.out.println("Enter value of a : ");
            a = scan.nextDouble();
            System.out.println("Enter value of b : ");
            b = scan.nextDouble();
            System.out.println("Enter value of c : ");
            c = scan.nextDouble();
            discriminant = b*b-(4*a*c);
            twoa = 2*a;
            if (discriminant < 0 ) {
                System.out.println("Since your discriminant is negative, (" + discriminant + ") There are no roots.");
            } else {
                double formulaplus, formulaminus, plusfin, minusfin;
                formulaplus = -b + Math.sqrt(discriminant);
                plusfin = formulaplus/twoa;
                formulaminus = -b - Math.sqrt(discriminant);
                minusfin = formulaminus/twoa;
                System.out.println("Your roots are\n" + plusfin + "\n" + minusfin);
                System.out.println("Discriminant = " + discriminant);
            }
        }
    }

How this works : All you have to do is plugin the variables a,b,c and it gives you the roots to the quadratic. If you don't know what quadratics are, then please head on to this wiki.
Anyways, I hope this will be useful to all of you, also I am developing another program which solves all the most common used equations, if you would like to know more about this left me know.

Note: I coded this for my own use, and I think it is badly coded because I just started learning java a week ago, and if it is, tell me where I could improve code in.
 

Jeisa

Member
May 4, 2011
112
2
Try this for .jar

PHP:
jar cf quadratics.jar quadratics.class
I got the .jar file now, but when I open no console or anything, should I make a GUI ( can you help me out, im learning java) :)
 

Myrax

New Member
Sep 14, 2011
11
10
I got the .jar file now, but when I open no console or anything, should I make a GUI ( can you help me out, im learning java)

GUI's are difficult.

Create a text file called Manifest.txt and inside of it put 'Main-Class: Package.Class' so in your case the below (with a newline after 'Quadratics')

PHP:
Main-Class: quadratics.Quadratics

Then create the jar using the following command

PHP:
jar cfm Quadratics.jar Manifest.txt quadratics/*.class

Then obviously execute it in the following fashion

PHP:
java -jar Quadratics.jar
 

Jeisa

Member
May 4, 2011
112
2
Alright, I got it working :D

Pretty nice, thanks for this!

Thanks! And you're welcome! Ill be releasing more useful programs :D
GUI's are difficult.

Create a text file called Manifest.txt and inside of it put 'Main-Class: Package.Class' so in your case the below (with a newline after 'Quadratics')

PHP:
Main-Class: quadratics.Quadratics

Then create the jar using the following command

PHP:
jar cfm Quadratics.jar Manifest.txt quadratics/*.class

Then obviously execute it in the following fashion

PHP:
java -jar Quadratics.jar
Thanks so much for the feedback, I'm barely learning java, I'll sure try this later.
 

Macemore

Circumcised pineapples
Aug 26, 2011
1,681
819
Could you post a link for the .jar download?
I actually have a shit ton of homework, xD
 
Status
Not open for further replies.

Users who are viewing this thread

Top