1 / 10

Some Assignments 

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.

molly
Download Presentation

Some Assignments 

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. 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

  2. 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.)

  3. Assignment No.1 • 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.

  4. Assignment No. 2 • 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.

  5. 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

  6. 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

  7. 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

  8. 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

  9. 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

  10. 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

More Related