Hi guys! I'm fairly new to this website, thought id give it a shot. I have an assignment that i must complete, and i'm hoping you experts can help! Basically, i have to write a program that allows me to enter an a, b and c value for Ax + By + C = 0 (i have already done), and then calculates slope, y int, xint (done). I also have to create a program that reads an equation that a user has typed in and then converts it into the Ax + By + C = 0 form. It would be even better if the program does not allow a person from typing in a wrong symbol/letter instead of a number or + or - sign. Also, i must be able to enter an equation, and the program makes a graph of that equation. The latter two, i cannot seem to make. I am not sure how to do. The point of the programs is to learn about classes. Thanks ahead of time for the help. This is what i've done.
// The Line Class import java.awt.*; import hsa.Console; public class LineClass { static Console c; public static void main (String[] args) { c = new Console (); char choice; do { c.clear (); // clears the screen c.println ("Read Line Class Problems"); //menu c.println ("--------------------------------"); c.println ("1. Reading A, B, and C"); c.println ("2. Read a line"); c.println ("3. Make a graph"); c.println ("0. Quit"); choice = c.getChar (); if (choice == '1') { reader (); c.print ("Press ENTER to return to the main menu."); c.getChar (); } } while (choice != '0'); // exit when 0 pressed c.close (); // Place your program here. 'c' is the output console } // main method public static void readtheline () { // c.println ("Please enter an equation in the form of Ax + By + C"); // String equation = c.readLine (); // int length = equation.getLength; // char[] bob = equation.toCharArray (); // for (int x = 0 ; x <= length ; x++) // { // if (bob [x] == 'x') // { // for (int y = 0 ; y <= x ; y++) // { // // } // } // } } public static void intersect () { } public static void graph () { } //============================================================================================ public static void reader () { c.clear (); c.print ("A: "); int a = c.readInt (); c.print ("B: "); int b = c.readInt (); c.print ("C: "); int d = c.readInt (); Line line = new Line (a, b, d); c.println ("The equation is: " + line); // overwrite the toString method boolean answer = line.slope1 (); if (answer == true) { c.print ("The slope is "); c.println (line.slope (), 4, 4); if (line.slope () == 0) c.println ("There is no x-intercept"); else c.println ("The x-intercept is " + line.xint ()); c.println ("The y-intercept is " + line.yint ()); } else if (answer == false) { c.println ("The slope does not exist for this line"); c.println ("The y-intercept does not exist"); c.println ("The x-intercept is " + line.xint ()); } } // main method } //============================================================================================================= class Line { private int A, B, C; public Line (int a, int b, int c) { A = a; B = b; C = c; } public boolean slope1 () { if (B == 0) return (false); else return (true); } public double slope () { double bob = -A * 1.0 / B; return bob; } public String toString () { return A + "x + " + B + "y + " + C + " = 0"; } public double yint () { return (double) - C / B; } public double xint () { return (double) - C / A; } }