- User input includes typing on the keyboard, clicking of a mouse, tapping or swiping a touch screen device, etc.



Similar documents
ios 9 Accessibility Switch Control - The Missing User Guide Updated 09/15/15

Workshop Tool in Moodle

Microsoft PowerPoint Exercises 4

LMS User Manual LMS Grade Book NUST LMS

Updating to Windows 8.1

Before you can use the Duke Ambient environment to start working on your projects or

User Guide for Windows 10

Task Card #2 SMART Board: Notebook

Step-by-Step Guide Procurement Card & Travel Reconciliation Expense Reports: Step 4c Attaching Documents by Receipt Store to Individual Expenses

KEYBOARD SHORTCUTS. Note: Keyboard shortcuts may be different for the same icon depending upon the SAP screen you are in.

Frequently Asked Questions for logging in to Online Banking

Statgraphics Getting started

Using Your Polyvision Digital Whiteboard and Walk-and-Talk

Auto Clicker Tutorial

Acrobat X Pro Accessible Forms and Interactive Documents

How to test and debug an ASP.NET application

Keyboard Shortcuts Instead of the Mouse NOTES

July 29, 2010 Revision 5

Setting up RDP on your ipad

New To Blackboard: Faculty Edition

EXCEED IEP Goals Product Screen

Getting Started Using AudibleManager. AudibleManager 5.0

Windows 8.1 Update 1 Supplement

Windows XP Pro: Basics 1

Lecture 2 Mathcad Basics

Greetings Keyboard Mastery Keyboarding Students! Teacher: Mrs. Wright

Medical Aid Remittance

Optimal Browser Settings for Internet Explorer Running on Microsoft Windows

Matterport Workshop 2.0. User Guide

Microsoft Office 2013

CATIA Basic Concepts TABLE OF CONTENTS

Inking in MS Office 2013

L OCUTOUR. Get Ready to Spell! MULTIMEDIA COGNITIVE REHABILITATION

5. Tutorial. Starting FlashCut CNC

SMART Sympodium and Notebook Software 9.5

Using WINK to create custom animated tutorials

For Introduction to Java Programming, 5E By Y. Daniel Liang

GETTING STARTED TABLE OF CONTENTS

Introduction to Eclipse

Fleet Maintenance Software

Mikogo User Guide Linux Version

SnagIt Add-Ins User Guide

Windows 7 for beginners

Sendspace Wizard Desktop Tool Step-By-Step Guide

Millennium Learning Centres How to scan documents you want to edit

FAQ for Transformer TF201

Banner Frequently Asked Questions (FAQs)

Getting Started on the Computer With Mouseaerobics! Windows XP

To Begin Customize Office

Adding emphasis to a presentation in PowerPoint 2010 and 2013 for Windows

SMART Notebook: Basics and Application

Instructions for using VPN and accessing your files remotely

Getting Started with Amazon EC2 Management in Eclipse

paragraph(s). The bottom mark is for all following lines in that paragraph. The rectangle below the marks moves both marks at the same time.

QuickStore Mobile Counting

CHRIS User Guide: Dated Information and Date Tracking

Organizing image files in Lightroom part 2

LogMeIn Ignition for Android User Guide

SMART board 101. SMART board 101 Training

1. Application Overview System Requirements Installation Splash Screen Registration Screen...

FREQUENTLY ASKED QUESTIONS

Instructions for the Epson Perfection 1670 Scanner

USER MANUAL (PRO-CURO LITE, PRO & ENT) [SUPPLIED FOR VERSION 3]

Section 5 Icons and Shortcuts

Contents. I. General Information...3. III. Pen Storage and Maintenance...9 IV. Question & Answer...10

The Richard Pate School. Draft Year 4 Scheme of Work for Scratch

Quick Start Guide. DVR DS-7200HWI-SH Series DVR. First Choice For Security Professionals

Kiva Technology User s Manual

USEFUL HINTS & TIPS ALCATEL ONE TOUCH 993. better BUSINESS

Summitsoft Corporation Font Management System Guide

Sticky Password User Manual Sticky Password

Bank Reconciliation: Improvements for the Shelby v5 Spring 2006 Release

Mailing lists process, creation and approval. Mailing lists process, creation and approval

WebEx Sharing Resources

The SMART Board Interactive Whiteboard

IT Quick Reference Guides Using Windows 7

MC Talent Management System. Goals Module Guidebook

Microsoft Migrating to PowerPoint 2010 from PowerPoint 2003

The very basic basics of PowerPoint XP

TRL Nook Simple Touch User guide

How to Create a Resume Using Microsoft Word

Basics of Working with TurningPoint in Office 2003

Lenovo Miix 2 8. User Guide. Read the safety notices and important tips in the included manuals before using your computer.

Home Agent Installation Manual Windows 8 v1.0

Access Tutorial 1 Creating a Database

Xerox WorkCentre 6655 Color Multifunction Printer Control Panel

Passport Installation. Windows 8 + Internet Explorer 10

Internet Explorer Settings for Optum CareTracker

AT&T U-verse App for iphone FAQ s

Maple T.A. Beginner's Guide for Instructors

So you want to create an a Friend action

Advantage Cloud Access: Microsoft Remote Desktop for Android

PC Troubleshooting Steps

GOALS: The goal for this session is: OBJECTIVES: By the end of the lesson participants should be able to: MATERIALS: Instructor ACTVITIES: EVALUATION:

iphone Application User Guide

How to Use the H-ITT Analyzer Version 2.4.4

CREATE AN ANIMATED AQUARIUM IN POWERPOINT

Autodesk Installation

Transcription:

Java User Input

WHAT IS USER INPUT? - Collecting and acting on user input is important in many types of programs or applications. - User input includes typing on the keyboard, clicking of a mouse, tapping or swiping a touch screen device, etc. - After the user input event, your program must react to that event in some way.

JAVA SCANNER CLASS - In the following examples, we will be using the java.util.scanner class to handle keyboard input. - We will be retrieving values from the keyboard and storing those values in variables for future use.

GRADEBOOK PROGRAM NEW FEATURES We will be adding the following new features to the Gradebook program we started previously. - Build a loop and menu system to start and exit the program. - Allow a user to enter in a defined number of grades and have the program automatically calculate the grade percentage and letter grade.

1 2 GRADEBOOK PROJECT PART 2 - Now it is time to follow along with the code samples in the upcoming slides. - Open the previously created Gradebook.java file. - Import the java.util.scanner class to the gradebook.

GRADEBOOK PROJECT PART 2 (CONTINUED) - Create an instance of the Scanner class in order to collect the user keyboard input. This can go in the main method directly underneath the grades List. 3

GRADEBOOK PROJECT PART 2 (CONTINUED) - The entire Gradebook program is now going to be set up to be controlled by a loop. In this program we will use a while loop. - Many different types of applications and games are controlled by a loop. The program will continue running until a user event shuts it down. This could include clicking the exit button on an application, losing in a game, etc.

- Select the initial grade list that you created in the previous lesson and DELETE it. 4 GRADEBOOK PROJECT PART 2 (CONTINUED) - Yes, I said to delete it. We will be replacing this code with some different coding next.

- Add the code found on the next slide inside the main method below the Scanner input = new Scanner(System.in); statement. 5 GRADEBOOK PROJECT PART 2 (CONTINUED) - Now lets create the basic menu loop. This code is slightly more complicated than what we have worked with so far. However, we will walk through it step by step.

GRADEBOOK PROJECT PART 2 (CONTINUED)

GRADEBOOK PROJECT PART 2 (CONTINUED) - When you run the program, you will need to click down in the console output to enter in a number. After entering a number, press the enter key to send the number back to your program. - The program will run until you enter a 2. Here is an example of what the output of the program would look like until you enter a 2:

GRADEBOOK PROJECT PART 2 (CONTINUED) - As we learned previously, both an if statement and while loop are control structures. - These control structures can be placed inside of each other as seen in the previous example. - When a control structure is placed inside another, this is called nesting. - It is possible to nest multiple different types of control structures inside another and is a very important concept in programming.

GRADEBOOK PROJECT PART 2 (CONTINUED) - Inside the menuselection if statement we collect some additional user input. Add the following statements to the menuselection if statement: 6

GRADEBOOK PROJECT PART 2 (CONTINUED) - Continued adding the following code to the menuselection if statement: 7

- Run the program and input some grades. The console output will be similiar to the screenshot below. 8 GRADEBOOK PROJECT PART 2 (CONTINUED) - Did you notice anything wrong with this? - Hopefully you noticed that the total possible is incorrect. Which results in an incorrect letter grade. - Why is it 300 instead of 45 like it should be?

GRADEBOOK PROJECT PART 2 (CONTINUED) - The total possible is 300 because we set the initial variable of totalpossible to grades.size() * 100; 9 - To fix this error we need to replace the 100 with the maxgradescore statement. Replace 100 with maxgradescore.

GRADEBOOK PROJECT PART 2 (CONTINUED) - Here is what a portion of the program look like. - Did you run the program? If you did, you got an error message.

- Lets fix the error so we can run the program with no issues. 10 GRADEBOOK PROJECT PART 2 (CONTINUED) - Select the two curley brackets that are above the variables and move them both below your print statements.

GRADEBOOK PROJECT PART 2 (CONTINUED) - Now that you have moved the curley brackets, run the program and input some grades. 11

DEBUGGING - In a past lesson, we introduced the idea of debugging. Eclipse has a built in debugging tool that makes it easy to walk through your program step by step. - This is also useful for trying to understand how a program works. - When using the Eclipse debugger, you can see the values of your variables when each line of code is running.

DEBUGGING (CONTINUED) - The first step in debugging is to set a breakpoint. - A breakpoint is simply a place that your program will stop executing and turn control over to the Eclipse debugger. 12 Right click here and select "Toggle Breakpoint" You will see an icon to indicate a breakpoint has been set.

DEBUGGING (CONTINUED) - Eclipse comes with different views, that are called perspectives. Perspectives make it easier to do specific tasks. - In the top right corner of Eclipse there are links to switch back and forth between the Debug perspective and the Java perspective. - If you try to run debug mode in the Java perspective, it will provide you with a message asking if you want to switch.

- The next step is to go to the Eclipse menu and click Run > Debug (or use the F11 shortcut key) 13 DEBUGGING (CONTINUED) - If you were not on the Debug perspective, click "Yes". - You will notice that this perspective is split into a bunch of panels with different information. We will walk through the important ones now.

DEBUGGING (CONTINUED) - The top left panel is the Debug panel. This contains information about the Java classes and which method you are currently in. Currently in the main method

DEBUGGING (CONTINUED) - The variables panel allows you to track the value of each variable based on where you are at in the code. Variables show up here Variable values show up here

DEBUGGING (CONTINUED) - The outline panel simply gives you an outline of the methods within the class. In this case it shows the main and lettergrade methods that are inside the Gradebook class.

DEBUGGING (CONTINUED) - The panel on the left center of the Debug perspective contains the code that is currently running. It will display which line of code the program is currently on. It will also show you the breakpoints that you have set. Currently on this line of code

DEBUGGING (CONTINUED) - The console panel allows you to see the output of your program. This is the same as the console panel in the main Java perspective. You will be able to enter your input values into this panel when you are debugging your code. Output and input values are handled here. You can stop the program by clicking the red stop button

DEBUGGING (CONTINUED) - The debugging tool allows you to step through the code, line by line. You can use the icons near the top of the screen to control the execution of the program. Stop the currently running program Continue to the next breakpoint (or end of code if no other breakpoints exist) Used to step inside of a method. This can be used on the lettergrade call to move into that method. Used to step out of the current method. This can be used within the lettergrade method to step back out to the main method. Used to execute and step over the current line of code

DEBUGGING (CONTINUED) - This was the most complicated program you have written so far. Now it is time for you to use your newly learned debugging skills to walk through the program step by step and see exactly how it works. - Make sure to examine the variables at each step to see how things are getting processed. - Spend a lot of time getting used to the debugging tool, it will make programming much easier for you. - After working with the debugging tool, you will notice that although programming can be complex, there is no magic involved. The computer only performs the specific instructions you tell it to.

PRINTING 14 - Print the Gradebook.java file and turn in