LAB 3 Part 1 OBJECTS & CLASSES



Similar documents
LAB4 Making Classes and Objects

Handout 3 cs180 - Programming Fundamentals Spring 15 Page 1 of 6. Handout 3. Strings and String Class. Input/Output with JOptionPane.

Appendix K Introduction to Microsoft Visual C++ 6.0

1.1 Installing Protégé You can follow the steps below to download and install Protégé from the source.

LAB 1. Familiarization of Rational Rose Environment And UML for small Java Application Development

CS106A, Stanford Handout #38. Strings and Chars

Appendix A Using the Java Compiler

Eventia Log Parsing Editor 1.0 Administration Guide

Primavera P6 Professional Windows 8 Installation Instructions. Primavera P6. Installation Instructions. For Windows 8 Users

Installing (1.8.7) 9/2/ Installing jgrasp

Appendix M: Introduction to Microsoft Visual C Express Edition

Goal: Practice writing pseudocode and understand how pseudocode translates to real code.

This feature allows you to convert a collection of PDFs into EndNote references using the Digital Object Identifier (DOI).

Configuring Thunderbird for Flinders Mail at home.

Creating a Java application using Perfect Developer and the Java Develo...

A Practical Guide to Test Case Types in Java

Practice Fusion API Client Installation Guide for Windows

Using SSH Secure File Transfer to Upload Files to Banner

Bulk Downloader. Call Recording: Bulk Downloader

File Management With Windows Explorer

File Share Service User guide

Sample CSE8A midterm Multiple Choice (circle one)

Fireworks 3 Animation and Rollovers

Hypercosm. Studio.

AP Computer Science Java Mr. Clausen Program 9A, 9B

Python Loops and String Manipulation

Part 1 Foundations of object orientation

AXIS 70U - Using Scan-to-File

How to Run Java Programs Using Microsoft J++

Perform this procedure when you need to add a recurring payment option, or when you need to change or withdraw it.

How to Backup and FTP your SQL database using E2.

Figure 1.9 Migrated Tally.ERP 9 data

How to use the Eclipse IDE for Java Application Development

Spambrella SaaS Encryption Enablement for Customers, Domains and Users Quick Start Guide

How to Copy A SQL Database SQL Server Express (Making a History Company)

Install Java Development Kit (JDK) 1.8

2 Getting Started with jgrasp 2.0

How to Resolve Login Errors with Business Objects XI

Installing the Android SDK

EMC Documentum Composer

For Introduction to Java Programming, 5E By Y. Daniel Liang

Java Software Development Kit (JDK 5.0 Update 14) Installation Step by Step Instructions

Computer Programming I

JMETER - MONITOR TEST PLAN

You must have at least Editor access to your own mail database to run archiving.

Download and Installation Instructions. Android SDK and Android Development Tools (ADT) Microsoft Windows

Setting Up My Business Account - Wireless

HTML Form Widgets. Review: HTML Forms. Review: CGI Programs

Backing Up and Restoring the Database

Supplement I.B: Installing and Configuring JDK 1.6

Online Valuation Portal User Guide

SaaS Encryption Enablement for Customers, Domains and Users Quick Start Guide

Windows Server 2003 Logon Scripts Paul Flynn

Web Services using Tomcat and Eclipse

5.4.8 Optional Lab: Managing System Files with Built-in Utilities in Windows 7

Lab Experience 17. Programming Language Translation

X1 Professional Client

Information Technology Services

Getting started with the Asset Import Converter. Overview. Resources to help you


Netbeans IDE Tutorial for using the Weka API

Installing Java. Table of contents

Notepad++ The COMPSCI 101 Text Editor for Windows. What is a text editor? Install Python 3

Auto-Archiving your s in Outlook

Windows XP Managing Your Files

A-PDF Scan and Split Scan and split pdf utility. User Documentation

CONFIGURATION AND APPLICATIONS DEPLOYMENT IN WEBSPHERE 6.1

Secure Messaging Quick Reference Guide

Create a Web Service from a Java Bean Test a Web Service using a generated test client and the Web Services Explorer

CS 170 Java Programming 1. Welcome to CS 170. All about CS 170 The CS 170 Online Materials Java Mechanics: Your First Program

Open Directory. Contents. Before You Start 2. Configuring Rumpus 3. Testing Accessible Directory Service Access 4. Specifying Home Folders 4

CS 1133, LAB 2: FUNCTIONS AND TESTING

Python Lists and Loops

Computer Programming In QBasic

Memory Management Simulation Interactive Lab

WA Continuous Integration with Jenkins- CI, Maven and Nexus. Classroom Setup Guide. Web Age Solutions Inc. Web Age Solutions Inc.

Using Websense Data Endpoint Client Software

Download and Installation Instructions. Java JDK Software for Windows

USING STUFFIT DELUXE THE STUFFIT START PAGE CREATING ARCHIVES (COMPRESSED FILES)

Canto Integration Platform (CIP)

Tutorial - How to Use Lotus Domino Web Services in Java Development

UML Class Diagrams (1.8.7) 9/2/2009

HP Operations Orchestration Software

Introduction to Java Applications Pearson Education, Inc. All rights reserved.

Using Salvage to recover accidently deleted or overwritten files

Users Guide. V1.0 Page 1

Mobile Labs Plugin for IBM Urban Code Deploy

Payroll Import. Version Main screen for Payroll Import.

Purchase Agent Installation Guide

Using ELM Reports in WhatsUp Gold. This guide provides information about configuring ELM reports in WhatsUp Gold v15.0

HIC.SOAP Network User Instructions last updated June 22, :39 AM

Transcription:

LAB 3 Part 1 OBJECTS & CLASSES Objective: In the lecture you learnt about classes and objects. The main objective of this lab is to learn how to instantiate the class objects, set their properties and access their methods, how to access other classes stored on other directory by setting classpath. You will also play with String class in this lab. String The String class represents character strings. All string literals in Java programs, such as "abc", are implemented as instances of this class. The class String includes methods for examining individual characters of the sequence, for comparing strings, for searching strings, for extracting substrings, and for creating a copy of a string with all characters translated to uppercase or to lowercase Here are some more examples of how strings can be used: // Show String abc in Interaction Pane System.out.println( abc ); // Show String abccde in Interaction Pane String cde= cde ; System.out.println( abc +cde); // Show String c in Interaction Pane String c = abc.substring(2,3); System.out.println(c); ClassPath ClassPath tells JDK tools and applications where to find third-party and user-defined classes i.e. classes that are not Java extensions or part of the Java platform. You only need to set the class path when you want to load a class that's not in the current directory or in any of its subdirectories, and not in a location specified by the extensions mechanism. DrJava had made this thing very simple. In DrJava there is an option named Project Properties to set and remove the classpath in Project menu. 1

When we click this option, another form will open. In this form you will find various kinds of options available to set the classpath and to remove the existing classpath. Now to add classpath of an existing class click Add button. 2

Now give the address of the folder which contains classes as shown above. Click select to select the folder. Now click OK.Now this class is available i.e. we can instantiate this class and use all its functionality. Not only this class is available to us but any class which is in this folder is accessible. We can instantiate it and use it. Alternate way of setting ClassPath Hint: This is an alternate way, while using DrJava don t have to follow these settings. The class path can be set using either the -classpath option when calling a JDK tool (the preferred method) or by setting the CLASSPATH environment variable. C :> set CLASSPATH=classpath1; classpath2... Class paths to the.jar,.zip or.class files. Each classpath should end with a filename or directory depending on what you are setting the class path to: 3

For a.jar or.zip file that contains.class files, the class path ends with the name of the.zip or.jar file. For.class files in an unnamed package, the class path ends with the directory that contains the.class files. For.class files in a named package, the class path ends with the directory that contains the "root" package (the first package in the full package name). Following Error will occur if we don t set the classpath. But after setting class path Unset CLASSPATH by using: C :> set CLASSPATH= Exercise 1. Display your Name using String class. 2. Create a String object named country and initialize it with PAKISTAN. a) Determine the length of this word using length() method. b) Determine the index of letter S by using indexof() method. c) Determine the index of IST by using indexof() method. d) Determine the last index of letter A by using lastindexof() method. e) Convert this String into lowercase by using tolowercase(). f) Convert this lowercase String into uppercase by using touppercase(). 3. Make a project by clicking Project Menu and selecting New option. Enter a name for your project and click Save. DrJava will display Project Properties window, set classpath to World.class and Turtle.class as shown in the start of the tutorial. 4

Hint: To make sure that you have made the project correctly and added the class paths of Turtle.class and World.class in the right way type the following in Interaction Pane: System.out.println(new World()); OR simply make the object the the World class World w = new World(); A window should appear as shown below, indicating that the classes have been added accurately. 4. Instantiate World class. Now make two objects named sqr, rect of Turtle class. Now draw square and, rectangle using these turtles. For square take x=200 and for rectangle length=180 and width=90. Hint: // Instantiate World object World world = new World(); //Instantiate Turtle class and pass object or World class as parameter. Turtle turtle1= new Turtle(world); // You can also give coordinates to draw turtle at a specific position Turtle turtle2= new Turtle(a,b,world); Where a and b are x and y coordinated on the window. By entering the code: World world= new World(); Turtle turtle1= new Turtle(10,10,world); Turtle turtle2= new Turtle(50,50,world); Turtle turtle3= new Turtle(77,77,world); Following Window is displayed 5

Use following methods to draw Rectangle and Square. Turtle1.turnLeft(); Turtle1.turnRght(); Turtle1.forward(x); // To Move Left. // To Move Right // To Move x steps The final result should be something like this 5. Write the word LOOP with 4 different Turtles using methods learned in above question. 6

7