Java Programming Help - thanks ahead of time
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.
Code Java:
// 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;
}
}
Re: Java Programming Help - thanks ahead of time
I don't see a question anywhere. Did you have one?
db
Re: Java Programming Help - thanks ahead of time
Can you rewrite you code to use Standard JDK input classes vs using the hsa package?
What happens when a person from typing in a wrong symbol/letter instead of a number?
What does your program do when that happens?
Re: Java Programming Help - thanks ahead of time
Oh, sorry. My question is more of a, i need help type thing. I need help writing the latter programs that i mentioned before, (1. type in an equation like 3y - y + 9 -5x, and it converts the equation into Ax + By + C= 0 form, and also doesnt allow the user as he is typing in the equation, to type invalid characters, so if the user is trying to type in the symbol ? then nothing happens in the program. The cursor keeps blinking but since ? is not allowed, nothing happens, it keeps waiting for me to type a valid character like +, or a number and 2. Create a graph of an equation that the user has typed in.)
um, for the second,
I have only been taught to use the hsa console, i am not sure what you are referring to when you want me to change it into some other format. really sorry.
thanks for your concern in my problem.
Re: Java Programming Help - thanks ahead of time
Many people do not have the classes in the hsa package. Without those classes, the code can't be compiled and tested.
Quote:
type in an equation like 3y - y + 9 -5x, and it converts the equation into Ax + By + C= 0 form
That sounds like a very complicated program that is able to convert one equation to another. I have no idea how to do that.
The design of an algorithm to do that isn't part of java programming. Do you have the algorithm to make that conversion?
Quote:
Create a graph of an equation that the user has typed in.)
Again that sounds more like designing an algorithm than java programming. Once you have a design/algorithm, then you can get help coding that design in java.
Quote:
doesnt allow the user as he is typing in the equation, to type invalid characters
With the JDK console input methods there is NO way to prevent a user from typing in anything he wants. All the program can do is examine it after the user has typed it in and see if it is valid.
Perhaps the classes in the hsa package has methods for doing that. Since I know nothing of the hsa package, I can't help there.
Re: Java Programming Help - thanks ahead of time
Quote:
type in an equation like 3y - y + 9 -5x, and it converts the equation into Ax + By + C= 0 form
Aren't you just trying to convert y=mx+b into slope intercept form. (ax+by+c=0) If you are then here is a link: How can I convert from mx+B form to Ax+By=C Form and what website is a good reference for math questions? - Yahoo! Answers