Computer Programming Lab 6. Exercise 1 Sample Runs.

Slides:



Advertisements
Similar presentations
Grade 2 Created by; Kim Smith
Advertisements

Computer Programming Lab(7).
Year 10 ISA Controlled assessment Week starting March 4 th 2013.
Computer Programming Lab 8.
Today Is Sunday By Dr Jean.
CS110 Programming Language I Lab 10: Arrays I Computer Science Department Spring 2014.
Ain't It A Shame 1-4 Aint it a shame to work on Sunday, Aint it a shame, (a working shame,) Aint it a shame to work on Sunday, Aint it a shame, (a working.
1 The seven days of the week. 2 Monday is our washing day. Scrub, scrub, scrub.
By Theresa Taderera Out and up Page 1 >introductionintroduction Page 2 > assault course Page 3> what we dowhat we do Page 4 > café Page 5> map> map Page.
QUESTION 1 What day is it today? A) I’m Tuesday. B) I have Tuesday. C) Tuesday. D) It’s Tuesday.
2012 CALENDAR. JANUARY 2012 Sunday 日 Monday 月 Tuesday 火 Wednesday 水 Thursday 木 Friday 金 Saturday 土
Primitive Data Types and Operations. Introducing Programming with an Example public class ComputeArea { /** Main method */ public static void main(String[]
Saturday May 02 PST 4 PM. Saturday May 02 PST 10:00 PM.
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.
Time Zones The World is divided up into 24 time zones. Each time zone is approximately 15 degrees of longitude wide. The time within each time zone has.
LAB 10.
Computer Programming Lab(4).
Computer Programming Lab(5).
ARISE Summer Institute UC Davis June 17-June 22, 2011.
Class Schedule Template SundayMondayTuesdayWednedayThursdayFridaySaturday 6 AM 7 AM 8 AM 9 AM 10 AM 11 AM 12 AM 1 PM 2 PM 3 PM 4 PM 5 PM 6 PM Title Classroom.
CS 241 – Computer Programming II Lab Kalpa Gunaratna –
CPS 2231 Computer Organization and Programming Instructor: Tian (Tina) Tian.
Using Object-Oriented JavaScript CST 200- JavaScript 4 –
Building Java Programs Chapter 5 Program Logic and Indefinite Loops Copyright (c) Pearson All rights reserved.
What day is today? What`s the date?. Sunday Monday Tuesday Wednesday Thursday Friday Saturday What day is today?
Days of the week instructions. Children can; Order the days of the week. Use sentence strips and activity cards to write sentences about what they do on.
(Tentative) Plan for Last Days of School. Friday 5/8 / Monday 5/11 Work on empathy final project Tuesday 5/12 / Wednesday 5/13 (MIN.) Work on empathy.
Conditional If Week 3. Lecture outcomes Boolean operators – == (equal ) – OR (||) – AND (&&) If statements User input vs command line arguments.
Lecture 10 Instructor: Craig Duckett Lecture 10 is in Lecture 11 Folder.
Floating Point Numbers Expressions Scanner Input Algorithms to Programs Shirley Moore CS 1401 Spring 2013 February 12, 2013.
PART OF SPEECH DEFINITION SYNONYM SENTENCE WORD ORIGIN NAME TEACHER AND DATE1 WORDS OF THE WEEK.
CSCI S-1 Section 6. Coming Soon Homework Part A – Friday, July 10, 17:00 EST Homework Part B – Tuesday, July 14, 17:00 EST Mid-Term Quiz Review – Friday,
10/14/10 BR – What type of Chart is this? Be sure to hand in this week’s bellringers!
CSc2310 tutoring session, week 8 Fall, 2012 Haidong Xue 5:30pm—8:30pm 11/06/2012 and 11/07/2012 -Test 3 Study Guide.
Lec 4: while loop and do-while loop. Review from last week if Statements if (num < 0.5){...println("heads"); } if –else Statements if (num < 0.5){...println("heads");
Click the button to begin. 12:25 What time does this clock show? 5:00 4:00.
Question of the Day! Week 18 5/22 – 5/26. Question of the Day! Monday, May 22nd Which type of cloud is easiest to spot and why?
CS110 Programming Language I Lab 4: Control Statements I Computer Science Department Spring 2014.
Lecture 9: Bits and Pieces, Part 2 Tami Meredith.
Week 61 Introduction to Programming Ms. Knudtzon C Period Tuesday October 12.
Reading input from the console input. Java's console input The console is the terminal window that is running the Java program I.e., that's the terminal.
Introduction to array: why use arrays ?. Motivational example Problem: Write a program that reads in and stores away 5 double numbers After reading in.
CSci 162 Lecture 2 Martin van Bommel. Enumeration –process of listing all of the elements in the domain of a type Enumerated type –type defined via enumeration.
TODAY IS MONDAY THE 16 th OF NOVEMBER 2015 ON MONDAY WE ARE WORKING WITH THE LAPTOP.
Expense Report Total Miles MONDAY 5 5 TUESDAY WEDNESDAY 6 6 THURSDAY FRIDAY SATURDAY 0 SUNDAY0 TOTAL 23.
1 Enums (Chapter 4) To enumerate is: to name things one after another in a list Java has a type, called an enum, where a programmer specifies a finite.
C OMMON M ISTAKES CSC Java Program Structure  String Methods.
Computer Programming Lab 9. Exercise 1 Source Code package excercise1; import java.util.Scanner; public class Excercise1 { public static void main(String[]
import java.util.Scanner; class myCode { public static void main(String[] args) { Scanner input= new Scanner(System.in); int num1; System.out.println(“Enter.
The birthday calendar 2B : Unit 6 Days of the week Days of the week.
1 1 Chapter 2 Elementary Programming. 2 2 Motivations In the preceding chapter, you learned how to create, compile, and run a Java program. Starting from.
Happy Days by Charles Fox and Norman Gimbel PowerPoint by Camille Page.
The Calendar.
A.P. Computer Science Input is NOT tested on the AP exam, but if we want to do any labs, we need input!!
Daily Math Review September 2-6, Monday Solve the following problems with strategies and/or algorithms 5, = 9, = 3, =
WITH Ada.Text_IO; PROCEDURE Three_Days IS | Finds yesterday and tomorrow, given today.
PART OF SPEECH DEFINITION SYNONYM SENTENCE NAME TEACHER AND DATE1 WORDS OF THE WEEK.
PART OF SPEECH DEFINITION SYNONYM SENTENCE NAME TEACHER AND DATE1 WORDS OF THE WEEK.
Loops Review. How to generate random numbers Math.random() will return a random decimal value in the form of a double. double num1 = Math.random(); num1.
Chapter 2 Clarifications
Categories of loops definite loop: Executes a known number of times.
Exercise 1- I/O Write a Java program to input a value for mile and convert it to kilogram. 1 mile = 1.6 kg. import java.util.Scanner; public class MileToKg.
Data types, Expressions and assignment, Input from User
Java Fix a program that has if Online time for Monday’s Program
AP Java Review If else.
Lec 4: while loop and do-while loop
Java Fix a program that has if Online time for Monday’s Program
Truth tables: Ways to organize results of Boolean expressions.
AP Java Review If else.
Input, Variables, and Mathematical Expressions
Presentation transcript:

Computer Programming Lab 6

Exercise 1

Sample Runs

Scanner input = new Scanner(System.in); System.out.print("Enter a, b and c: "); double a = input.nextInt(); double b = input.nextInt(); double c = input.nextInt(); double discriminant = ((b*b) - (4*a*c)); Source Code

Cont if (discriminant > 0){ double root = Math.pow(discriminant, 0.5); double ro1 = ((-b + root)/(2*a)); double ro2 = ((-b - root)/(2*a)); System.out.println("The roots are " + ro1 + " and "+ro2); }else if (discriminant == 0){ double ro = (-b/(2*a)); System.out.println("The root is " + ro); }else System.out.println("The Equation has no real roots.");

Exercise 2 (Find future dates) Write a program that prompts the user to enter an integer for today’s day of the week (Sunday is 0, Monday is 1,..., and Saturday is 6). Also prompt the user to enter the number of days after today for a future day and display the future day of the week.

Source Code Scanner input = new Scanner(System.in); System.out.print("Enter today’s day: "); int today = input.nextInt(); System.out.print("Enter the number of days elapsed since today: "); int elapsed = input.nextInt(); String nameDay;

Cont. if (today == 0) { nameDay = "Sunday"; } else if (today == 1) { nameDay = "Monday"; } else if (today == 2) { nameDay = "Tuesday"; } else if (today == 3) { nameDay = "Wednesday"; } else if (today == 4) { nameDay = "Thursday"; } else if (today == 5) nameDay = "Friday"; else nameDay = "Saturday";

Cont. int futureDay = (today + elapsed) % 7; String nameFuture; if (futureDay == 0) { nameFuture = "Sunday"; } else if (futureDay == 1) { nameFuture = "Monday"; } else if (futureDay == 2) { nameFuture = "Tuesday"; } else if (futureDay == 3) { nameFuture = "Wednesday"; } else if (futureDay == 4) { nameFuture = "Thursday"; } else if (futureDay == 5) nameFuture = "Friday"; else nameFuture = "Saturday"; System.out.println("Today is " + nameDay + " and the future day is " + nameFuture);

Exercise 3

Scanner input = new Scanner(System.in); System.out.print("Enter three integers: "); int number1 = input.nextInt(); int number2 = input.nextInt(); int number3 = input.nextInt(); if (number1 > number2) { int temp = number1; number1 = number2; number2 = temp; } Source Code

if (number2 > number3) { int temp = number2; number2 = number3; number3 = temp; } if (number1 > number2) { int temp = number1; number1 = number2; number2 = temp; } System.out.println("The sorted numbers are " + number1 + " " + number2 + " " + number3); Cont