Hi,Please i need some help in my java program,it's purpose is to enter 2 equations and it solves them graphically,the problem is that the graph has a glitch with the x and y axis,plz can someone help me so that all the equations are solved correctly..
here's my source code:
import java.awt.*;
import javax.swing.*;
import java.util.Scanner;
public class Main1
{
public static void main(String args[])
{
Scanner sc = new Scanner(System.in);
System.out.println("Please Enter 1st Constraint Equation In Terms Of aX + bY = c");
System.out.println("Enter Value Of 'a'");
int a = sc.nextInt();
System.out.println("Enter Value Of 'b'");
int b = sc.nextInt();
System.out.println("Enter Value Of 'c'");
int c = sc.nextInt();
System.out.println("Equation : " + a + "x + " + b + "y = " + c);
GlobalVariables.result = ( c / b );
GlobalVariables.result2 = ( c / a );
System.out.println("First Point ( 0 , " + GlobalVariables.result + " )");
System.out.println("Second Point ( " + GlobalVariables.result2 + " , 0 )");
System.out.println("Please Enter 2nd Constraint Equation In Terms Of dX + eY = f");
System.out.println("Enter Value Of 'd'");
int d = sc.nextInt();
System.out.println("Enter Value Of 'e'");
int e = sc.nextInt();
System.out.println("Enter Value Of 'f'");
int f = sc.nextInt();
System.out.println("Equation : " + d + "x + " + e + "y = " + f);
GlobalVariables.result3 = ( f / e );
GlobalVariables.result4 = ( f / d );
System.out.println("First Point ( 0 , " + GlobalVariables.result3 + " )");
System.out.println("Second Point ( " + GlobalVariables.result4 + " , 0 )");
JFrame frame = new JFrame("Linear Equation Solver");
frame.setSize(500,500);
frame.setLocation(250,100);
frame.setLayout(null);
Draw i = new Draw();
frame.add(i);
frame.setContentPane(i);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setVisible(true);
}
}
class GlobalVariables
{
public static int result;
public static int result2;
public static int result3;
public static int result4;
}
class Draw extends JPanel
{
public void paintComponent(Graphics g)
{
Graphics2D g2 = (Graphics2D)g;
g2.drawLine(0,GlobalVariables.result*20,GlobalVariables.result2*20,0);
g2.drawLine(0,GlobalVariables.result3*20,GlobalVariables.result4*20,0);
g2.drawLine(0,280,500,280);
g2.drawLine(80,0,80,500);
g2.rotate(Math.PI / 2 , 20, 200);
g2.drawLine(0,GlobalVariables.result*20,GlobalVariables.result2*20,0);
g2.drawLine(0,GlobalVariables.result3*20,GlobalVariables.result4*20,0);
}
}