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

This seems like a very simple problem, but I just want to make sure that I am do

ID: 3584223 • Letter: T

Question

This seems like a very simple problem, but I just want to make sure that I am doing it the right way, so any help is appreciated!! Thanks in advance! Write a class called Line that represents a line such as y=mx+b. Your Line class cannot have any System. calls, must have at a minimum the following defined, and only two private fields (attributes):: private double slope; // the slope of this line private double intercept; // the intercept of this line public Line(Point p1, Point p2) // Constructor using java.awt.Point public double getSlope() // returns the slope of this line public boolean intersect(Line other) // true if this Line intersects another Line public String toString() // returns a form like y=mx+b for user to examine this Line Attach a simple text .java file, following the coding specs of our text, specifically adhering to: -File name matches class name which starts with uppercase character. -It compiles with one of the Java IDE's using JDK6 -Import only java and javax classes, or other classes covered in our text -Never submit specialized IDE specific code (I might just run at command line) -Never submit those //TODO lines that show your IDE generated this and you did not change it. -Your name, date, and reasons for doing this appear as the first few lines (/** comments */) -More lines of comments, using // style, so every screen had a few comments at all times. -Proper indent of code as described in textbook, for class, methods, loops, decisions, etc... -Proper naming of objects (start lower case) using reasonably descriptive names. -Good Boolean ZEN, and never let me see while(true) or if(true) as you can do better.

Explanation / Answer

yeah i've done it for you ! here's your program (using swing and awt:)) import java.io.*; import javax.swing.*; import java.util.*; import java.awt.event.*; import java.awt.*; public class Equation extends JFrame implements ActionListener { JLabel m_labelP1; JLabel m_labelP2; JPanel m_panelInputP1; JPanel m_panelP1; JTextField m_textfieldP1X; JTextField m_textfieldP1Y; JPanel m_panelInputP2; JPanel m_panelP2; JTextField m_textfieldP2X; JTextField m_textfieldP2Y; JButton m_buttonCompute; JPanel m_panelInput; JPanel m_panelResult; JLabel m_labelResult; public Equation () { //initialize GUI setTitle(”Assignment 1 – Straight Line Equation”); m_labelP1=new JLabel(”Point1 (x1,y1):”); m_labelP2=new JLabel(”Point2 (x2,y2):”); m_panelP1=new JPanel(new GridLayout(1,2));//row,column m_textfieldP1X=new JTextField(”0.0?); m_textfieldP1Y=new JTextField(”0.0?); m_panelP1.add(m_textfieldP1X); m_panelP1.add(m_textfieldP1Y); m_panelInputP1=new JPanel(new GridLayout(1,2)); m_panelInputP1.add(m_labelP1); m_panelInputP1.add(m_panelP1); m_panelP2=new JPanel(new GridLayout(1,2)); m_textfieldP2X=new JTextField(”0.0?); m_textfieldP2Y=new JTextField(”0.0?); m_panelP2.add(m_textfieldP2X); m_panelP2.add(m_textfieldP2Y); m_panelInputP2=new JPanel(new GridLayout(1,2)); m_panelInputP2.add(m_labelP2); m_panelInputP2.add(m_panelP2); m_buttonCompute=new JButton(” COMPUTE “); m_buttonCompute.addActionListener(this); m_panelInput=new JPanel(new GridLayout(3,1)); m_panelInput.add(m_panelInputP1); m_panelInput.add(m_panelInputP2); m_panelInput.add(m_buttonCompute); m_labelResult=new JLabel(” Y = mX + C: “); m_panelResult=new JPanel(); m_panelResult.add(m_labelResult); //set arrangement position of the controls setLayout(new BorderLayout(1,1)); getContentPane().add(m_panelResult,BorderLayout.NORTH); getContentPane().add(m_panelInput,BorderLayout.CENTER); //display GUI setSize(400,200); setVisible(true); } public void actionPerformed(ActionEvent evt) { if(evt.getSource()==m_buttonCompute){ String strP1X=m_textfieldP1X.getText(); String strP1Y=m_textfieldP1Y.getText(); String strP2X=m_textfieldP2X.getText(); String strP2Y=m_textfieldP2Y.getText(); double dP1X=0.0;double dP1Y=0.0;double dP2X=0.0;double dP2Y=0.0; try{ dP1X=Double.parseDouble(strP1X); dP1Y=Double.parseDouble(strP1Y); dP2X=Double.parseDouble(strP2X); dP2Y=Double.parseDouble(strP2Y); } catch(NumberFormatException ex){ System.out.println(”Input not a double”); System.exit(1); } String strResult=”"; if(!(dP1X==0.0 && dP1Y==0.0 && dP2X==0.0 && dP2Y==0.0)){ System.out.println(”P1 x:”+strP1X+” P1 y:”+strP1Y+” P2 x:”+strP2X+” P2 y:”+strP2Y); System.out.println(”P1 x:”+dP1X+” P1 y:”+dP1Y+” P2 x:”+dP2X+” P2 y:”+dP2Y); Point objPoint1=new Point(dP1X,dP1Y); Point objPoint2=new Point(dP2X,dP2Y); Line objLine=new Line(objPoint1,objPoint2); objLine.calculateSlope(); objLine.calculateIntercept(); strResult=”Y = “+objLine.getSlope()+”X + “+objLine.getIntercept(); m_labelResult.setText(” “+strResult+” “); } else { strResult=”Invalid Input”; m_labelResult.setText(” “+strResult+” “); } } } public static void main(String args[]) { new Equation (); } } class Point { public double x; public double y; public Point(double x1, double y1) { x=x1; y=y1; } } class Line { private Point p1; private Point p2; private double slope; private double intercept; public Line(Point pt1, Point pt2) { p1=pt1; p2=pt2; } public void calculateSlope() { slope=(p2.y-p1.y)/(p2.x-p1.x); } public void calculateIntercept() { //take p1 as point to calculate intercept intercept=p1.y-(slope*p1.x); } public double getSlope() { return slope; } public double getIntercept() { return intercept; } }

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