The 5 th and 6 th tutoring session - A case study about verifying a ISBN - Writing code for problems in HW1 Fall, 2012 Haidong(Haydon) Xue 5:30pm—8:30pm.

Slides:



Advertisements
Similar presentations
Introduction to Programming
Advertisements

Bookseller Guide How to TOP-UP a National Book Token Electronic Gift Card using the Web Recommended solution for booksellers with broadband computer access.
The 3 rd and 4 th tutoring session -- A case study about using variables Fall, 2012 Haidong(Haydon) Xue 5:30pm8:30pm 9/11/2012 and 9/12/2012.
Computing Science Software Design and Development SOFTWARE DESIGN AND DEVELOPMENT USING PYTHON.
Computer Programming Lab(7).
Computer Programming Lab 8.
Bookseller Guide How to REDEEM a National Book Token Electronic Gift Card using the Web Recommended solution for booksellers with broadband computer access.
Today’s topics: I/O (Input/Output). Scribbler Inputs & Outputs  What are the Scribbler’s inputs and outputs?  reset button  motors/wheel  light sensor.
CEN 226: Computer Organization & Assembly Language :CSC 225 (Lec#4)
CSCI S-1 Section 5. Deadlines for Problem Set 3 Part A – Friday, July 10, 17:00 EST Parts B – Tuesday, July 14, 17:00 EST Getting the code examples from.
1 Lab Session-3 CSIT 121 Fall 2004 Section-3 should finish Lab-1 Exercise first Division rules Operator precedence rules Lab Exercise.
1 Interactive Applications (CLI) and Math Interactive Applications Command Line Interfaces The Math Class Example: Solving Quadratic Equations Example:
Moving To Code 3 More on the Problem-Solving Process §The final step in the problem-solving process is to evaluate and modify (if necessary) the program.
1 The First Step Learning objectives write Java programs that display text on the screen. distinguish between the eight built-in scalar types of Java;
Copyright 2008 by Pearson Education Building Java Programs Chapter 3 Lecture 3-3: Interactive Programs w/ Scanner reading: self-check: #16-19.
1 Interactive Applications (CLI) Interactive Applications Command Line Interfaces Project 1: Calculating BMI Example: Factoring the Solution Reading for.
Bookseller Guide How to SELL a National Book Token Electronic Gift Card using the Web Recommended solution for booksellers with broadband computer access.
Using Java's Math & Scanner class. Java's Mathematical functions (methods) (1)
CSc2310 tutoring session, week 8 Fall, 2012 Haidong Xue 5:30pm—8:30pm 10/30/2012 and 10/31/2012 -Code PrintCalendar.
CPS 2231 Computer Organization and Programming Instructor: Tian (Tina) Tian.
The 10 th and 11 th tutoring session Fall, 2012 Haidong Xue 5:30pm—8:30pm 10/9/2012 and 10/10/2012 -What is a class, what is an object and why we need.
CS1101: Programming Methodology Aaron Tan.
Methods (Functions) CSE 1310 – Introduction to Computers and Programming Vassilis Athitsos University of Texas at Arlington 1.
CSc2310 tutoring session, week 7 Fall, 2012 Haidong Xue 5:30pm—8:30pm 10/9/2012 and 10/10/2012 -Using arrays -Case study: PhoneDirectory.
Sam Houston State University's IR Office Organization System.
CSc2010 Lab Fall 2015 Bing Li. Contact  Name : Bing Li   Website : cs.gsu.edu/~bli6  Office : Suntrust.
CSc2310 tutoring session, week 8 Fall, 2012 Haidong Xue 5:30pm—8:30pm 10/23/2012 and 10/24/2012 -Using Exceptions -Homework 4.
CSc2310 tutoring session, week 8 Fall, 2012 Haidong(Haydon) Xue 5:30pm—8:30pm 11/27/2012 and 11/28/2012 -Class Members vs Instance Members.
C++ Functions. Objectives 1. Be able to implement C++ functions 2. Be able to share data among functions 2.
CSc2310 tutoring session, week 8 Fall, 2012 Haidong Xue 5:30pm—8:30pm 11/06/2012 and 11/07/2012 -Test 3 Study Guide.
CSci 111 – computer Science I Fall 2014 Cynthia Zickos WRITING A SIMPLE PROGRAM IN JAVA.
The 1 st and 2 nd tutoring session of CSc2310 Fall, 2012 Haidong Xue.
Welcome to the MTLC MATH 115 Spring MTLC Information  Hours of Operation  Sunday:4:00pm – 10:00pm  Monday – Thursday: 8:00am – 10:00pm  Friday:8:00am.
Using MyMathLab Features of MyMathLab You must already be registered or enrolled in a current MyMathLab class in order to use MyMathLab. If you are not.
When I want to work with SQL, I start off as if I am doing a regular query.
CSC1401 Strings (text). Learning Goals Working with Strings as a data type (a class) Input and output of Strings String operations.
Chapter 3: Classes and Objects Java Programming FROM THE BEGINNING Copyright © 2000 W. W. Norton & Company. All rights reserved Java’s String Class.
Introduction Chapter 1 8/31 & 9/1 Imagine! Java: Programming Concepts in Context by Frank M. Carrano, (c) Pearson Education - Prentice Hall, 2010.
The 9 th and 10 th tutoring session Fall, 2012 Haidong Xue 5:30pm—8:30pm 10/2/2012 and 10/3/2012 -Review loop structures and improve CheckISBN and CourseAverage.
CSC Programming I Lecture 9 September 11, 2002.
Homework 8 Due ( MT sections ) ( WTh sections ) at midnight Sun., 10/28 Mon., 10/29 Problems Reading is under week 7, however.
CSc2310 tutoring session, week 8 Fall, 2012 Haidong Xue 5:30pm—8:30pm 11/13/2012 and 11/14/2012 -Dr Cao’s Assignment 5 -i.e. Problem 4 on page 335 and.
1 Project 2: Using Variables and Expressions. 222 Project 2 Overview For this project you will work with three programs Circle Paint Ideal_Weight What.
1 Project 3 String Methods. Project 3: String Methods Write a program to do the following string manipulations: Prompt the user to enter a phrase and.
Introduction Chapter 1 1/22/16. Check zyBooks Completion Click on the boxes for each section.
Please CLOSE YOUR LAPTOPS, and turn off and put away your cell phones, and get out your note- taking materials.
Special Methods in Java. Mathematical methods The Math library is extensive, has many methods that you can call to aid you in your programming. Math.pow(double.
The 7 th and 8 th tutoring session Fall, 2012 Haidong(Haydon) Xue 5:30pm—8:30pm 9/25/2012 and 9/26/ Review control structures - Improve CheckISBN.
import java.util.Scanner; class myCode { public static void main(String[] args) { Scanner input= new Scanner(System.in); int num1; System.out.println(“Enter.
Computer Programming 12 Mr. Jean March 5 th, 2014.
1 Project 5: Leap Years. 222 Leap Years Write a program that reads an integer value from the user representing a year and determines if the year is a.
1 Project 4: Computing Distance. 222 Computing Distance Write a program to compute the distance between two points. Recall that the distance between the.
Setting up Categories and Grade Setup Middle Schools.
Variable scope. Variable Scope Variables do not live forever. Failing to take that into account leads to problems. Let's look at an example. Let's write.
CSC 1051 – Data Structures and Algorithms I Dr. Mary-Angela Papalaskari Department of Computing Sciences Villanova University Course website:
Some Assignments  Write a program which prints the following information about at least 5 persons: NAME MAIL-ID EMPLOYEE-CODE PHONE Eg. Umesh
Building Java Programs
CSC 1051 – Data Structures and Algorithms I
Introduction to Methods in java
Data types, Expressions and assignment, Input from User
Use proper case (ie Caps for the beginnings of words)
Computers & Programming Languages
Python Basics with Jupyter Notebook
Building Java Programs
Basic Lessons 5 & 6 Mr. Kalmes.
Basic Mr. Husch.
Input, Variables, and Mathematical Expressions
Methods/Functions.
Repetition CSC 1051 – Data Structures and Algorithms I Course website:
Printing from the Konica after you’ve sent a file down to print
Presentation transcript:

The 5 th and 6 th tutoring session - A case study about verifying a ISBN - Writing code for problems in HW1 Fall, 2012 Haidong(Haydon) Xue 5:30pm—8:30pm 9/18/2012 and 9/19/2012

CSc2310 Tutoring Time: 5:30pm-8:30pm Tutor: Haidong Xue (You can call me Haydon) There are 2 sections: 1. Review 5:30pm – 6:30pm Code the ISBN verifying program Code the programs for the problems in your HW1 2. Q&A If you have any questions about Java programming, I am right here

ISBN Checking – problem definition An certain version of ISBN (International Standard Book Number) is a unique number assigned to a book when it’s published, such as 0–393–96945–2. The number at the end is a check digit that’s calculated from the other digits in the ISBN. Our goal is to write a program named CheckISBN that calculates the check digit for an ISBN entered by the user: Enter ISBN: Check digit entered: 2 Check digit computed: 2

ISBN Checking – to do list What is the to-do list?

ISBN Checking – to do list 1. Prompt the user to enter an ISBN. 2. Compute the check digit for the ISBN. 3. Display the check digit entered by the user. 4. Display the computed check digit. You can start from putting this list into your code as comments

ISBN Checking – The mathematics to verify the last digit

ISBN Checking – The mathematics to verify the last digit total= 0          2 = = 262 Check digit: 10 – ((262 – 1) mod 11) = 10 – (261 mod 11) = 10 – 8 = 2

ISBN Checking – coding Let code it step by step Please get your Eclipse ready Create a class named CheckISBN with main method If you are not very confident, please download and open this code first (it is the finished program): heckISBN.java

ISBN Checking – coding // 1. Prompt the user to enter an ISBN. Your code:

ISBN Checking – coding // 1. Prompt the user to enter an ISBN. System.out.print("Please enter a ISBN: "); Scanner s = new Scanner(System.in); String originalISBN = s.next(); s.close();

ISBN Checking – coding // 2. Compute the check digit for the ISBN. (About String: Your code:

ISBN Checking – coding // 2. Compute the check digit for the ISBN. int dashPos1 = originalISBN.indexOf('-'); // return the index of '-' int dashPos2 = originalISBN.indexOf('-', dashPos1 + 1); // return the index of '-', //only scan the string //from dashPos1+1 to //the end String reducedISBN = originalISBN.substring(0, dashPos1) + originalISBN.substring(dashPos1 + 1, dashPos2) + originalISBN.substring(dashPos2 + 1, 11); //remove '-' (….)

ISBN Checking – coding // 2. Compute the check digit for the ISBN. (…) int total = 10 * Integer.parseInt(reducedISBN.substring(0, 1)) + 9 * Integer.parseInt(reducedISBN.substring(1, 2)) + 8 * Integer.parseInt(reducedISBN.substring(2, 3)) + 7 * Integer.parseInt(reducedISBN.substring(3, 4)) + 6 * Integer.parseInt(reducedISBN.substring(4, 5)) + 5 * Integer.parseInt(reducedISBN.substring(5, 6)) + 4 * Integer.parseInt(reducedISBN.substring(6, 7)) + 3 * Integer.parseInt(reducedISBN.substring(7, 8)) + 2 * Integer.parseInt(reducedISBN.substring(8, 9)); int checkDigit = 10 - ((total - 1) % 11);

ISBN Checking – coding // 3. Display the check digit entered by the user. Your code:

ISBN Checking – coding // 3. Display the check digit entered by the user. System.out.println("Check digit entered: " + originalISBN.charAt(12));

ISBN Checking – coding // 4. Display the computed check digit. Your code:

ISBN Checking – coding // 4. Display the computed check digit. final String DIGITS = " X"; System.out.println("Check digit computed: " + DIGITS.charAt(checkDigit));

ISBN Checking - testing Run your finished code and let me know your questions.

HW1 – Problem #1 X = (-b ± Sqrt(b 2 – 4ac))/2a Use the following values 2, 6 and 2 for variables a, b and c respectively. Your code:

HW1 – Problem #1 X = (-b ± Sqrt(b 2 – 4ac))/2a Use the following values 2, 6 and 2 for variables a, b and c respectively. My code: double a =2; double b=6; double c=2; double doubleTempSqrt = Math.sqrt(b*b-4*a*c); double x1 = (-b+ doubleTempSqrt )/(2*a); double x2 = (-b- doubleTempSqrt )/(2*a);

HW1 – Problem #2 Print:

HW1 – Problem #2 Solution from Haidong: Find a ASCII art generator like: =Alpha&t=Java Copy it to java line by line For each ‘\’, replace it with ‘\\’, and put ‘\n’ at the end of each line Print it

HW1 – Problem #2 My code: String java = " _____ _____ _____ _____\n" +" /\\ \\ /\\ \\ /\\ \\ /\\ \\ \n" +" /::\\ \\ /::\\ \\ /::\\____\\ /::\\ \\\n" +" \\:::\\ \\ /::::\\ \\ /:::/ / /::::\\ \\\n" +" \\:::\\ \\ /::::::\\ \\ /:::/ / /::::::\\ \\\n" +" \\:::\\ \\ /:::/\\:::\\ \\ /:::/ / /:::/\\:::\\ \\\n" +" \\:::\\ \\ /:::/__\\:::\\ \\ /:::/____/ /:::/__\\:::\\ \\\n" +" /::::\\ \\ /::::\\ \\:::\\ \\ |::| | /::::\\ \\:::\\ \\\n" +" _____ /::::::\\ \\ /::::::\\ \\:::\\ \\ |::| | _____ /::::::\\ \\:::\\ \\\n" +" /\\ \\ /:::/\\:::\\ \\ /:::/\\:::\\ \\:::\\ \\ |::| | /\\ \\ /:::/\\:::\\ \\:::\\ \\\n" +"/::\\ /:::/ \\:::\\____\\/:::/ \\:::\\ \\:::\\____\\ |::| | /::\\____\\/:::/ \\:::\\ \\:::\\____\\\n" +"\\:::\\ /:::/ \\::/ /\\::/ \\:::\\ /:::/ / |::| | /:::/ /\\::/ \\:::\\ /:::/ /\n" +" \\:::\\/:::/ / \\/____/ \\/____/ \\:::\\/:::/ / |::| | /:::/ / \\/____/ \\:::\\/:::/ / \n" +" \\::::::/ / \\::::::/ / |::|____|/:::/ / \\::::::/ / \n" +" \\::::/ / \\::::/ / |:::::::::::/ / \\::::/ / \n" +" \\::/ / /:::/ / \\::::::::::/____/ /:::/ / \n" +" \\/____/ /:::/ / ~~~~~~~~~~ /:::/ / \n" +" /:::/ / /:::/ / \n" +" \\::/ / \\::/ / \n" +" \\/____/ \\/____/ \n" +" \n"; System.out.println(java);

HW1 – Problem #2 Result:

If you have any questions about java programming, I will be here till 8:30pm