TemperatureConversion

Slides:



Advertisements
Similar presentations
Computer Programming Lab(7).
Advertisements

Computer Programming Lab 8.
Today’s topics: I/O (Input/Output). Scribbler Inputs & Outputs  What are the Scribbler’s inputs and outputs?  reset button  motors/wheel  light sensor.
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.
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.
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.
Input and Output The system console. In the beginning … When computers were relatively expensive and rare, most users interacted with a terminal –CRT.
Strings as objects Strings are objects. Each String is an instance of the class String They can be constructed thus: String s = new String("Hi mom!");
© 2006 Pearson Addison-Wesley. All rights reserved2-1 Console Input Using the Scanner Class Starting with version 5.0, Java includes a class for doing.
Scanner & Stepwise Refinement Pepper With credit to Dr. Siegfried.
LAB 10.
Computer Programming Lab(4).
Week 2 - Friday.  What did we talk about last time?  Data representation  Binary numbers  Types  int  boolean  double  char  String.
Computer Programming Lab(5).
Chapter 2 Section 2.2 Console Input Using The Scanner CLASS Slides prepared by Rose Williams, Binghamton University Kenrick Mock, University of Alaska.
Intro to Java Programming  A computer follows the instruction precisely and exactly.  Anything has to be declared and defined before it can be used.
Integer Division What is x? int x = 1729 / 100; Answer: 17.
Week 2 - Wednesday.  What did we talk about last time?  Data representation  Binary numbers  Types  int  boolean  double  char  String.
Input/Output in Java. Output To output to the command line, we use either System.out.print () or System.out.println() or System.out.printf() Examples.
Can we talk?. In Hello World we already saw how to do Standard Output. You simply use the command line System.out.println(“text”); There are different.
Miscellaneous topics Chapter 2 Savitch. Miscellaneous topics Standard output using System.out Input using Scanner class.
A Simple Java Program //This program prints Welcome to Java! public class Welcome { public static void main(String[] args) public static void main(String[]
Java Concepts Chapter 2 - Using Objects Mr. Smith AP Computer Science A.
CMSC 202 Java Console I/O. July 25, Introduction Displaying text to the user and allowing the user to enter text are fundamental operations performed.
Java 1.5 The New Java Mike Orsega Central Carolina CC.
String and Scanner CS 21a: Introduction to Computing I First Semester,
CS110 Programming Language I Lab 4: Control Statements I Computer Science Department Spring 2014.
FUNDAMENTALS 2 CHAPTER 2. OPERATORS  Operators are special symbols used for:  mathematical functions  assignment statements  logical comparisons 
Outline Character Strings Variables and Assignment Primitive Data Types Expressions Data Conversion Interactive Programs Graphics Applets Drawing Shapes.
CHAPTER 5 GC 101 Input & Output 1. INTERACTIVE PROGRAMS  We have written programs that print console output, but it is also possible to read input from.
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.
Java basics – part 2. Where are we Last week –Java basics Simple output program Started programs as calculators –Codelab –Lab procedures This week –Types,
Strings CSE 1310 – Introduction to Computers and Programming Vassilis Athitsos University of Texas at Arlington 1.
© 2007 Lawrenceville Press Slide 1 Chapter 4 Review Assignment Statement An assignment statement gives a value to a variable. Assignment can take several.
import java.util.Scanner; class myCode { public static void main(String[] args) { Scanner input= new Scanner(System.in); int num1; System.out.println(“Enter.
Interactive Programs Programs that get input from the user 1 In PowerPoint, click on the speaker icon then click the "Play" button to hear the narration.
Building Java Programs Chapter 4 Lecture 4-1: Scanner ; cumulative algorithms reading: 3.3 – 3.4, 4.2.
Copyright 2008 by Pearson Education Building Java Programs Chapter 3 Lecture 3-3: Interactive Programs w/ Scanner reading: self-check: #16-19.
Introduction to programming in java
Introduction to Computer Science and Object-Oriented Programming
Reading Parameters CSCI 201 Principles of Software Development Jeffrey Miller, Ph.D.
User Input ICS2O.
Building Java Programs
Introduction to programming in java
Input/Output.
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.
CSC1401 Input and Output (and we’ll do a bit more on class creation)
Compiling and Running a Java Program
Maha AlSaif Maryam AlQattan
Java Concepts Chapter 2 - Using Objects
TEMPERATURE CONVERSION
Chapter 3 Java Input/Output.
TK1114 Computer Programming
INPUT STATEMENTS GC 201.
Primitive Types Operators Basic input and output
Introduction to Classes and Methods
A+ Computer Science INPUT.
Introduction to Computer Science and Object-Oriented Programming
Chapter 3 Input/Output.
Object Oriented Programming
Module 3 Selection Structures 4/5/2019 CSE 1321 Module 3.
Building Java Programs
មជ្ឈមណ្ឌលកូរ៉េ សហ្វវែរ អេច អ ឌី
Building Java Programs
CSE Module 1 A Programming Primer
Building Java Programs
Optional Topic: User Input with Scanner
Presentation transcript:

TemperatureConversion Create a TemperatureConversion client class as follows: Enter a prompt for the Fahrenheit temperature in the console (using the Scanner class), and allow the user to enter the temperature there. Convert the temperature from Fahrenheit to Celsius Convert the temperature from Fahrenheit to Kelvin Print a message to the console that shows the conversion, such as: 50.0 F = 10.0 C 50.0 F = 283.15 K Do the same thing to allow the user to enter the temperature in Celsius and then print the conversion to Fahrenheit and Kelvin. 0.0 C = 32.0 F 0.0 C = 273.15 K Do the same thing to allow the user to enter the temperature in Kelvin and then print the conversion to Fahrenheit and Celsius. 283.15 K = 50.0 F 283.15 K = 10.0 C The conversion formulas can easily be found on the internet Please try these conversions where Fahrenheit = 50 and Celsius = 0. Also try a couple of other examples of your choice to verify that the program is working correctly.

Terminal I/O for Different Data types Scanner class: reads from the input stream **** new for Java 5.0, but not tested on AP exam Here are the methods in the Scanner class: METHOD DESCRIPTION double nextDouble() Returns the first double in the input line. Leading and trailing spaces are ignored. int nextInt() Returns the first integer in the input line. Leading and trailing spaces are ignored. String nextLine() Returns the input line, including leading and trailing spaces. Warning: A leading newline is returned as an empty string.

Terminal I/O for Different Data types The following program illustrates the major features of terminal I/O: import java.util.Scanner;   public class TestTerminalIO { public static void main (String [] args) { Scanner in = new Scanner(System.in); System.out.print ("Enter your name (a string): "); String name = in.nextLine(); System.out.print("Enter your age (an integer): "); int age = in.nextInt(); System.out.print("Enter your weight (a double): "); double weight = in.nextDouble();

Terminal I/O for Different Data types System.out.println ("Greetings " + name + ". You are " + age + " years old and you weigh " + weight + " pounds."); }