Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Quadratic perplextion  RSS feed

 
Sammi Groover
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi again from the most programming challenged person in the world... I really appreciated al your help before. I had hoped to not need to ask for help again,yet here I am, asking for help, and saying THANKS! for before and inadvance for help here too =]

I have a question which I cannot even understand no matter how many times I read it; I am worse at one thing than JAVA, and that is Algebra.... I am posting the problem, and then the code I have for it so far. It did complie, once, and but when I tried to execute it gave me the "Exception in thread "main" java.lang.NoClassDefFoundError: QuadraticB
Press any key to continue...." error.

Anyhow, the problem:
Problem B: Write a Java class (call it Quadratic) that contains private instance variables for each of the 3 coefficients (a, b, c) and private instance variables for the two roots of a quadratic equation. Include the following instance methods: (each MUST refer directly to one or more instance variables)

�Default constructor with no parameters for the coefficients, which will assign 0 to coefficients instance variables.

�Constructor with 3 double parameters for the coefficients, which will assign the parameters to the coefficients instance variables. Call the method to calculate the roots here.

�Constructor with 2 double parameters (for a & b only, assigning c to 0), calling the previous constructor with the parameters for a & b, and 0 for c.

�Private instance (not static) method which will calculate and assign to both root instance variables a root. This will be called from each constructor and mutator/modifier method. The roots calculations are on the next page.

�accessor methods, one for each instance variable and roots.

�mutator method to change all three coefficients (a, b or c) ONLY in one method (call roots method here, too)

�a Boolean method called isQuadratic that returns (in a return statement) true if "a" isn't 0 (is a quadratic) or false if "a" is 0

�a Boolean method called isImaginary that returns (in a return statement) true if (b2-4ac) is negative or false otherwise

�Display method that displays the name of the class, each variable name (all 3 coefficients and 2 roots) and their values

Formulas for the roots (you convert to Java expressions):
(-b + squareroot(b2-4ac)) / 2a
(-b - squareroot(b2-4ac)) / 2a

Write a Java application program in which main is in a separate file and class from the Quadratic class. Have the program declare a Quadratic object variable and assign to an instance of a Quadratic object with the 2., 5. (nothing for c) passed from main. Call the display method for that object.

**Prompt & input from the user 3 coefficients and change the object var. using it's mutator method. In main, call the isQuadratic method on the Quadratic object and print "Not a quadratic" if it returns false, but if it returns true, call the isImaginary method on the Quadratic object and print "Imaginary Roots" if it's true, otherwise print ONLY the two roots (in main, call the accessors for the roots).

Prompt the user and input if the user wants to continue. Read the answer into a String, and repeat from ** if the first char. of the answer is 'y' or 'Y'.

8. 3. 4.//Output from toString or display (for a, b, c)
Yes
0. 1. 2.
Y
-2.5 4. 3.
No
Quitting....
(cut & pasted from instruction, not lying....)

So, my code as I understand him to be asking for in the problem, minus the quadcalc (I know is a mess, but a work in progress....):


Sigh, when you are through laughing and find composure, can you find it in your heart to help?

thanks again
Sammi
 
Giovanni De Stefano
Ranch Hand
Posts: 161
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Sammi,
you are lucky...it's friday night and it's raining...this means I am staying home trying to be helpful!

I assume you wrote the WHOLE instruction, and I also assume you are eager to learn but let me tell you that your approach is WRONG!!! :-)

I used to teach Computer Science at the university in Italy, while I was still a student...so, Let's go step by step...

The first thing to do is READ CAREFULLY the instruction and then FOLLOW THEM STEP BY STEP, point by point...without doing ANYTHING that you are NOT asked to do.

Ready...GO!

1. Write a Java class (call it Quadratic) that contains private instance variables for each of the 3 coefficients (a, b, c) and private instance variables for the two roots of a quadratic equation.


2. Include the following instance methods: (each MUST refer directly to one or more instance variables)
This simply means that you are not supposed to use any other variable BUT the private ones you already declared!

3. Default constructor with no parameters for the coefficients, which will assign 0 to coefficients instance variables.


4. Constructor with 3 double parameters for the coefficients, which will assign the parameters to the coefficients instance variables.


5. Constructor with 2 double parameters (for a & b only, assigning c to 0), calling the previous constructor with the parameters for a & b, and 0 for c.


6. Private instance (not static) method which will calculate and assign to both root instance variables a root.


...
[ May 06, 2005: Message edited by: Giovanni De Stefano ]
 
Giovanni De Stefano
Ranch Hand
Posts: 161
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
7. accessor methods, one for each instance variable and roots. and mutator method to change all three coefficients (a, b or c) ONLY in one method (call roots method here, too) are NOT clear...at least they are not clear to me! Here it is:


...
[ May 06, 2005: Message edited by: Giovanni De Stefano ]
 
Giovanni De Stefano
Ranch Hand
Posts: 161
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
8. a Boolean method called isQuadratic that returns (in a return statement) true if "a" isn't 0 (is a quadratic) or false if "a" is 0 and a Boolean method called isImaginary that returns (in a return statement) true if (b2-4ac) is negative or false otherwise


...
[ May 06, 2005: Message edited by: Giovanni De Stefano ]
 
Giovanni De Stefano
Ranch Hand
Posts: 161
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
9. Display method that displays the name of the class, each variable name (all 3 coefficients and 2 roots) and their values
 
Sammi Groover
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
wow, I was going about it all wrong... thank you so much, I am going to study this for a while.



Thank you very kindly!!! I wish you were our instructor, you explain it all quite comprehensibly

I am still here
 
Giovanni De Stefano
Ranch Hand
Posts: 161
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
...I guess you can continue on your own now!

I hope I have been useful to you with the meaning that I hope you will focus more attention on WHAT THE PROBLEM REQUIRES YOU TO DO...and THEN ON HOW TO SOLVE IT!

Your code is full of mistakes...and unecessary lines...NOT required from the instructions...

By the way...let me know how this goes...you can also send me a private message if I don't answer within an hour.
I am waiting for THE answer for a very good job, in the meantime I am unemployed :-( with a lot of spare time!

I just realized you answered...you are mor than welcome! I enjoyed very much my teaching experience...but now I live in the US...you reminded me some of my students, eager to learn but with poor teacher in the class...don't forget my recomendations...STEP BY STEP...if you are an inexperienced programmer you CANNOT expect to have a generic idea of the WHOLE thing right away...you have to split the requirements in smaller sentences and start from them.
Good luck with your studies...and keep your fingers crossed for me...I REALLY NEED THIS JOB!!!

Giovanni
[ May 06, 2005: Message edited by: Giovanni De Stefano ]
 
Sammi Groover
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you Giovanni!

And yes, I do see my mistake now, I was so overwhelmed with trying to dechiper it all that I lost site of what I needed to do. The way you explained it all, step-by-step was extremely helpful!

I shall rememebr what you said, and e-mail as you requested.

And best of luck in your endeavor; from the outstanding performance you showed in helping me, I would be astounded if the answer your are waiting for is not the one you both hope for and deserve!
 
Giovanni De Stefano
Ranch Hand
Posts: 161
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Glad to help!
I believe in energies...just from your words I felt good energies from you, that's why I decided to write some code for you!
You alre almost done though...just the last part which should be a piece of cake now.
Last hint...READ CAREFULLY and repeat from ** if the first char.
of the answer is 'y' or 'Y'.
...you should use something like if((answer.charAt(0) == 'Y') || (answer.charAt(0) == 'y'))...meditate on every single line I wrote, so my effort will be paid back by you learning things.
I am going to bed now!

Good night from NJ!
Giovanni
 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!