CS 240 – Computer Programming I Lab

Slides:



Advertisements
Similar presentations
Computer Science & Engineering 2111 Text Functions 1CSE 2111 Lecture-Text Functions.
Advertisements

More Java Syntax. Scanner class Revisited The Scanner class is a class in java.util, which allows the user to read values of various types. There are.
ECS15 for and sequence. Comments  Another way to repeat.
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!");
TA: Nouf Al-Harbi NoufNaief.net :::
1 Lab Session-VI CS121 Fall 2000 l HW#2 Assigned l Multiple Choice Selectors l The While Loop l Switch-Case-Break Exercise l The Counter Controlled Loops.
CS 241 – Computer Programming II Lab Kalpa Gunaratna –
CS 240 – Computer Programming I Lab Kalpa Gunaratna –
CS 241 – Computer Programming II Lab Kalpa Gunaratna –
CS 240 – Computer Programming I Lab Kalpa Gunaratna –
CS 241 – Computer Programming II Lab Kalpa Gunaratna –
CPS 2231 Computer Organization and Programming Instructor: Tian (Tina) Tian.
CS0007: Introduction to Computer Programming File IO and Recursion.
Lists and More About Strings CS303E: Elements of Computers and Programming.
CS 241 – Computer Programming II Lab Kalpa Gunaratna –
CS 241 – Computer Programming II Lab Kalpa Gunaratna –
Console Input & Output CSS 161: Fundamentals of Computing Joe McCarthy 1.
Lecture 2: Classes and Objects, using Scanner and String.
Computer Programming 2 Lab(1) I.Fatimah Alzahrani.
Using Data Within a Program Chapter 2.  Classes  Methods  Statements  Modifiers  Identifiers.
Computer Labs Orientation September 2003 Prepared by Computer Services.
CS 1150 – Lab #3 – Representing Numbers TA – Sanjaya Wijeratne – Web Page -
Lab5 Please submit the lab before you leave Please include at a minimum your name, the date, and the lab- program number at the top of the program as a.
Conditional Statements.  Checking if input is a number  Radio buttons  Check boxes 2.
Representing Characters in a computer Pressing a key on the computer a code is generated that the computer can convert into a symbol for displaying or.
CS 240 – Computer Programming I Lab Kalpa Gunaratna –
CSE 1341 Honors Note Set 05 Professor Mark Fontenot Southern Methodist University.
CS 240 – Computer Programming I Lab Kalpa Gunaratna –
Validation final steps Stopping gaps being entered in an input.
©2016 Pearson Education, Inc. Upper Saddle River, NJ. All Rights Reserved. CSC 110 – INTRO TO COMPUTING - PROGRAMMING String and Scanner Objects.
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.
CS 240 – Computer Programming I Lab Kalpa Gunaratna –
Keyboard and Screen I/O (Input/Output). Screen Output  System.out is an object that is part of the Java language. (Don’t worry yet about why there is.
Lab 9 Exercises.
Copyright 2008 by Pearson Education Building Java Programs Chapter 3 Lecture 3-3: Interactive Programs w/ Scanner reading: self-check: #16-19.
Intelligent Data Systems Lab. Department of Computer Science & Engineering Practices 컴퓨터의 개념 및 실습 4 월 11 일.
CSC 1051 – Data Structures and Algorithms I Dr. Mary-Angela Papalaskari Department of Computing Sciences Villanova University Course website:
CS 241 – Computer Programming II Lab
CSS 290: Video Games and Computer Programming
Basic concepts of C++ Presented by Prof. Satyajit De
CS 241 – Computer Programming II Lab
CS 240 – Computer Programming I Lab
Text File Input/Output
Review Materials I (T) Subject : T0016 – ALGORITHM AND PROGRAMMING
Reading from a file A file is typically stored on your computers hard drive. In the simplest case, lets just assume it is text. For a program to use.
Hours question Given a file hours.txt with the following contents:
CS305J Introduction to Computing
Text File Input/Output
CSC 108H: Introduction to Computer Programming
Building Java Programs
Representing Characters
Program Style Console Input and Output
CSS 161 Fundamentals of Computing Introduction to Computers & Java
Use proper case (ie Caps for the beginnings of words)
CSS 161: Fundamentals of Computing
CS 1430: Programming in C++ No time to cover HiC.
September 9, 2008 Lecture 5 – More IO.
SELECTION STATEMENTS (2)
Building Java Programs
CS 336/536: Computer Network Security Fall 2015 Nitesh Saxena
Input from the Console This video shows how to do CONSOLE input.
CS150 Introduction to Computer Science 1
Additional Topics in VB.NET
elementary programming
September 9, 2008 Lecture 5 – More IO.
CS 336/536: Computer Network Security Fall 2014 Nitesh Saxena
Building Java Programs
String Encodings and Penny Math
CS 1111 Introduction to Programming Spring 2019
PYTHON - VARIABLES AND OPERATORS
Presentation transcript:

CS 240 – Computer Programming I Lab Kalpa Gunaratna – kalpa@knoesis.org http://knoesis.wright.edu/researchers/kalpa/

Contact Contact by e-mail Office hours kalpa@knoesis.org 376 Joshi Mondays & Wednesday 3:00 pm – 4:00 pm

Reading a file Scanner class can be used to read a file as well as getting user input from key board. How to create a file. File <name> = new File(<file name>); <file name> is the string of the file name (for example, “example.txt”). Scanner input = new Scanner(System.in); System.in can be replaced with a valid file File myFile = new File("example.txt");

Convert a String to upper case In the String class there is a method to convert a string to upper case.

In lab Create a file named randomCharacters.txt and have a single line with lower case letters and numbers. Get the file name from the user and use that file name to read the file. Convert all the strings into upper case and print the resultant string into console. Create a method each for getting file name, reading the file and converting the line to upper case. Write javadocs for your methods.

Writing to a file PrintWriter class could be used. Create a File instance and then use that instance for PrintWriter. PrintWriter <name> = new PrintWriter(<file>); If the file is used to write back, strings will be appended. File myFile = new File(“example.txt”); PrintWriter myWriter = new PrintWriter(myFile); myWriter.print(“test”); myWriter.println(“testing”);

Checking a character is a digit In Character class, there is a method isDigit(<character>) which returns true or false. Example: Character.isDigit(‘4’) returns true. There is also a method to convert a lower case character in to a upper case character. As an exercise for you, type Character and then . And see what method you can use by reading the javadcos available. If you do not see the javadoc after some time, go to the “.” after Character (you typed) and press <ctrl> + <space> and you will get the list of available methods for that class.

Post lab Read the String from file. Convert characters into upper case and each digit is replaced with a “*”. Write back the converted string in to the file. Use proper javadocs and comments. Read the rubrics for grading and make sure you follow them.