Object Oriented Programming I - Study Guide | CMSC 131, Study notes of Computer Science

Material Type: Notes; Class: OBJECT-ORIENTED PROG I; Subject: Computer Science; University: University of Maryland; Term: Unknown 1989;

Typology: Study notes

Pre 2010

Uploaded on 02/13/2009

koofers-user-46r
koofers-user-46r 🇺🇸

10 documents

1 / 2

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
CMSC 131 Spring 2005 Quiz 1 Worksheet
The first Quiz of the course will be on Wednesday Feb 2 during your lab (discussion)
session.. The following bullet list provides more information about the quiz:
You will have 15 minutes to complete the quiz.
It will be a written quiz (not using any computer).
It will be a closed book, closed notebook, no calculator quiz.
You should be able to write a complete Java class.
You must use a pencil to complete the quiz
The quiz will be based on the exercises you will find below. Iteration statements
(do whiles/whiles) will not be part of the quiz.
The following exercises cover the material you are expected to be familiar for Quiz #1,
Solutions to these exercises will not be provided but you are welcome to discuss your
solutions with TAs and instructors during office hours.
1. From Lewis & Loftus
a. Page 56 (“programming projects section”): 1.1, 1.3
b. Page 120 (“exercises”): 2.2, 2.6 (a, b, c, d, e, f, g, n, o, p, q)
c. Page 123 (“programming projects”): 2.2, 2.3, 2.5, 2.11
2. Write a Java program that computes the letter grade associated with student based
on a numeric grade value. The program will read the numeric grade of the student
and will compute a letter grade using the following cutoff values:
Letter Grade Cutoff
A 90.0
B 80.0
C 70.0
D 60.0
Any student with a numeric grade value lower than 60.0 will have F as letter
grade.
3. Note: This problem was last semester’s quiz. The solution has been provided at
the end.
Write a Java program that prompts the user for two values, computes the average
of the values and generates a message based on the computed average. The
message “Satisfactory” will be output if the average is greater or equal to 70.0 and
“Unsatisfactory” otherwise. The following restrictions/assumptions apply to this
problem:
pf2

Partial preview of the text

Download Object Oriented Programming I - Study Guide | CMSC 131 and more Study notes Computer Science in PDF only on Docsity!

CMSC 131 Spring 2005 Quiz 1 Worksheet

The first Quiz of the course will be on Wednesday Feb 2 during your lab (discussion) session.. The following bullet list provides more information about the quiz:

  • You will have 15 minutes to complete the quiz.
  • It will be a written quiz (not using any computer).
  • It will be a closed book, closed notebook, no calculator quiz.
  • You should be able to write a complete Java class.
  • You must use a pencil to complete the quiz
  • The quiz will be based on the exercises you will find below. Iteration statements (do whiles/whiles) will not be part of the quiz.

The following exercises cover the material you are expected to be familiar for Quiz #1, Solutions to these exercises will not be provided but you are welcome to discuss your solutions with TAs and instructors during office hours.

1. From Lewis & Loftus a. Page 56 (“programming projects section”): 1.1, 1. b. Page 120 (“exercises”): 2.2, 2.6 (a, b, c, d, e, f, g, n, o, p, q) c. Page 123 (“programming projects”): 2.2, 2.3, 2.5, 2. 2. Write a Java program that computes the letter grade associated with student based on a numeric grade value. The program will read the numeric grade of the student and will compute a letter grade using the following cutoff values:

Letter Grade Cutoff

A 90.

B 80.

C 70.

D 60.

Any student with a numeric grade value lower than 60.0 will have F as letter grade.

3. Note: This problem was last semester’s quiz. The solution has been provided at the end.

Write a Java program that prompts the user for two values, computes the average of the values and generates a message based on the computed average. The message “Satisfactory” will be output if the average is greater or equal to 70.0 and “Unsatisfactory” otherwise. The following restrictions/assumptions apply to this problem:

  • The name of the class you will define is ComputeStatus.
  • The input values are floating point values. You may use any of the Java floating point types.
  • Input and output operations must be completed using methods associated with JOptionPane.
  • You do not need to provide comments, however, you must use meaningful variable names and good indentation.
  • You must write any necessary import statements.
  • Write the program on the next page.

Problem 3 Solution

import javax.swing.*; public class ComputeStatus {

public static void main(String[] args) { String strVal1 = JOptionPane.showInputDialog("Enter Value"); String strVal2 = JOptionPane.showInputDialog("Enter Value"); double val1 = Double.parseDouble(strVal1); double val2 = Double.parseDouble(strVal2); double avg = (val1 + val2)/2;

String message = "Satisfactory"; if (avg < 70.0) { message = "Unsatisfactory"; }

JOptionPane.showMessageDialog(null, message); System.exit(0); } }