Computer Science 261

Programming Assignment #1

Due: Monday, Sept. 16

Purpose: The purpose of this assignment is to


  1. Please write a program, called quad.java, which accepts three real (double) numbers from the user (call them A, B, and C for now) and which then calculates and prints the solution(s) to the quadratic equation A*x^2 + B*x + C = 0 according to the following rules:
    • If A = B = 0 then there is no solution, else
    • If A = 0 then the solution is x = -C/B
    • Otherwise, calculate D = B^2 - 4*A*C
      • If D < 0 there are no (real) solutions
      • If D = 0 the solution is x = -B/(2*A)
      • Else there are two solutions: x = (-B+sqrt(D))/(2*A) and x = (-B-sqrt(D))/(2*A)
  1. Write a second program, called Fibonacci.java, which accepts an integer N and then calculates the Nth Fibonacci number three ways
    • By using a loop without any functions or arrays
    • By using an array
    • By using a recursive function.

We will discuss the details of submitting programs Monday.


Some notes:

Any questions/problems? Please ask!