Roll Number. Common to II Year B.E.CSE & EIE INTERNAL ASSESSMENT TEST - I. Credit 3 R-2017

Similar documents
Introduction to Programming Using Java (98-388)

Sri Vidya College of Engineering & Technology

Java Professional Certificate Day 1- Bridge Session

CS 231 Data Structures and Algorithms, Fall 2016

CSC 1214: Object-Oriented Programming

Darshan Institute of Engineering & Technology for Diploma Studies Unit 3

H212 Introduction to Software Systems Honors

Fall CS 101: Test 2 Name UVA ID. Grading. Page 1 / 4. Page3 / 20. Page 4 / 13. Page 5 / 10. Page 6 / 26. Page 7 / 17.

Discover how to get up and running with the Java Development Environment and with the Eclipse IDE to create Java programs.

1 Shyam sir JAVA Notes

Inherit a class, you simply incorporate the definition of one class into another by using the extends keyword.

University of Cape Town ~ Department of Computer Science. Computer Science 1015F ~ 2007

CS212 Midterm. 1. Read the following code fragments and answer the questions.

JAVA PROGRAMMING LAB. ABSTRACT In this Lab you will learn to define and invoke void and return java methods

ASSIGNMENT NO 13. Objectives: To learn and understand concept of Inheritance in Java

AP Computer Science Chapter 10 Implementing and Using Classes Study Guide

Java: Classes. An instance of a class is an object based on the class. Creation of an instance from a class is called instantiation.

Third Year Diploma Courses in Computer Science & Engineering, Computer Engineering, Computer Technology & Information Technology Branch.

CS/B.TECH/CSE(OLD)/SEM-6/CS-605/2012 OBJECT ORIENTED PROGRAMMING. Time Allotted : 3 Hours Full Marks : 70

1. Find the output of following java program. class MainClass { public static void main (String arg[])

ICSE Class 10 Computer Applications ( Java ) 2010 Solved Question...

Language Features. 1. The primitive types int, double, and boolean are part of the AP

Interpreted vs Compiled. Java Compile. Classes, Objects, and Methods. Hello World 10/6/2016. Python Interpreted. Java Compiled

The Java language has a wide variety of modifiers, including the following:

Sequence structure. The computer executes java statements one after the other in the order in which they are written. Total = total +grade;

JAVA: A Primer. By: Amrita Rajagopal

VALLIAMMAI ENGINEERING COLLEGE

COMPUTER APPLICATIONS

Example: Monte Carlo Simulation 1

For that purpose, java provides control structures that serve to specify what has to be done by our program, when and under which circumstances.

McGill University School of Computer Science COMP-202A Introduction to Computing 1

Java provides a rich set of operators to manipulate variables. We can divide all the Java operators into the following groups:

CS111: PROGRAMMING LANGUAGE II

COE318 Lecture Notes Week 3 (Week of Sept 17, 2012)

Computer Science II (20073) Week 1: Review and Inheritance

The Java programming environment. The Java programming environment. Java: A tiny intro. Java features

OOPs Concepts. 1. Data Hiding 2. Encapsulation 3. Abstraction 4. Is-A Relationship 5. Method Signature 6. Polymorphism 7. Constructors 8.

CS 101 Spring 2007 Midterm 2 Name: ID:

Zhifu Pei CSCI5448 Spring 2011 Prof. Kenneth M. Anderson

Computer Science II (20082) Week 1: Review and Inheritance

STRUCTURING OF PROGRAM

Core JAVA Training Syllabus FEE: RS. 8000/-

CS/B.TECH/CSE(New)/SEM-5/CS-504D/ OBJECT ORIENTED PROGRAMMING. Time Allotted : 3 Hours Full Marks : 70 GROUP A. (Multiple Choice Type Question)

CONTENTS: Compilation Data and Expressions COMP 202. More on Chapter 2

CS 6456 OBJCET ORIENTED PROGRAMMING IV SEMESTER/EEE

DM503 Programming B. Peter Schneider-Kamp.

Course Text. Course Description. Course Objectives. StraighterLine Introduction to Programming in C++

Unit 3 INFORMATION HIDING & REUSABILITY. Interface:-Multiple Inheritance in Java-Extending interface, Wrapper Class, Auto Boxing

Object Oriented Programming with Java. Unit-1

3. Convert 2E from hexadecimal to decimal. 4. Convert from binary to hexadecimal

Character Stream : It provides a convenient means for handling input and output of characters.

Introduction to Java

Chapter 6 Introduction to Defining Classes

CSCI 136 Data Structures & Advanced Programming. Lecture 3 Fall 2018 Instructors: Bill & Bill

MIDTERM REVIEW. midterminformation.htm

Self-test Java Programming

Software Practice 1 - Basic Grammar Basic Syntax Data Type Loop Control Making Decision

Place your name tag here

Give one example where you might wish to use a three dimensional array

Outline. Parts 1 to 3 introduce and sketch out the ideas of OOP. Part 5 deals with these ideas in closer detail.

SECTION A (40 Marks) Attempt all questions. (a) What is inheritance? [2] (c) State the number of bytes occupied by char and int data types.


Programming Language Basics

Syllabus & Curriculum for Certificate Course in Java. CALL: , for Queries

المملكة العربية السعودية وزارة التعليم العالى

Java Programming for Selenium

Answer1. Features of Java

COMPUTER APPLICATIONS

Exam 1 Prep. Dr. Demetrios Glinos University of Central Florida. COP3330 Object Oriented Programming

COMP-202: Foundations of Programming. Lecture 4: Flow Control Loops Sandeep Manjanna, Summer 2015

TeenCoder : Java Programming (ISBN )

Java Programming Language. 0 A history

S.E. Sem. III [CMPN] Object Oriented Programming Methodology

Class, Variable, Constructor, Object, Method Questions

CO Java SE 8: Fundamentals

Java Programming. MSc Induction Tutorials Stefan Stafrace PhD Student Department of Computing

Outline. Overview. Control statements. Classes and methods. history and advantage how to: program, compile and execute 8 data types 3 types of errors

Operators and Expressions

Object-Oriented Programming

Array. Array Declaration:

9 Working with the Java Class Library

Handout 7. Defining Classes part 1. Instance variables and instance methods.

What is Inheritance?

Day 2 : Intermediate Concepts 1 Examples

Jump Statements. The keyword break and continue are often used in repetition structures to provide additional controls.

Creating Classes and Objects

bitwise inclusive OR Logical logical AND && logical OR Ternary ternary? : Assignment assignment = += -= *= /= %= &= ^= = <<= >>= >>>=

INDEX. A SIMPLE JAVA PROGRAM Class Declaration The Main Line. The Line Contains Three Keywords The Output Line

Array. Prepared By - Rifat Shahriyar

Some Sample AP Computer Science A Questions - Solutions

Chapter 4: Control Structures I

Lecture 02, Fall 2018 Friday September 7

Software Practice 1 Basic Grammar

Jump Statements. The keyword break and continue are often used in repetition structures to provide additional controls.

Java Bytecode (binary file)

PROGRAMMING FUNDAMENTALS

Text User Interfaces. Keyboard IO plus

Chapter 6 Lab Classes and Objects

Java Identifiers, Data Types & Variables

CS11 Java. Fall Lecture 1

Transcription:

Roll Number ERODE SENGTHAR ENGINEERING COLLEGE PERDURI, ERODE 638 057 (Accredited by NBA, Accredited by NAAC with A grade, Accredited by IE (I), Kolkotta, Permanently affiliated to Anna University, Chennai and ISO 9001:2008 certified.) Credit 3 Common to II Year B.E.CSE & EIE INTERNAL ASSESSMENT TEST - I R-2017 Course Code : CS8392 Course Name : Object Oriented Programming Date : 25-07-2018 SET 1 Answer Key Max Marks : 50 Time : 11.00 A.M. to 12.30 P.M. ANSWER ALL THE QUESTIONS Duration : 1.30 Hours 1. 2. 3. 4. 5. 6. PART A ( 10 X 2 = 20 Marks) List the features of Java. Simple, Object Oriented, Multi threaded, Portable, High Performance, Architecture neutral, distributed and interpreted language How java is platform independent? Java programs are compiled to byte code. This byte code is set of optimized instruction that are designed to be executed in all the platform by the JVM which contains Java Interpreter Differentiate Structure in C and Class in java. Structure is a collection various data items. It does not contain any methods. Class is a collection of different data items and methods No access specifier is used in structure. Class uses access specifier for data protection. Structure variable can be used to access structure member. Objects can be created to access Class members Write the syntax to create one dimensional array in java. To Create one dimensional integer array int a[] = new int[10]; The above declaration creates array a with size 10. What is type Conversion and Casting? Type conversion : Process of converting expression result into particular data type. This will be performed automatically. Type Casting: Process of converting one data type into another. The following example shows how to convert double to integer value int a; double d=12.6; a=(int)d; Write the output of the following java code segment. If any error then write the details of error. class test int a; double b; String str; void display() System.out.println( The Integer value is +a); System.out.println( The Double value is +b); System.out.println( The String value is +str); Blooms Level COs

7. 8. 9. 10 11. a. class example public static void main(string s[]) test obj= new test(); obj.display(); Output The Integer value is 0 The Double value is 0.0d The String value is null What is access specifier? Give example. Access specifiers are keywords that can be used to assign access rights (scope) to class members (variables and methods). There are four access specifier in java public, private, protected and default. The following code segment shows how to use access specifier private int a; What is encapsulation in OOP? Process of hiding or combining data and methods in a single unit. The unit is called class Write notes on javadoc. Documentation facility available in java for program documentation. Javadoc generated document in HTML format. Write the significance of Unicode character set. Unicode is a 16 bit character set followed in java. Unicode support multi language during software development. PART B (2 X 15 = 30 Marks) i) Explain the various control statement of java. (7) Java s program control statements can be put into the following categories Selection, iteration and jump statement Selection Statement If If-else If else if Nested if Switch Iteration Statement For loop While loop Do while loop Nested loop Jump statement Break Labeled break continue ii) Explain the following with suitable example. Static variable, Static Methods, Static Block (8) It is possible to create a member that can be used by itself, without reference to a specific instance. To create such a member, precede its declaration with the keyword static. When a member is declared static, it can be accessed before any objects of its class are created, and without reference to any object. You can declare

both methods and variables to be static. Methods declared as static have several restrictions: They can only call other static methods. They must only access static data. We can declare a static block that gets executed exactly once, when the class is first loaded. The following example shows a class that has a static method, some static variables, and a static initialization block: class UseStatic static int a = 3; static int b; static void meth(int x) System.out.println("x = " + x); System.out.println("a = " + a); System.out.println("b = " + b); static System.out.println("Static block initialized."); b = a * 4; public static void main(string args[]) meth(42); OR Explain Object and Classes with suitable example. (15) Class A class is a template for an object, and an object is an instance of a class. Because an object is an instance of a class. A class is declared by use of the class keyword. A general form of a class definition is class classname type instance-variable1; type instance-variable2; b. type instance-variablen; type methodname1(parameter-list) // body of method type methodname2(parameter-list) // body of method //... type methodnamen(parameter-list) // body of method The data, or variables, defined within a class are called instance variables. The code is contained within methods. Collectively, the methods and variables defined within a class are called members of the class. Declaring Objects First, you must declare a variable of the class type. This variable does not define an object. Instead, it is simply a variable that can refer to an object. Second, we must

acquire an actual, physical copy of the object and assign it to that variable. We can do this using the new operator. The new operator dynamically allocates (that is, allocates at run time) memory for and object and returns a reference to it. Example: ABC obj= new ABC() ABC Class Obj object name new keyword ABC() Constructor i) How user defined packages are created and accessed in java? Explain with example.(7) Packages are container for class Defining a Package To create a package is quite easy: simply include a package command as the first statement in a Java source file. Any classes declared within that file will belong to the specified package. This is the general form of the package statement: package pkg; Here, pkg is the name of the package. For example, the following statement creates a package called MyPackage. package MyPackage; 12.a. Java uses file system directories to store packages. For example, the.class files for any classes you declare to be part of MyPackage must be stored in a directory called MyPackage. Example: package MyPack; class Balance String name; double bal; Balance(String n, double b) name = n; bal = b; void show() if(bal<0) System.out.print("--> "); System.out.println(name + ": $" + bal); class AccountBalance public static void main(string args[]) Balance current= new Balance("K. J. Fielding", 123.23); current.show(); Call this file AccountBalance.java and put it in a directory called MyPack. Next, compile the file. Make sure that the resulting.class file is also in the MyPack directory. ii) Develop a Java application to generate Electricity bill. Create a class with the AP

following members: Consumer no., consumer name, previous month reading, current month reading. Compute the bill amount using the following tariff. (8) First 100 units - Rs. 1 per unit 101-200 units - Rs. 2.50 per unit 201-500 units - Rs. 4 per unit 501 units - Rs. 6 per unit Program import java.util.*; class ElectricityBill int cno; String cname; int pr; int cr; int reading; double bamount; public ElectricityBill(int no, String name,int prev, int cur) this.cno=no; this.cname=name; this.pr=prev; this.cr=cur; public void calculate() reading=cr-pr; if(reading<=100) bamount=reading*1.0; if(reading>100 && reading<=200) bamount=100+((reading-100)*2.50); if(reading>200 && reading<=500) bamount=100+250 + (reading-200)*4; if(reading>500) bamount=100+250+ 1200+(reading-500)*6; public void displaybill() System.out.println("\t\t Electricity Bill \n"); System.out.println("\t\t \n"); System.out.println("customer Name :"+cname); System.out.println("Customer Number :"+cno); System.out.println("Total Reading :"+reading); System.out.println("Total Amount : Rs."+bamount); public class EBBill public static void main(string ss[]) int no=0; String name=" "; int prev=0; int cur=0;

String type=" "; try Scanner s= new Scanner(System.in); System.out.println("Enter the Customer No\t"); no=s.nextint(); System.out.println("Enter the Customer Name\t"); name=s.next(); System.out.println("Previous Month Reading\t"); prev=s.nextint(); System.out.println("Current Month Reading\t"); cur=s.nextint(); catch(exception ee) System.out.println("Read Error"); ElectricityBill eb=new ElectricityBill(no,name,prev,cur); eb.calculate(); eb.displaybill(); b. OR What is constructor? How constructors are created and accessed in java? Explain (15) A constructor initializes an object immediately upon creation. It has the same name as the class in which it resides and is syntactically similar to a method. Once defined, the constructor is automatically called immediately after the object is created. It does not have any return type Example Class A int a; double d; public A( )// constructor definition System.out.println( constructor ); public void show() System.out.println(a); System.out.println(d); class consex public static void main(string ss[]) A obj= new A();//Constructor call obj.show();

CO2 Output constructor 0 0.0d Parameterized constructor We can define constructor with arguments also. These constructors are called parameterized constructor. Example Class A int a; double d; public A( )// constructor definition System.out.println( constructor ); public A(int x, double y) a=x; d=y; public void show() System.out.println(a); System.out.println(d); class consex public static void main(string ss[]) A obj= new A();//calling no args Constructor obj.show(); A obj2= new A(10,20.5) // Calling parameterized constructor obj2.show(); Output constructor 0 0.0d 10 20.5 Default constructor: If no constructor available in the class then the compiler will provide default constructor to the class and create object. The default constructor is a constructor with no args and no body. Example public A() COURSE OUTCOMES To write Simple java program using Classes and Objects To write a java program using Interfaces and Inheritance MARKS

CO3 CO4 CO5 To handle exception and I/O To write program using multithreading and Generics To develop event driven application Prof. G. Sivakumar, ASP/CSE Ms. R. Thangamani, AP/CSE & Ms. D. Sathya, AP/CSE Signature 80 (Including Choice) Total Prepared by Blooms Level Keyword Marks Approved by Remembering 42 Understanding 30 Applying AP 8 Evaluating EV - Creating CR - Total 80 (Including choice) HoD/CSE