The Artima Developer Community
Sponsored Link

Java Answers Forum
helpppp

6 replies on 1 page. Most recent reply: Nov 17, 2008 2:52 AM by Matthias Neumair

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 6 replies on 1 page
Mike williams

Posts: 3
Nickname: jpnym15
Registered: Nov, 2008

helpppp Posted: Nov 14, 2008 9:28 AM
Reply to this message Reply
Advertisement
I have to create a program which finds the solutions for second degree polynomials. ax^2+bx+c=0

it refers to the quadratic equation...
the description states: The part under the square root symbol (b^2-4ac) is called the discriminant. If this number is zero, the equation has one solution. which is printed by the program. If the discriminant is greater than zero, there are two solutions, and the program prints both. However, if the discriminant is negative, the program can not take the squareroot. The user sees a message saying that the solutions are complex.
This program is supposed to contain 1 value returning method, and also 3 void methods.

Sample Run:
Please enter a:
1
Please enter b:
-3
Please enter c:
-4

The solutions are -1 and -4


Vincent O'Sullivan

Posts: 724
Nickname: vincent
Registered: Nov, 2002

Re: helpppp Posted: Nov 15, 2008 2:06 AM
Reply to this message Reply
I assume that you're aware that, these days, schools and colleges routinely do internet searches, to see if pupils post their homework in the hope that someone else will magically do it for them, which they can then submit in their own name and take the credit for.

Once submitted, homework content is also frequently used as the basis for internet searches, to see if it is a (thinly disguised) copy of something out there.

You might interestded in this extract from a posting relating to a university course I'm involved with:

"It has been brought to our attention that some students are posting queries to online fora, such as experts-exchange, asking for help with their continuous assessment.

Please remember that the work you submit for ... must be your own. Generally speaking, if you submit an assignment that contains work that is not your own, without indicating this in your ... document (i.e. without acknowledging your sources), you are committing plagiarism. In the case of computer code, where appropriate you may re-use your own code or code we have provided. It is wrong, however, to get someone else to provide the code for you or to answer your ... questions. If a case of plagiarism is proven, this is a serious offence and ... disciplinary procedures will be followed."


Now, having said all that, you appear to have submitted a question that you've been asked to answer yourself, but you haven't said what kind of problem you're having answering it. We're very happy to help with specific questions you may have about Java. What's your question?

Mike williams

Posts: 3
Nickname: jpnym15
Registered: Nov, 2008

Re: helpppp Posted: Nov 16, 2008 3:40 AM
Reply to this message Reply
well, I did the program (or tried to) and I'm still having problems... I just don't know what the problem is though.any thoughts?

import java.util.*;

public class Quadratic
{
public static void main(String[] args)
{
Scanner console = new Scanner(System.in);

double a = 1, b = 1, c = 1;
}

public void numA(double a)
{
this.a = a;
}

public void numB(double b)
{
this.b = b;
}

public void numC(double c)
{
this.c = c;
}

public double[] getResult()
{
double[] result = new double[2];
this.numA(readDouble("a"));
System.out.println("Enter the value of a");
scanner.nextDouble();

this.numB(readDouble("b"));
System.out.println("Enter the value of b");
scanner.nextDouble();

this.numC(readDouble("c"));
System.out.println("Enter the value of c");
scanner.nextDouble();

result[0] = (-b+Math.sqrt((b*b)-4*a*c))/2*a);
result[1] = (-b-Math.sqrt((b*b)-4*a*c))/2*a);
return result;
}
}

Vincent O'Sullivan

Posts: 724
Nickname: vincent
Registered: Nov, 2002

Re: helpppp Posted: Nov 17, 2008 2:40 AM
Reply to this message Reply
OK. What happens when you try to compile the code above?

Matthias Neumair

Posts: 660
Nickname: neumi
Registered: Sep, 2003

Re: helpppp Posted: Nov 17, 2008 2:42 AM
Reply to this message Reply
first of all, use the "java" tag and not "code".

2. What problem are you facing (I can see a few)?

NOTE: Please answer before you read on, you need to be able to analyze your problems.

3. You ARE aware you never actually call your "getResult" method?
All you do is assigning 1 to local variables a, b and c which will be visible no where outside the main method.

4. what is "this"? You never actually created a instance of the class. "this" can only work when a instance was created.

feel welcome to post your changed code when you gave these hints a 2nd thought.

Matthias Neumair

Posts: 660
Nickname: neumi
Registered: Sep, 2003

Re: helpppp Posted: Nov 17, 2008 2:49 AM
Reply to this message Reply
note: the use of "this" is actually correct, but the methods need to be called in a instance.

but "this.a" points no where since your class does not contain any variable called "a".

Matthias Neumair

Posts: 660
Nickname: neumi
Registered: Sep, 2003

Re: helpppp Posted: Nov 17, 2008 2:52 AM
Reply to this message Reply
I wish there would be a "edit" button :(
Ignore my previous post, was quite crap.
"this" also works in a static context.

Flat View: This topic has 6 replies on 1 page
Topic: Java Developper Previous Topic   Next Topic Topic: How to implement a JTextArea that shows the messages coming in the console?

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use