Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 6 of 6

Thread: Java Programming Help - thanks ahead of time

  1. #1
    Junior Member
    Join Date
    Sep 2010
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default 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.

     
    // 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;
        }
    }


  2. #2
    Member Darryl.Burke's Avatar
    Join Date
    Mar 2010
    Location
    Madgaon, Goa, India
    Posts
    494
    Thanks
    8
    Thanked 48 Times in 46 Posts

    Default Re: Java Programming Help - thanks ahead of time

    I don't see a question anywhere. Did you have one?

    db

  3. #3
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default 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?

  4. #4
    Junior Member
    Join Date
    Sep 2010
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default 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.
    Last edited by javanerd; September 28th, 2010 at 03:35 PM.

  5. #5
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default 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.

    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?

    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.

    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.

  6. #6
    Member
    Join Date
    Jul 2010
    Location
    Washington, USA
    Posts
    307
    Thanks
    16
    Thanked 43 Times in 39 Posts

    Default Re: Java Programming Help - thanks ahead of time

    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
    Last edited by Brt93yoda; September 28th, 2010 at 04:16 PM.

Similar Threads

  1. java threading execution time question
    By centenial in forum Threads
    Replies: 4
    Last Post: September 8th, 2010, 11:32 PM
  2. Replies: 0
    Last Post: May 11th, 2010, 03:37 AM
  3. Java 3d Programming
    By Nickthecoder in forum Java Theory & Questions
    Replies: 1
    Last Post: May 5th, 2010, 10:48 PM
  4. Please help me with this Java programming
    By simply_stunning79 in forum What's Wrong With My Code?
    Replies: 4
    Last Post: March 12th, 2010, 08:04 AM
  5. Please help me with this Java programming
    By simply_stunning79 in forum What's Wrong With My Code?
    Replies: 5
    Last Post: January 14th, 2010, 06:42 AM