Some Assignments  Write a program which prints the following information about at least 5 persons: NAME MAIL-ID EMPLOYEE-CODE PHONE Eg. Umesh umesh@cse.

Slides:



Advertisements
Similar presentations
Computer Programming w/ Eng. Applications
Advertisements

Making Choices in C if/else statement logical operators break and continue statements switch statement the conditional operator.
Variables, Expressions and Arithmetic Operators in JAVA
The UNIVERSITY of NORTH CAROLINA at CHAPEL HILL Adrian Ilie COMP 14 Introduction to Programming Adrian Ilie July 5, 2005.
Computer Science 1620 Programming & Problem Solving.
The Class String. String Constants and Variables  There is no primitive type for strings in Java.  There is a class called String that can be used to.
COMP 14 Introduction to Programming Miguel A. Otaduy May 20, 2004.
PHYS 2020 Making Choices; Arrays. Arrays  An array is very much like a matrix.  In the C language, an array is a collection of variables, all of the.
1 The First Step Learning objectives write Java programs that display text on the screen. distinguish between the eight built-in scalar types of Java;
“Introduction to Programming With Java”
Laboratory Study October, The very first example, traditional "Hello World!" program: public class first { public static void main (String[ ]
IPC144 Introduction to Programming Using C Week 1 – Lesson 2
Welcome to the Lecture Series on “Introduction to Programming With Java”
“Introduction to Programming With Java” Lecture - 6 U MESH P ATIL
“Introduction to Programming With Java”
BUILDING JAVA PROGRAMS CHAPTER 7 Arrays. Exam #2: Chapters 1-6 Thursday Dec. 4th.
CHAPTER 3 GC Java Fundamentals. 2 BASICS OF JAVA ENVIRONMENT  The environment  The language  Java applications programming Interface API  Various.
More While Loop Examples CS303E: Elements of Computers and Programming.
Ch. 10 For Statement Dr. Bernard Chen Ph.D. University of Central Arkansas Spring 2012.
AP Computer Science edition Review 1 ArrayListsWhile loopsString MethodsMethodsErrors
Classes and Methods. Classes Class Definition Data Fields –Variables to store data items –Differentiate multiple objects of a class –They are called.
Method Overloading.. Method Overloading Can two methods in a class have the same name? Two methods in a class can have the same name provided – they take.
Arithmetic, Class Variables and Class Methods Week 11
REPETITION STATEMENTS - Part2 Structuring Input Loops Counter-Controlled Repetition Structure Sentinel-Controlled Repetition Structure eof()-Controlled.
Structuring Data: Arrays ANSI-C. Representing multiple homogenous data Problem: Input: Desired output:
1 Project 7: Looping. Project 7 For this project you will produce two Java programs. The requirements for each program will be described separately on.
Introduction to programming in java Lecture 22 Arrays – Part 2 and Assignment No. 3.
COMPUTER PROGRAMMING Year 9 – lesson 1. Objective and Outcome Teaching Objective We are going to look at how to construct a computer program. We will.
Introduction to programming in java Lecture 21 Arrays – Part 1.
Chapter 1.2 Introduction to C++ Programming
Array in C# Array in C# RIHS Arshad Khan
Introduction to Computing Science and Programming I
CS 160 – Summer 16 Exam 1 Prep.
CSC111 Quick Revision.
Chapter 7: User-Defined Functions II
Chapter 1.2 Introduction to C++ Programming
Chapter 1.2 Introduction to C++ Programming
[ 4.00 ] [ Today’s Date ] [ Instructor Name ]
C Programming Tutorial – Part I
Chapter 2 Assignment and Interactive Input
Introduction to Programming
Basic operations in Matlab
Counted Loops.
Control Statement Examples
CS 177 Week 15 Recitation Slides
Variables In programming, we often need to have places to store data. These receptacles are called variables. They are called that because they can change.
One-Dimensional Array Introduction Lesson xx
Introduction to Programming
Creation, Traversal, Insertion and Removal
An Introduction to Java – Part I, language basics
Building Java Programs
EKT150 : Computer Programming
Java Tutotrial for [NLP-AI] 2
Introduction to Programming
Module 4 Loops.
Logical Operations In Matlab.
Topics discussed in this section:
CS2011 Introduction to Programming I Arrays (I)
Arrays.
elementary programming
Building Java Programs
Dr. Sampath Jayarathna Cal Poly Pomona
Functions continued.
Unit 3: Variables in Java
Introduction to Programming
Agenda Types and identifiers Practice Assignment Keywords in Java
Dry Run Fix it Write a program
Classes and Methods 15-Aug-19.
H446 Computer Science.
Presentation transcript:

Some Assignments  Write a program which prints the following information about at least 5 persons: NAME MAIL-ID EMPLOYEE-CODE PHONE Eg. Umesh umesh@cse p03161 25764728 Salil salil@cse p03160 25764728 Each entry should be on a separate line. Write a program that prints the following line on the screen along with quotes. “Can we print ‘\’ with System.out.println() statement?” nlp-ai@cse.iitb

Practice Program Create two String objects. The first String will get the characters "Green eggs" The second String will get the characters " and ham." The program will compute the length of each string, and then Write out the combined length of both Strings (the sum of the individual lengths.)

Assignment No.1 Check that your program prints the correct results. Write a program that averages the product sale for three months April, May and June. Declare and initialize variable to the sale entered for each month. Compute the average and write out the results, something like this: sale Entered for April: 12 sale Entered for May : 14 sale Entered for June: 8 Average sale Entered: 11.333333 Check that your program prints the correct results.

Assignment No. 2 Check the correctness of the result. Write a program that computes summation of 1 to n numbers where n can be any positive number. Declare and initialize variables and print the output as Value of n is : 5 Sum of first 5 positive numbers : 15 Check the correctness of the result.

Assignment 3 int a_number=1; // (range: 1 to 4 including both) Print the value of a_number in word. For example, it should print “Four” if a_number contains 4. and message if number is out of range Use equality ‘= =’ operator with if-else constructs. Use Switch nlp-ai@cse.iitb

Assignment # 4 Write a program that uses two arrays of size 5. One string array for storing names of students and one int array for storing marks obtained by the students. Assign values to the elements in the arrays. Print names and marks of students who have scored more than 35 marks. Write a program same as the above, but don’t use numbers (like 0, 1, 2…etc) to access the elements in the array. Declare an int variable ‘i’ and use it as an index into the arrays. nlp-ai@cse.iitb

Lab Work Run the following code & determine its output after execution class Sphere { static final double PI = 3.14; //class variable with fixed value static int count = 0; // Class variable to count objects // Instance variables double radius; // Radius of a sphere double xCenter; // 3D coordinates double yCenter; // of the center double zCenter; // of a sphere } nlp-ai@cse.iitb

Step-I: Now Add main method to it Lab Work Step-I: Now Add main method to it Step-II: Just add one print statement to it, Let say System.out.println(“This is my Ist class”); Step-III: Examine its output nlp-ai@cse.iitb

Lab Work Now Add following methods to the class & examine its output // Static method to report the number of objects created static int getCount(){ return count; // Return current object count } // Instance method to calculate volume double volume() { return 4.0/3.0*PI*radius*radius*radius; } } nlp-ai@cse.iitb

Lab Work Call class method in main method Print class variable in main method Create object of class & call instance methods. Call class methods through reference variable & examine its output Try to change the value of “final” class variable in main. Remove keyword “static” from count variable and examine its effect. nlp-ai@cse.iitb