Name: Checked: Preparation: Response time experiment accessing the system clock

Similar documents
Name: Checked: Preparation: Response time experiment accessing the system clock

Lab 6. Name: Checked:

CSC 1051 Algorithms and Data Structures I. Final Examination May 12, Name: KEY. Question Value Score

CSC 1051 Algorithms and Data Structures I. Final Examination May 12, Name

CSC 1051 Algorithms and Data Structures I. Midterm Examination October 11, Name: KEY

Name: Checked: Preparation: Investment Calculator with input and output to text files Submit through Blackboard by 8:00am the morning of Lab.

Lab Activity Plan. John Dalbey CPE /30/2013

Selection and Repetition Revisited

Selection and Repetition Revisited

Selection and Repetition

CSC 1051 Villanova University. CSC 1051 Data Structures and Algorithms I. Course website:

Control flow, conditionals, boolean expressions, block statements, nested statements. Course website:

Selection and Repetition

St. Edmund Preparatory High School Brooklyn, NY

Improved algorithm. Java code. Control flow and conditionals CSC 1051 Villanova University. Dr Papalaskari 1. Java Programè Algorithm

Check out how to use the random number generator (introduced in section 4.11 of the text) to get a number between 1 and 6 to create the simulation.

Java code. Updated program. Control flow and conditionals CSC 1051 Villanova University. Dr Papalaskari 1. Java Programè Algorithm. Improved algorithm

CSC 1051 Data Structures and Algorithms I

CSC 1051 Algorithms and Data Structures I. Dr. Mary-Angela Papalaskari Department of Computing Sciences Villanova University

3/18/2015. Chapter 19 Sorting and Searching SELECTION SORT SORTING AN ARRAY OF INTEGERS SORTING AN ARRAY OF INTEGERS FILE SELECTIONSORTER.

CSC 1051 Algorithms and Data Structures I. Dr. Mary-Angela Papalaskari Department of Computing Sciences Villanova University

Loops. CSE 114, Computer Science 1 Stony Brook University

Due Date: Two Program Demonstrations (Testing and Debugging): End of Lab

Wentworth Institute of Technology. Engineering & Technology WIT COMP1000. Simple Control Flow: if-else statements

Java I/O and Control Structures Algorithms in everyday life

CSIS 10A Assignment 4 SOLUTIONS

Wentworth Institute of Technology. Engineering & Technology WIT COMP1000. Java Basics

CSC 1051 Data Structures and Algorithms I

AP Computer Science Final Project - Indexing and the Word-Location Trick Indexing Algorithms

Java I/O and Control Structures

Anatomy of a Java Program: Comments

while (/* array size less than 1*/){ System.out.print("Number of students is invalid. Enter" + "number of students: "); /* read array size again */

CS 152: Data Structures with Java Hello World with the IntelliJ IDE

Midterm Examination (MTA)

Exam 2. Programming I (CPCS 202) Instructor: M. G. Abbas Malik. Total Marks: 40 Obtained Marks:

AP Computer Science Unit 1. Programs

Introduction to Computer Science Unit 2. Exercises

There are several files including the start of a unit test and the method stubs in MindNumber.java. Here is a preview of what you will do:

2.2 - Making Decisions

private static final char[] Alphabet = "abcdefghijklmnopqrstuvwxyz".tochararray();

Introduction to Computer Programming

CSC 1051 Data Structures and Algorithms I

Question: Total Points: Score:

Web-CAT submission URL: CAT.woa/wa/assignments/eclipse

Name: Checked: Access the Java API at the link above. Why is it abbreviated to Java SE (what does the SE stand for)?

Oct Decision Structures cont d

Algorithms and Conditionals

Mr. Monroe s Guide to Mastering Java Syntax

Chapter 3: Classes and Objects. CSC2010 Lab 9. Java Programming. Copyright 2000 W. W. Norton & Company. All rights reserved. FROM THE BEGINNING

Loops. Eng. Mohammed Abdualal. Islamic University of Gaza. Faculty of Engineering. Computer Engineering Department

Lab 5. Name: Checked: Part A. Focus on Strings

CSC 1051 Algorithms and Data Structures I. Midterm Examination February 24, Name: KEY 1

CAT.woa/wa/assignments/eclipse

! definite loop: A loop that executes a known number of times. " The for loops we have seen so far are definite loops. ! We often use language like

Topic 11 Scanner object, conditional execution

CSE142 Sample Midterm, Winter 2018

AP COMPUTER SCIENCE A

Lesson 10: Quiz #1 and Getting User Input (W03D2)

C Sc 227 Project 1: Three Main Methods

CSE 142 Sample Midterm Exam #3

Example Program. public class ComputeArea {

CS 231 Data Structures and Algorithms Fall Event Based Programming Lecture 06 - September 17, Prof. Zadia Codabux

CCHS Math Recursion Worksheets M Heinen CS-A 12/5/2013. Recursion Worksheets Plus Page 1 of 6

Java Classes: Random, Character A C S L E C T U R E 6

CSE115 / CSE503 Introduction to Computer Science I Dr. Carl Alphonce 343 Davis Hall Office hours:

Fundamentals of Programming Data Types & Methods

Bjarne Stroustrup. creator of C++

CMSC 150 INTRODUCTION TO COMPUTING LAB WEEK 3 STANDARD IO FORMATTING OUTPUT SCANNER REDIRECTING

M105: Introduction to Programming with Java Midterm Examination (MTA) Makeup Spring 2013 / 2014

Lab1 Solution. Lab2 Solution. MathTrick.java. CoinFlip.java

Arrays. Eng. Mohammed Abdualal

Over and Over Again GEEN163

Course overview: Introduction to programming concepts

Garfield AP CS. User Input, If/Else. Most slides from Building Java Programs. Thanks, Stuart Regesand Marty Stepp!

Introduction to Computer Programming

Building Java Programs

1. An operation in which an overall value is computed incrementally, often using a loop.

Building Java Programs

Topic 11 Scanner object, conditional execution

AL GHURAIR UNIVERSITY College of Computing. Objectives: Examples: Text-printing program. CSC 209 JAVA I

Entry Point of Execution: the main Method. Elementary Programming. Learning Outcomes. Development Process

COMP6700/2140 Std. Lib., I/O

Welcome to the Using Objects lab!

JAVA PROGRAMMING (340)

Welcome to the Primitives and Expressions Lab!

Controls Structure for Repetition

Building Java Programs

Assignment 8B SOLUTIONS

JAVA PROGRAMMING LAB. ABSTRACT In this Lab you will learn to write programs for executing statements repeatedly using a while, do while and for loop

CSE 1223: Introduction to Computer Programming in Java Chapter 7 File I/O

CP122 Computer Science I. Chapter 2: Data Types, Variables, and I/O

Building Java Programs

COMP1406 Tutorial 1. Objectives: Getting Started:

COSC 236 Section 101 Computer Science 1 -- Prof. Michael A. Soderstrand

Introduction to Computer Science Unit 2. Notes

Darrell Bethea May 10, MTWRF 9:45-11:15 AM Sitterson 011

CS 101 Spring 2007 Midterm 2 Name: ID:

Section 003 Fall CS 170 Exam 1. Name (print): Instructions:

CS61BL. Lecture 1: Welcome to CS61BL! Intro to Java and OOP Testing Error-handling

CSE 1223: Introduction to Computer Programming in Java Chapter 1 Computer Basics

Transcription:

Lab 9 Name: Checked: Objectives: Practice using the conditional operator; switch statements; do and for loops. Explore the use of dialog boxes (JOptionPane) and learn how to implement a simple experimental setup to measure response times using System.currentTimeMillis() (current system time in milliseconds). Preparation: Response time experiment accessing the system clock 1. Download and run ResponseTimeExperiment.java. (shown on next page). 2. Run the program a few times to observe its function. Note the use of System.currentTimeMillis() to find the current time at two different points during the run, and thus obtain the amount of time elapsed between issuing of a question and the input (answer) from the user. 3. Refer to the code shown on the next page. Modify the code enclosed in the boxes, as follows: Using the conditional operator, compute the value of outcome in just one line of code (replace the if/else). Display the result ( Correct! or Incorrect. ) using a single System.out.println statement (again, use the conditional operator). 4. Test your program to ensure that it functions exactly as before. 5. Upload and submit ResponseTimeExperiment.java through blackboard under Lab 9 Prep.

// ResponseTimeExperiment.java // Measure response time for addition problems. // M A Papalaskari import java.util.scanner; import java.util.random; public class ResponseTimeExperiment { public static void main(string[] args) { Scanner in = new Scanner(System.in); Random rand = new Random(); System.out.print("Please enter your name: "); String name = in.nextline(); System.out.println("Hello " + name + ". Please answer as fast as you can." + "\n\nhit <ENTER> when ready for the question."); in.nextline(); // wait for user to hit <ENTER> int a = rand.nextint(100); int b = rand.nextint(100); long starttime = System.currentTimeMillis(); System.out.print(a + " + " + b + " = "); String response = in.nextline(); int number = Integer.parseInt(response); long endtime = System.currentTimeMillis(); int outcome; if (number == a + b) outcome = 1; else outcome = 0; long reactiontime = endtime - starttime; if (outcome == 1) System.out.println("Correct!"); else System.out.println("Incorrect."); } System.out.println("That took " + reactiontime + " milliseconds"); System.out.println("Thank you " + name + ", goodbye."); }

Part A: switch statement Write a program to input a number n that symbolizes a version of the Mac OS X 10.n software. Output the name of that version of the Mac OS X 10.n software. For example, if the user inputs 8, then the program should output Mountain Lion. [You will need to do a little googling to find the names of the different mac software. They run from 1-10 and most of them are cats, but more recently they are joined by mountains.] Part B. Dialog boxes and do loops Run EvenOdd.java and get familiar with how it works. Modify it so that it performs the function of the GPA calculator (from Lab 4b version that asks each time whether to repeat). You will need to modify the prompts and other interaction (for example, "Enter quality points: " instead of "Enter an integer: " ) and to input an additional number for the credits. Part C. for-loops 1. Examine the code of ResponseTimeExperiment.java printed on the previous page and annotate the code with the number to match each step in the algorithm: Algorithm: 1. input name 2. print personalized welcome message & instructions 3. a = random int 4. b = random int 5. starttime = current time 6. print question using a, b 7. input answer 8. endtime = current time 9. outcome = 1 or 0 (answer is correct or incorrect) 10. reactiontime = endtime starttime 11. print outcome as Correct or Incorrect 12. print goodbye

2. We will now modify the ResponseTimeExperiment to repeat the experiment four times, computing the number of correct answers and the average response time of the user, and printing these results at the end. See the algorithm below some steps have been added (highlighted below). Algorithm: 1. input name 2. print personalized welcome message & instructions A. numcorrect = 0 B. totaltime = 0 C. repeat 4 times: 3. a = random int 4. b = random int 5. starttime = current time 6. print question using a, b 7. input answer 8. endtime = current time 9. outcome = 1 or 0 (answer is correct or incorrect) 10. reactiontime = endtime starttime 11. print outcome as Correct or Incorrect D. numcorrect = numcorrect + outcome E. totaltime = totaltime + reactiontime F. averagetime = totaltime/4 G. print averagetime 12. print goodbye Annotate the code with the new steps to prepare to implement the algorithm. Be sure to mark clearly, with the appropriate letter, the exact position where code must be added. 3. Add some code and restructure ResponseTimeExperiment.java to implement the new steps, using your notes from 2, above. Be sure to use a for-loop to implement the repetition of the experiment. Part D. Dialog boxes, revisited Convert the program from part A or part C to use dialog boxes for input/output.

Lab 9 Comments Name: Checked: Comments on this lab, please: What was the most valuable thing you learned in this lab? What did you like best about this lab? Was there any particular problem? Do you have any suggestions for improving this lab as an effective learning experience?