CSC 1760 Lesson 15: Methods and Random Number Generation - Prof. Charles W. Lillie, Assignments of Computer Science

The tasks for lesson 15 of csc 1760, introduction to programming, focusing on methods and random number generation. Students are required to write a method named printmatrix.java that displays an n-by-n matrix using the given header, and a test program named randomnumbstest.java to input the matrix size and display the generated matrix. Additionally, students must write a program named sincosdisplay.java that uses math.sin and math.cos methods to display sin and cos values for degrees from 0 to 360 with increments of 10 degrees, rounded to keep four digits after the decimal point.

Typology: Assignments

Pre 2010

Uploaded on 08/09/2009

koofers-user-mzf
koofers-user-mzf 🇺🇸

10 documents

1 / 2

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
CSC 1760 Introduction to Programming
Lesson 15: Methods
Due Date: 3/16/2009
1. Textbook: Introduction to Java Programming, Brief Version, Seventh Edition,
Author: Y. Daniel Liang, 2009, Prentice Hall
a. Chapter 5
2. Overview
Demonstrate using methods.
3. Tasks
a. Write a method named printMatrix.java that displays an n-by-n matrix,
using the following header:
public static void printMatrix(int n)
Each element is a random number between 0 and 9.
Write a test program named RandomNumbsTest.java that inputs the
matrix size and displays the matrix. For example, the user might input 3,
and the program will print a 3-by-3 matrix that may look like this:
0 9 4
3 8 0
2 5 8
where the numbers in the matrix are randomly generated using the
Math.random() method.
b. Write a program named SinCosDisplay.java that uses the Math.sin and
Math.cos methods to display sin value and cos value of degrees from 0 to
360 with increments of 10 degrees. Round the values to keep four digits
after the decimal point. (Hint: Math.cos and Math.sin only accept radians
not degrees as parameters.)
Degree Sin Cos
0 0.0 1.0
10 0.1736 0.9848
350 -0.1736 0.9849
360 0.0 1.0
4. Assignments due:
a. printMatrix.java
b. RandomNumbsTest.java
pf2

Partial preview of the text

Download CSC 1760 Lesson 15: Methods and Random Number Generation - Prof. Charles W. Lillie and more Assignments Computer Science in PDF only on Docsity!

CSC 1760 Introduction to Programming

Lesson 15: Methods

Due Date: 3/16/

  1. Textbook: Introduction to Java Programming, Brief Version , Seventh Edition, Author: Y. Daniel Liang, 2009, Prentice Hall a. Chapter 5
  2. Overview Demonstrate using methods.
  3. Tasks a. Write a method named printMatrix.java that displays an n-by-n matrix, using the following header: public static void printMatrix(int n) Each element is a random number between 0 and 9. Write a test program named RandomNumbsTest.java that inputs the matrix size and displays the matrix. For example, the user might input 3, and the program will print a 3-by-3 matrix that may look like this: 0 9 4 3 8 0 2 5 8 where the numbers in the matrix are randomly generated using the Math.random() method. b. Write a program named SinCosDisplay.java that uses the Math.sin and Math.cos methods to display sin value and cos value of degrees from 0 to 360 with increments of 10 degrees. Round the values to keep four digits after the decimal point. (Hint: Math.cos and Math.sin only accept radians not degrees as parameters.) Degree Sin Cos 0 0.0 1. 10 0.1736 0. … 350 -0.1736 0. 360 0.0 1.
  4. Assignments due: a. printMatrix.java b. RandomNumbsTest.java

c. SinCosDisplay.java