Değişik Parametreli Nesne Tanımı 1. Object with parameter Class Box { double width; double height; double depth; Box(Box ob) { width=ob.width; height=ob.height;

Slides:



Advertisements
Similar presentations
UNIT II DATA TYPES OPERATORS AND CONTROL STATEMENT 1.
Advertisements

I/O Basics 12 January 2014Smitha N. Pai, CSE Dept.1.
Continuation of chapter 6…. Nested while loop A while loop used within another while loop is called nested while loop. Q. An illustration to generate.
1 Streams and Input/Output Files Part 2. 2 Files and Exceptions When creating files and performing I/O operations on them, the systems generates errors.
1 Classes and Objects in Java Parameter Passing, Delegation, Visibility Control, and Object Cleanup.
1 Streams and Input/Output Files Part 3. 2 Handling Primitive Data Types The basic input and output streams provide read/write methods that can be used.
Taking Input Java Md. Eftakhairul Islam
Programming for Beginners Martin Nelson Elizabeth FitzGerald Lecture 3: Flow Control I: For Loops.
Methods and Formatted Output Chapter 4. Overview Breaking down a big program into small methods. Formatting output – using printf – using DecimalFormat.
Input review If review Common Errors in Selection Statement Logical Operators switch Statements Generating Random Numbers practice.
1 StringBuffer & StringTokenizer Classes Chapter 5 - Other String Classes.
1 public class Newton { public static double sqrt(double c) { double epsilon = 1E-15; if (c < 0) return Double.NaN; double t = c; while (Math.abs(t - c/t)
Introduction to Computer Science Robert Sedgewick and Kevin Wayne Recursive Factorial Demo pubic class Factorial {
1 Arrays An array is a special kind of object that is used to store a collection of data. The data stored in an array must all be of the same type, whether.
Lecture 15: I/O and Parsing
Simple Programs Simple Strings Writing some programs Only in Parameters? I/O Gadget.
Computer Programming Lab(7).
Chapter 10 Ch 1 – Introduction to Computers and Java Streams and File IO 1.
MOD III. Input / Output Streams Byte streams Programs use byte streams to perform input and output of 8-bit bytes. This Stream handles the 8-bit.
Multi-Dispatch in the Java Virtual Machine TM What is (dynamic) multi-dispatch? Method selection based on the types of … all (or more than one) of the.
The Point Class public class Point { public double x; public double y; public Point(double x0, double y0) { x = x0; y = y0; } public double distance(Point.
Graohics CSC 171 FALL 2001 LECTURE 16. History: COBOL Conference on Data System Languages (CODASYL) - led by Joe Wegstein of NBS developed the.
1 Calling within Static method /* We can call a non static method from a static method but by only through an object of that class. */ class Test1{ public.
Java Programming Abstract classes and Interfaces.
Inheritance // A simple class hierarchy. // A class for two-dimensional objects. class TwoDShape { double width; double height; void showDim() { System.out.println("Width.
Objects contains data and methods Class – type of object Create class first Then object or instance String – defined class String s; // creates instance.
Exercise 1 Suppose C is a class that implements interfaces I and J. Which of the following Requires a type cast? C c = ……? I i = …..? J j = …..? c =
INTERFACES IN JAVA 1.Java Does not support Multiple Inheritance directly. Multiple inheritance can be achieved in java by the use of interfaces. 2.We need.
Övning 4. Repetition göra egna klasser class Rektangel { private double längd; private double bredd; public Rektangel(double l, double b) { this.längd.
Files from Ch4. File Input and Output  Reentering data all the time could get tedious for the user.  The data can be saved to a file. Files can be input.
James Tam Simple File Input And Output Types of Java Files Simple File Output in Java Simple File Input in Java.
1 Fall 2009ACS-1903 The break And continue Statements a break statement can be used to abnormally terminate a loop. use of the break statement in loops.
James Tam Simple file handling in Java Simple File Input And Output Types of Java files Simple file output in Java Simple file input in Java.
Unit 201 FILE IO Types of files Opening a text file for reading Reading from a text file Opening a text file for writing/appending Writing/appending to.
1 Text File I/O  I/O streams  Opening a text file for reading  Closing a stream  Reading a text file  Writing and appending to a text file.
James Tam Simple File Input And Output Types of Java Files Simple File Output in Java Simple File Input in Java.
Methods CSC 171 FALL 2004 LECTURE 3. Methods Variables describe static aspects – “nouns” Methods describe dynamic aspects – “verbs”, “behaviors” – Methods.
1 Text File I/O Overview l I/O streams l Opening a text file for reading l Reading a text file l Closing a stream l Reading numbers from a text file l.
1 Streams Overview l I/O streams l Opening a text file for reading l Reading a text file l Closing a stream l Reading numbers from a text file l Writing.
Java I/O – what does it include? Command line user interface –Initial arguments to main program –System.in and System.out GUI Hardware –Disk drives ->
Reading/Writing Files, Webpages CS2110, Recitation 10 1.
Two Ways to Store Data in a File Text format Binary format.
Chapter 10 Exceptions and File I/O. © 2004 Pearson Addison-Wesley. All rights reserved10-2 Exceptions Exception handling is an important aspect of object-oriented.
Session 05 Java Strings and Files. Exercise Complete the “quick-and-dirty” class CharacterCounter containing only a main() method that displays the number.
5-Oct-15 Air Force Institute of Technology Electrical and Computer Engineering Object-Oriented Programming Design Topic : Streams and Files Maj Joel Young.
Very Brief Introduction to Java I/O with Buffered Reader and Buffered Writer.
Console Input. So far… All the inputs for our programs have been hard-coded in the main method or inputted using the dialog boxes of BlueJ It’s time to.
Chapter 9 1 Chapter 9 – Part 1 l Overview of Streams and File I/O l Text File I/O l Binary File I/O l File Objects and File Names Streams and File I/O.
Java Arrays …………. Java Arrays …………. * arrays are objects in Java * arrays are objects in Java * an array variable is a reference * an array variable is.
Overloading There is another aspect to polymorphism: Overloading Overloading is not overriding. In Turkish: Overridding: eskisini (geçersiz kılmak) Overloading:
File IO Basics By Dan Fleck Coming up: Data Streams.
Chapter 15 Text Processing and File Input/Output Lecture Slides to Accompany An Introduction to Computer Science Using Java (2nd Edition) by S.N. Kamin,
CSI 3125, Preliminaries, page 1 Java I/O. CSI 3125, Preliminaries, page 2 Java I/O Java I/O (Input and Output) is used to process the input and produce.
Strings and File I/O. Strings Java String objects are immutable Common methods include: –boolean equalsIgnoreCase(String str) –String toLowerCase() –String.
CS202 Java Object Oriented Programming Input and Output Chengyu Sun California State University, Los Angeles.
Methods Matthew Harrison. Overview ● There are five main aspects of methods... ● 1) Modifiers – public, private ● 2) Method Name ● 3) Parameters ● 4)
IO in java.
JAVA API Strings, I/O, Formatting and Parsing
Strings and File I/O.
תרגול מס' 5: IO (קלט-פלט) זרמי קלט וזרמי פלט ((Input & Output Streams,
Dosyalar.
הרצאה 12: קבצים וחריגות (Exceptions)
תרגול מס' 5: IO (קלט-פלט) זרמי קלט וזרמי פלט ((Input & Output Streams,
Reading and Writing Text Files
Unit-2 Objects and Classes
Java Lesson 36 Mr. Kalmes.
class PrintOnetoTen { public static void main(String args[]) {
មជ្ឈមណ្ឌលកូរ៉េ សហ្វវែរ អេច អ ឌី
David Davenport Spring 2005
class Box { double width; double height; double depth; }
Presentation transcript:

Değişik Parametreli Nesne Tanımı 1

Object with parameter Class Box { double width; double height; double depth; Box(Box ob) { width=ob.width; height=ob.height; depth=ob.depth; } Box(double w, double h, double d) { width=w; height=h; depth=d; } Box( ) { width=-1; height=-1; depth=-1; } Box(double len) { width=height=depth=len; } double volume( ) { return width*height*depth; } Class OverloadCons2 { public static void main(String args[]) { Box mybox1=new Box(10,20,15); Box mybox2=new Box( ); Box mycube= new Box( 7); Box myclone=new Box(mybox1); 2

double vol; vol=mybox1.volume( ); System.out.println(“Volume of mybox1 is “ + vol); vol=mybox2.volume( ); System.out.println(“Volume of mybox2 is “ + vol); vol=mycube.volume( ); System.out.println(“Volume of mycube is “ + vol); vol=myclone.volume( ); System.out.println(“Volume of myclone is “ + vol); } 3

Sıradan Erişimli Dosyadan Bilgi Okuma 4

impot java.io.*; class FileReaderDemo { public static void main (String args[]) throws Exception { FileReader fr=new FileReader(“FileReaderDemo.java”); BufferedReader br=new BufferedReader(fr); String s; while(( s=br.readLine( )) != null) { System.out.println(s); } fr.close; } 5

Sıradan Erişimli Dosyaya Bilgi Yazma 6

impot java.io.*; class FileWriterDemo { public static void main (String args[]) throws Exception { String source=”Now is the time for all good men\n” + “to come to the aid of their country\n” + “ and pay their due taxes.”; char buffer[]= new char[source.length( )]; source.getChars(0,source.length( ),buffer,0); FileWriter f0=new FileWriter(“file1.txt”); for(int i=0; i<buffer.length; i++) { f0.write(buffer[i]); } f0.close( ); FileWriter f1=new FileWriter(“file2.txt”); f1.write(buffer); f1.close( ); } 7