12-assignment-2

12-assignment-2 - CS 106A Handout #12 June 29, 2009...

Info iconThis preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon
Handout #12 CS 106A June 29, 2009 Assignment #2—Simple Java Programs Based on Assignment by Eric Roberts Due: Monday, July 6 at 10:30am SHARP Your job in this assignment is to write programs to solve each of these problems. 1. In high-school algebra, you learned that the standard quadratic equation a x 2 + b x + c = 0 has two solutions given by the formula x = –b ± b 2 – 4ac 2a The first solution is obtained by using + in place of ±; the second is obtained by using – in place of ±. Most of this expression contains simple operators covered in Chapter 3. The one piece that’s missing is taking square roots, which you can do by calling the standard function Math.sqrt . For example, the statement double y = Math.sqrt(x); sets y to the square root of x . Write a ConsoleProgram that accepts values for a , b , and c , as ints and then calculates the two solutions, as doubles . If the quantity under the square root sign is negative, the equation has no real solutions, and your program should display a message to that effect. You may assume that the value for a is nonzero. Your program should be able to duplicate the following sample run:
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
– 2 – 2. Write a ConsoleProgram that reads in a list of integers, one per line, until a sentinel value of 0 (which you should be able to change easily to some other value). When the sentinel is read, your program should display the smallest and largest values in the list, as illustrated in this sample run: Your program should handle the following special cases: If the user enters only one value before the sentinel, the program should report
Background image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 5

12-assignment-2 - CS 106A Handout #12 June 29, 2009...

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online