Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

How do i make a class and then make a driver or vice verse? public class LinearE

ID: 3641999 • Letter: H

Question

How do i make a class and then make a driver or vice verse?



public class LinearEquation {

private int m_a;
private int m_b;
private int m_c;
private int m_d;
private int m_e;
private int m_f;
public LinearEquation(int a,int b,int c,int d,int e,int f )
{
m_a = a;
m_b = b;
m_c = c;
m_d = d;
m_e = e;
m_f = f;
}
public boolean isSolvable()
{
if((m_a*m_d - m_b*m_c)==0)
{
return false;
}
return true;
}
public double getX()
{
return (double) (m_e*m_d - m_b*m_f) / (m_a*m_d - m_b*m_c);

}
public double getY()
{
return (double) (m_a*m_f - m_e*m_c) /( m_a*m_d - m_b*m_c );
}
}


And the driver part that goes into a separate class

import java.util.Scanner;
public NameYourDriverClass{
public static void main(String[]arg)
{
Scanner scan = new Scanner(System.in);
int a,b,c,d,e,f;
System.out.println("Enter a");
a = scan.nextInt();
System.out.println("Enter b");
b = scan.nextInt();
System.out.println("Enter c");
c = scan.nextInt();
System.out.println("Enter d");
d = scan.nextInt();
System.out.println("Enter e");
e = scan.nextInt();
System.out.println("Enter f");
f = scan.nextInt();
LinearEquation l = new LinearEquation(a, b, c, d, e, f);
if(!l.isSolvable())
{
System.out.println("The system has no solution");
}
else
{
System.out.println("The value of x= " + l.getX());
System.out.println("The value of y= " + l.getY());

}
}
}

Explanation / Answer

You mean how do you create a new Java Class in Eclipse? 1. Create a new project in Eclipse. - Click File -> New -> Java Project 2. Name your project and leave everything else alone and click finish. 3. In the Package Explorer, expand your newly created project and right click on the src folder. 4. Click New -> Class. Name the class (your driver class name) and click finish. 5. Create another class the same way (this time make sure you navigate all the way down into the "(default package)" in the src of your project. This is for your LinearEquation class. 6. Right click on the root folder (your project name) and highlight the Run as... option. 7. Click on the Run Configurations option and you will be taken to a new dialog window. 8. In the Main tab, browse to your newly created project and select it. 9. Now search for the Main class to use. This is your Driver class. Eclipse should only list classes that have the main() in them. (should only be one per project). 10. You have now set a driver class for your project and this class will be run each time you Run / Start the project. Hope this Helps! Happy Coding!

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote