Ihsan Ayyub Qazi Introduction to Computer Programming Recitation 3 Ihsan Ayyub Qazi.

Slides:



Advertisements
Similar presentations
©2004 Brooks/Cole Chapter 3 Interactive Input. Figures ©2004 Brooks/Cole CS 119: Intro to JavaFall 2005 Standard Input and Output System.in Is Used to.
Advertisements

Primitive Data Types and Operations. Introducing Programming with an Example public class ComputeArea { /** Main method */ public static void main(String[]
Scanner Pepper With credits to Dr. Siegfried. The Scanner Class Most programs will need some form of input. At the beginning, all of our input will come.
Java Intro. Strings “This is a string.” –Enclosed in double quotes “This is “ + “another “ + “string” –+ concatenates strings “This is “ “ string”
IC211 Lecture 8 I/O: Command Line And JOptionPane.
School of Computing Science CMT1000 Ed Currie © Middlesex University Lecture 4: 1 CMT1000: Introduction to Programming Ed Currie Lecture 5a: Input and.
© A+ Computer Science - Visit us at Full Curriculum Solutions M/C Review Question Banks.
Scanner & Stepwise Refinement Pepper With credit to Dr. Siegfried.
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;
Computer Programming Lab(5).
JOptionPane class. Dialog Boxes A dialog box is a small graphical window that displays a message to the user or requests input. A variety of dialog boxes.
Warm-Up: Monday, March 3 List all devices you can think of that can be used to input information into the computer.
CS-0401 INTERMEDIATE PROGRAMMING USING JAVA Prof. Dr. Paulo Brasko Ferreira Fall 2014.
Chapter 4 Objects and Classes.
Object Oriented Programming Concepts Fatih University Ceng-104-A Introduction to Object Oriented Programming Harun Reşit Zafer This is a slide version.
Starting Out with Java: From Control Structures through Objects
Source Code: Chapters 1 and 2
Starting Out with Java: From Control Structures through Objects
Java. Features of Java Architecture Neutral and Portable o Write once, run anywhere o Java Virtual Machine (JVM) Object Oriented o Classes encapsulate.
Data Types in Java James Burns. Recitation Name some characteristics of objects Name some characteristics of objects Chemical Bank Chemical Bank Describe.
Using Data Within a Program Chapter 2.  Classes  Methods  Statements  Modifiers  Identifiers.
CS 106 Introduction to Computer Science I 01 / 31 / 2007 Instructor: Michael Eckmann.
Data Types and Operators  Two category of data types:  Primitive type: value type. Store values.  Object type: reference type. Store addresses.
Computer programming Lecture#2 أ. إلهام باسندوه 1.
Introduction to Java Lecture Notes 3. Variables l A variable is a name for a location in memory used to hold a value. In Java data declaration is identical.
Introduction to Programming
Chapter 3 Java Input/Output.
1/28: Inputs, Variable Types, etc. Addition.java in depth Variable types & data types Input from user: how to get it Arithmetic operators.
CSC1030 HANDS-ON INTRODUCTION TO JAVA Introductory Lab.
Dialog Boxes.
FUNDAMENTALS 2 CHAPTER 2. OPERATORS  Operators are special symbols used for:  mathematical functions  assignment statements  logical comparisons 
Data Types – Reference Types Objective To understand what reference types are The need to study reference types To understand Java standard packages To.
Java Fundamentals Part Integer Division Division can be tricky. In a Java program, what is the value of 1/2? You might think the answer is.
Introduction to Computing Concepts Note Set 15. JOptionPane.showMessageDialog Message Dialog Allows you to give a brief message to the user Can be used.
Component 4: Introduction to Information and Computer Science Unit 5: Overview of Programming Languages, Including Basic Programming Concepts Lecture 3.
2/18: Assignment Operators About Average2.java –while loop use –explicit casting –twoDigits object Assignment Operators Increment & Decrement Operators.
Variables and Types Java Part 3. Class Fields  Aka member variable, field variable, instance variable, class variable.  These are the descriptors of.
What Is a Package? A package is a namespace that organizes a set of related classes and interfaces. Conceptually you can think of packages as being similar.
Computer Programming1 Computer Science 1 Computer Programming.
©2016 Pearson Education, Inc. Upper Saddle River, NJ. All Rights Reserved. CSC 110 – INTRO TO COMPUTING - PROGRAMMING String and Scanner Objects.
By : Robert Apeldorn. What is OOP?  Object-oriented programming is a programming paradigm that uses “objects” to design applications and computer programs.
Starting Out with Java: From Control Structures through Objects 5 th edition By Tony Gaddis Source Code: Chapter 5.
Data Types – Reference Types Objective To understand what reference types are The need to study reference types To understand Java standard packages To.
Java Scanner Class Keyboard Class. User Interaction So far when we created a program there was no human interaction Our programs just simply showed one.
©2016 Pearson Education, Inc. Upper Saddle River, NJ. All Rights Reserved. CSC 110 – INTRO TO COMPUTING - PROGRAMMING Switch Statement.
Casting, Wrapper Classes, Static Methods, JOptionPane Class.
© A+ Computer Science - import java.util.Scanner; Try to be as specific as possible when using an import.
CS0007: Introduction to Computer Programming The for Loop, Accumulator Variables, Seninel Values, and The Random Class.
A.P. Computer Science Input is NOT tested on the AP exam, but if we want to do any labs, we need input!!
JAVA 1.COMPARISON: JAVA AND C++ 2.KEYBOARD INPUT 3.OUTPUT 4.CONVERSION FROM STRING 5.OPERATORS AND EXPRESSIONS 6.DIALOG BOX – USER PROMPT January
UFCFY5-30-1Multimedia Studio Coding for Interactive Media Fundamental Concepts.
What is an Object Objects are key to understanding object-oriented technology. An object can be considered a "thing" that can perform a set of related.
INTERMEDIATE PROGRAMMING USING JAVA
Data Types – Reference Types
Yanal Alahmad Java Workshop Yanal Alahmad
Dialogues and Wrapper Classes
Chapter 3 Java Input/Output.
Computer Programming Methodology Input and While Loop
Message, Input, Confirm, and Specialized Dialogs
Something about Java Introduction to Problem Solving and Programming 1.
CS-0401 INTERMEDIATE PROGRAMMING USING JAVA
البرمجة الكينونية بلغة جافا 1294
CSS 161 Fundamentals of Computing Introduction to Computers & Java
Introduction to Classes and Methods
Chapter 3: Introduction to Objects and Input/Output
Chapter 3 Input/Output.
Message, Input, and Confirm Dialogs
JOptionPane class.
Chapter 2: Java Fundamentals cont’d
Presentation transcript:

Ihsan Ayyub Qazi Introduction to Computer Programming Recitation 3 Ihsan Ayyub Qazi

Ihsan Ayyub Qazi Agenda  Project Questions  FTP  Dialog Boxes  Classes and Objects  Scanner Class

Ihsan Ayyub Qazi Project: Any Questions?  Goal: Make a Tip Calculator  Input:  Total bill  Tip percentage  Number of people splitting the bill  Output:  Tip amount  Total to pay  Total per person  Requirements:  JOptionPane class must be used for input and output  Atleast two different data types must be used  Extra Credit:  Use DecimalFormat class

Ihsan Ayyub Qazi Dialog Boxes: JOptionPane Class  Java API has a class that allows you to create dialog boxes  JOptionPane  import javax.swing.JOptionPane;  JOptionPane.showMessageDialog(null, "Hello");  JOptionPane.showInputDialog("Enter name");  returns a String  How can we convert a String into a number?  Why not casting?  Strings are not primitive data types?

Ihsan Ayyub Qazi Converting Strings to numbers  byte age = Byte.parseByte( “7 ");  short year = Short.parseShort( “ 1007");  int bigNum = Integer.parseInt( “ 82456");  long bigNum2 = Long.parseLong( " ");  float price = Float.parseFloat("1.99");  double sum = Double.parseDouble("72.345");

Ihsan Ayyub Qazi Output? import javax.swing.JOptionPane; public class Test { public static void main(String args []) { String input; float value; int con; input = JOptionPane.showInputDialog("Enter your GPA); value = Float.parseFloat(input); con = value; JOptionPane.showMessageDialog(null, “Your GPA is ”+con); }

Ihsan Ayyub Qazi What is a class? An object?  Consider a bicycle of a particular model from a given company  Thousands of such bicycles may have been manufactured and sold  Each bicycle was built from the same set of blueprints and therefore contains the same components  In object-oriented terms, we say that your bicycle is an instance of the class (of objects) known as bicycles.  A class is the blueprint from which individual objects are created.

Ihsan Ayyub Qazi Variables  What does a primitive type variable store?  holds data items  What does class type variables store?  holds references (or address of an object)

Ihsan Ayyub Qazi Bicycle class: Output? public class Bicycle { int speed = 0; int gear = 1; void changeGear(int newValue) { gear = newValue; } void speedUp(int increment) { speed = speed + increment; } void applyBrakes(int decrement) { speed = speed - decrement; } void printStates() { System.out.println(" speed:"+speed+" gear:"+gear); } public static void main(String args []) { Bicycle bike = new Bicycle(); bike.speed = 34; bike.gear = 3; bike.changeGear(5); bike.speedUp(3); bike.printStates(); bike.applyBrakes(5); bike.printStates(); } Attribute s Method Creating an instance of a class

Ihsan Ayyub Qazi In-class problem  Create two objects of type Bicycle  name them bike1 and bike2  The output of the program should be  speed:10 gear:2 // bike 1  speed:7 gear:2 // bike 2  speed:30 gear:4 // bike 1  speed:32 gear:4 // bike 2  speed:5 gear:2 // bike 1 [bicycle goes down, tough luck !]  speed:40 gear:5 // bike 2

Ihsan Ayyub Qazi Quick Review: Scanner Class  Another method for getting user input!  One can get input in different data formats  import java.util.Scanner;  Some Scanner Class methods Method NameReturns Input As nextBytebyte nextDoubledouble nextFloatfloat nextIntint nextLineString nextLonglong nextShortshort

Ihsan Ayyub Qazi public class Payroll { public static void main(String[] args) { String name; // To hold a name int hours; // Hours worked double payRate; // Hourly pay rate double grossPay; // Gross pay // Create a Scanner object to read input. Scanner keyboard = new Scanner(System.in); // Get the user's name. System.out.print("What is your name? "); name = keyboard.nextLine(); // Get the number of hours worked this week. System.out.print("How many hours did you work this week? "); hours = keyboard.nextInt(); // Get the user's hourly pay rate. System.out.print("What is your hourly pay rate? "); payRate = keyboard.nextDouble(); // Calculate the gross pay. grossPay = hours * payRate; // Display the resulting information. System.out.println("Hello " + name); System.out.println("Your gross pay is $" + grossPay); }

Ihsan Ayyub Qazi THANKS !!