Introduction to programming in java Lecture 05 Review of 1 st four lectures and Practice Questions.

Slides:



Advertisements
Similar presentations
Programming for Beginners Martin Nelson Elizabeth FitzGerald Lecture 3: Flow Control I: For Loops.
Advertisements

Building Java Programs
CS100A, Fall 1997, Lecture 111 CS100A, Fall 1997 Lecture 11, Tuesday, 7 October Introduction to Arrays Concepts: Array declaration and allocation Subscripting.
Methods Liang, Chapter 4. What is a method? A method is a way of running an ‘encapsulated’ series of commands. System.out.println(“ Whazzup ”); JOptionPane.showMessageDialog(null,
Introduction to Computers and Programming Lecture 4: Mathematical Operators New York University.
Math class methods & User defined methods Introduction to Computers and Programming in JAVA: V
Introduction to Computers and Programming Lecture 16: Arrays (cont) Professor: Evan Korth New York University.
1 More on Arrays Passing arrays to or from methods Arrays of objects Command line arguments Variable length parameter lists Two dimensional arrays Reading.
Random (1) Random class contains a method to generate random numbers of integer and double type Note: before using Random class, you should add following.
Relational Operators Control structures Decisions using “if” statements  2000 Prentice Hall, Inc. All rights reserved. Modified for use with this course.
Copyright 2006 by Pearson Education 1 Building Java Programs Chapter 3: Parameters, Return, and Interactive Programs.
Lecture 7. Review Homework 1 (sample solution) Project 1 will be assigned next week –Draw a picture (whatever you want) in the world by using turtles.
Lesson 1-6 Solving Quadratic Equations. Objective:
4.8 Quadratic Formula and Discriminant
Options for User Input Options for getting information from the user –Write event-driven code Con: requires a significant amount of new code to set-up.
10/25: Methods & templates Return to concepts: methods Math class methods 1 st Program of the day About DrawLine.java modifications Method definitions.
Section 7.2 – The Quadratic Formula. The solutions to are The Quadratic Formula
Arrays (Part 1) Computer Science Erwin High School Fall 2014.
1. 2 Reference... Student stu; Reference of Student stu When the reference is created it points to a null value. Before access the reference, objects.
“Introduction to Programming With Java”
CSC 1051 – Data Structures and Algorithms I Dr. Mary-Angela Papalaskari Department of Computing Sciences Villanova University Course website:
Introduction to Programming David Goldschmidt, Ph.D. Computer Science The College of Saint Rose Java Fundamentals (Variables, Arithmetic, etc.)
Introduction to Programming David Goldschmidt, Ph.D. Computer Science The College of Saint Rose Java Methods (a.k.a. Functions)
***** SWTJC STEM ***** Chapter 3-1 cg 39 Math Class The Math class provides a convenient way to access higher math functions. The Math class is automatically.
Mixing integer and floating point numbers in an arithmetic operation.
Java Arrays and Methods MIS 3023 Business Programming Concepts II The University of Tulsa Professor: Akhilesh Bajaj All slides in this presentation ©Akhilesh.
1 Building Java Programs Chapter 3: Introduction to Parameters and Objects These lecture notes are copyright (C) Marty Stepp and Stuart Reges, They.
1.2 Built-in Types of Data Introduction to Programming in Java: An Interdisciplinary Approach · Robert Sedgewick and Kevin Wayne · Copyright © 2008 · December.
2.1 Functions. Functions in Mathematics f x y z f (x, y, z) Domain Range.
Week 61 Introduction to Programming Ms. Knudtzon C Period Tuesday October 12.
By Christina Armetta. The First step is to get the given equation into standard form. Standard form is Example of putting an equation in standard form:
College Board Topics – A.P. Computer Science A Program Design - Read and understand a problem's description, purpose, and goals; Apply data abstraction.
AP Computer Science A – Healdsburg High School 1 Unit 9 - Parameter Passing in Java.
1 Arrays: Matrix Renamed Instructor: Mainak Chaudhuri
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 Science A 1. Course plan Introduction to programming Basic concepts of typical programming languages. Tools: compiler, editor, integrated editor,
Lecture 6: Methods MIT-AITI Kenya © 2005 MIT-Africa Internet Technology Initiative In this lecture, you will learn… What a method is Why we use.
CS305j Introduction to Computing Parameters and Methods 1 Topic 8 Parameters and Methods "We're flooding people with information. We need to feed it through.
Building Java Programs Chapter 4 Lecture 4-1: Scanner ; cumulative algorithms reading: 3.3 – 3.4, 4.2.
Introduction to programming in java Lecture 22 Arrays – Part 2 and Assignment No. 3.
Copyright 2011 by Pearson Education Building Java Programs Chapter 3 Lecture 3-2: Return values, Math, and double reading: 3.2,
Introduction to programming in java Lecture 11 Boolean Expressions and Assignment no. 2.
Introduction to programming in java Lecture 21 Arrays – Part 1.
Introduction to programming in java
Common Mistakes with Functions CSE 1310 – Introduction to Computers and Programming Vassilis Athitsos University of Texas at Arlington 1.
Introduction to programming in java
Building Java Programs
Building Java Programs
Building Java Programs
Something about Java Introduction to Problem Solving and Programming 1.
Starting Out with Java: From Control Structures through Objects
The Quadratic Formula.
CS 200 Primitives and Expressions
class PrintOnetoTen { public static void main(String args[]) {
CS 200 Primitives and Expressions
Building Java Programs
Week 4 Lecture-2 Chapter 6 (Methods).
See requirements for practice program on next slide.
Building Java Programs
Building Java Programs
Building Java Programs
Building Java Programs
Building Java Programs
Building Java Programs
Chapter 4 Lecture 4-1: Scanner; if/else reading: 3.3 – 3.4, 4.1, 4.5
Lecture 22: Number Systems
Building Java Programs
PROGRAMMING ASSIGNMENT I
Building Java Programs
Presentation transcript:

Introduction to programming in java Lecture 05 Review of 1 st four lectures and Practice Questions

Answer : D

Answer : A

Answer : C

What does the following program output? Answer : C

Answer : A

Answer : C

Answer : D

Answer : C

Answer : A

Practice Questions Program 1: Write a program that takes base and height of a triangle from the command line arguments and prints the area of triangle. Program 2: Write a program that prints the random value between 0 and 100.

Solution: Program 1 class AreaOfTriangle{ public static void main(String args[]){ int b = Integer.parseInt(args[0]); // base of triangle int h = Integer.parseInt(args[1]); // height of trangle int area = (½)*b * h; System.out.println(“base : ” + b); System.out.println(“height : ” + h); System.out.println(“Area of triangle: ” + area); }

Solution: Program 2 class RandomNumber{ public static void main(String args[]) { double r = Math.random(); // uniform between 0 and 1 int num = (int)(r*100); // uniform between 0 and 100 System.out.println(“Random number: ” + num); }

Homework Assignment # 1 (Total marks: 5) Submission deadline: 24 th Sep 2013 NOTES: 1.Only HAND WRITTEN assignments are acceptable on A4 size white paper. 2.If any student copy assignment from other then -5 marks will be deducted from the overall grade. 3.Late submission is not allowed.

Homework Assignment # 1 (Cont…) Question 1: Write a program called MyInfo.java that prints your name, student ID and GPA on separate lines. Note use three variables name, studentID, and GPA and assign proper values to them. Question 2: What do each of the following print? – System.out.println(2 + "bc"); – System.out.println( "bc"); – System.out.println((2+3) + "bc"); – System.out.println("bc" + (2+3)); – System.out.println("bc" ); Explain each outcome.

Homework Assignment # 1 (Cont…) Question 3: Write a program that averages the rain fall for three months, April, May, and June. Declare and initialize a variable to the rain fall for each month. Compute the average, and write out the results, something like: Rainfall for April: 12 Rainfall for May : 14 Rainfall for June: 8 Average rainfall:

Homework Assignment # 1 (Cont…) Question 4: Write a program called MaxNumber.java that takes two positive integers as command-line arguments and prints the maximum value. For example: Java MaxNumber 9 4 Maximum value: 9 Hint: you need to use Math.max() function (See lecture 3, slide 21). Question 5: Write a program that solves the quadratic equation x 2 + bx + c = 0. Note that, pass the values of b and c as a command line argument to the program. Formula for solving quadratic equation is given below.