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 8 of 8

Thread: please help

  1. #1
    Junior Member
    Join Date
    Nov 2013
    Posts
    4
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default please help

    In an orthogonal system, given a point, a line from that point to the origin forms an angle with the positive x-axis. The line is said to terminate, either in one of the four quadrants or to coincide with the positive x-axis, positive y-axis, negative x-axis, or negative y-axis.

    Write a java program that prompts the user for a given angle and determines the location of the line, whether it is in one of the four quadrants or it lies on the positive x-axis, positive y-axis, negative x-axis or negative y-axis. For example, if the input angle is 90°, then the line lies on the positive y-axis. If the angle is -30°, then the line lies in the fourth quadrant and so forth. Your program must be able to handle angles of any values, such as -783.87.

  2. #2
    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: please help

    If you don't understand my answer, don't ignore it, ask a question.

  3. #3
    Junior Member
    Join Date
    Nov 2013
    Posts
    4
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: please help

    Quote Originally Posted by Norm View Post

    i am still a beginner in java
    i cant think of a way to begin
    scanner scan= new scanner (system.in);
    i am visualizing the code
    but i cant write it
    i need to figure out a way to to put in if the multiples of (0,90 180 and 360)
    we can use switch but i dont know how
    thank u

  4. #4
    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: please help

    i am visualizing the code
    Use a piece of paper to write down your raw thoughts about how to solve the problem. Then refine the thoughts into a design. When you have a design, the start writing the code. Code and test the code in small steps. Use println statements to print out results to check if the code is doing what you want.
    If you get errors, copy the full text and paste it here.
    If you don't understand my answer, don't ignore it, ask a question.

  5. The Following User Says Thank You to Norm For This Useful Post:

    Joud Mahayni (November 4th, 2013)

  6. #5
    Junior Member
    Join Date
    Nov 2013
    Posts
    4
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: please help

    import java.util.Scanner;
    public class Angle
    {
    public static void main(String []args)
    {
    double a;
    Scanner scan=new Scanner (System.in);
    system.out.println("Enter the value for an angle");
    a=scan.nextDouble();
    if(a>0 && a<90)
    system.out.println("The line is located in quadrant 1")
    else
    if (a==0)
    System.out.println("The line is located on positive x-axis")
    .
    .
    .
    .
    .
    .
    .
    .
    .
    If i continue in this manner i will finish in a couple of years
    how can i condense my code

  7. #6
    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: please help

    how can i condense my code
    I don't see where the code could be condensed.
    What happens when you compile and execute the code?
    If there are error messages, copy the full text and paste it here.

    Please edit your post and wrap your code with code tags:
    [code=java]
    YOUR CODE HERE
    [/code]
    to get highlighting and preserve formatting.
    If you don't understand my answer, don't ignore it, ask a question.

  8. #7
    Junior Member
    Join Date
    Nov 2013
    Posts
    4
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: please help

    import java.util.Scanner;
    public class Angle {

    /**
    * @param args the command line arguments
    */
    public static void main(String[] args) {
    double a;
    Scanner scan=new Scanner (System.in);
    System.out.println("Enter a value for an angle");
    a=scan.nextDouble();
    if (a>0 && a<90)
    System.out.println("The line is located in Quardrant I");
    else
    if (a>90 && a<180)
    System.out.println("The line os located in Quadrant II");
    else
    if (a>180 && a<270)
    System.out.println("The line is located in Quadrant III");
    else
    if (a>270 && a<360)
    System.out.println("The line is located in Quadrant IV");

    else
    if (a==0)
    System.out.println("The line lies on the positive x-axis");
    else
    if (a==90)
    System.out.println("The line lies on the positive y-axis");
    else
    if (a==180)
    System.out.println("The line lies on the negative x-axis");
    else
    if (a==270)
    System.out.println("The line lies on the negative y-axis");




    how can i put in the negative value....
    ALMOST DONE

  9. #8
    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: please help

    Please edit your post and wrap your code with code tags:
    [code=java]
    YOUR CODE HERE
    [/code]
    to get highlighting and preserve formatting.

    how can i put in the negative value
    Whats when you input a negative value?
    If you don't understand my answer, don't ignore it, ask a question.