Upcoming SlideShare
×

# Ann

510 views
374 views

Published on

Published in: Education, Technology
0 Likes
Statistics
Notes
• Full Name
Comment goes here.

Are you sure you want to Yes No
• Be the first to comment

• Be the first to like this

Views
Total views
510
On SlideShare
0
From Embeds
0
Number of Embeds
6
Actions
Shares
0
14
0
Likes
0
Embeds 0
No embeds

No notes for slide

### Ann

1. 1. Universidad De Manila Antonio J. Villegas Street Mehan Garden Ermita, Manila College of Engineering and Technology Compilation of Exercises in Object Oriented Programming Submitted by: Estorninos, Rose Ann G. CO-41 Instructor: Engr. Elmerito D. Pineda
2. 2. EXERCISE #1 package javaapplication13 public class JavaApplication13 { public static void main(String[] args) { System.out.println("ttRESUMEn"); System.out.println("tPERSONAL DATA:n"); System.out.println("Rose Ann G. Estorninos"); System.out.println("2314 Gapan St. Gag. Tondo,Manila"); System.out.println("09129694078"); System.out.println("roseannestorninos@yahoo.com"); System.out.println("nObjective: To obtain a position in a stable work enviroment with growth potential."); System.out.println("ntEDUCATIONAL BACKGROUND:n"); System.out.println("Primary: Gregoria De Jesus Elementary Schooln"); System.out.println("Secondary: Jose P. Laurel High Schooln"); System.out.println("Tertiary: Universidad De Manila") }} EXERCISE#2
3. 3. package javaapplication14; importjava.util.Scanner; public class JavaApplication14 { public static void main(String[] args) { Scanner epal = new Scanner (System.in); float grade; System.out.println("input your grade:"); grade = epal.nextFloat(); if ((grade<=100)&&(grade>=75)) { System.out.println("Pass"); } else if ((grade<75)&&(grade>=50)) { System.out.println("Fail"); } else { System.out.println("Input Error!"); } } } EXERCISE #3
4. 4. package javaapplication19; importjava.util.Scanner; public class JavaApplication19 { public static void main(String[] args) { Scanner input = new Scanner( System.out.println("Quiz #1:"); //quizzes int q1 = input.nextInt(); System.out.println("Quiz #2:"); int q2 = input.nextInt(); System.out.println("Quiz #3:"); int q3 = input.nextInt(); doubleavgm = (q1 + q2 + q3) / 3; System.out.println("Midterm Exam:"); // midterm exam intmidterme = input.nextInt(); doublemidtermg = (midterme*0.6)+(avgm*0.4); //midterm grade System.out.println("Quiz #4:"); int q4 = input.nextInt(); System.out.println("Quiz #5:"); int q5 = input.nextInt(); doubleavgf = (q4 + q5) / 2; System.out.println("Final Exam:"); //Final exam intfinalse = input.nextInt(); doublefinalsg = (finalse*0.6)+(avgf*0.4); doublefg = (finalsg*0.6)+(midtermg*.4); System.out.println("Your Midterm grade is: " + midtermg);
5. 5. System.out.println("Your Finals grade is : " + finalsg); System.out.println("Your Final grade is : " + fg);}} EXERCISE #4 package javaapplication15; importjavax.swing.JOptionPane; public class JavaApplication15 { public static void main(String[] args) { String name; String msg; name = JOptionPane.showInputDialog("Enter Your Name:"); msg = "Hello " + name + "!!"; JOptionPane.showMessageDialog(null, msg); } }
8. 8. importjava.util.Scanner; importjava.text.*; public class JavaApplication20 { public static void main(String[] args) { Scanner input = new Scanner(System.in); DecimalFormat two = new DecimalFormat("\$0.00"); String line = ""; char again = 'Y'; while (again == 'Y' || again == 'y'){ System.out.println("Enter Account Balance: "); double balance = input.nextDouble(); double annual = balance; double monthly = balance; double daily = balance; System.out.println("Enter Interest Rate(%): "); double interest = input.nextDouble()/100; int count = 1; while (count <= 10){ annual = annual*(1+interest); int month = 0; while (month < 12){ monthly = monthly*(1+(interest/12)); month++;} int day = 0; while (day < 365){ daily = daily*(1+(interest/365));
9. 9. day++; } count++;} System.out.println("Your interest in 10 years"); System.out.println("Your new balance when compounded annually: " + two.format(annual)); System.out.println("Your new balance when compounded monthly: " + two.format(monthly)); System.out.println("Your new balance when compounded daily: " + two.format(daily)); System.out.println("Again? (Y/N)"); line = input.next(); again = line.charAt(0); }} } EXERCISE #5.3 package javaapplication18; importjava.io.BufferedReader; importjava.io.IOException;
10. 10. importjava.io.InputStreamReader; importjava.util.Scanner; public class JavaApplication18 { public static void main(String[] args) { BufferedReaderdataIn = new BufferedReader(new InputStreamReader( System.in) ); String name = ""; System.out.print(" Please Enter Your Name:"); try{ name = dataIn.readLine(); }catch( IOException e ){ System.out.println("Error!");} System.out.println(" Hello " + name +"!"); System.out.println("^_^Lets determine your Zodiac Sign ^_^"); String zs = ""; String mon = ""; Scanner input = new Scanner(System.in); System.out.println(" Enter month(1-12): "); int m = input.nextInt(); System.out.println("Enter day(1-31): "); int d = input.nextInt(); if((m== 1) && (d <= 19) || (m == 12) && (d >= 22)) { zs = "Capricorn"; } else if((m == 2) && (d <= 18) || (m == 1) && (d >= 20)) { zs = "Aquarius"; } else if((m == 3) && (d <= 20) || (m == 2) && (d >= 19)) { zs = "Pisces"; }
11. 11. else if((m == 4) && (d<= 19) || (m == 3) && (d >= 21)) { zs = "Aries"; } else if((m== 5) && (d <= 20) || (m == 4) && (d >= 20)) { zs = "Taurus"; } else if((m == 6) && (d <= 20) || (m == 5) && (d >= 21)) { zs = "Gemini"; } else if((m == 7) && (d <= 22) || (m == 6) && (d >= 21)) { zs = "Cancer"; } else if((m == 8) && (d <= 22) || (m == 7) && (d>= 23)) { zs = "Leo"; } else if((m == 9) && (d <= 22) || (m == 8) && (d >= 23)) { zs = "Virgo"; } else if((m == 10) && (d <= 22) || (m == 9) && (d >= 23)) { zs = "Libra"; } else if((m == 11) && (d <= 21) || (m == 10) && (d >= 23)) { zs = "Scorpio"; } else if((m == 12) && (d <= 21) || (m == 11) && (d >= 22)) { zs = "Sagittarius"; } switch (m){ case 1:mon = "January";break; case 2:mon = "February";break; case 3:mon = "March";break; case 4:mon = "April";break; case 5:mon = "May";break; case 6:mon = "June";break; case 7:mon = "July";break;
12. 12. case 8:mon = "August";break; case 9:mon = "September";break; case 10:mon = "October";break; case 11:mon = "November";break; case 12:mon = "December";break;} System.out.println("Zodiac sign for " + mon + " " + d + " is " + zs); } } Exercise #6.1 package oopexercise6.pkg1; importjava.util.Scanner; public class OOPExercise61 { public static void main(String[] args) { int[] binary = new int[100]; int[] octal = new int[100];
13. 13. char[] hexa = new char[100]; int i=1; int initial; Scanner input = new Scanner(System.in); System.out.print("Enter Decimal Value: "); int decimal = input.nextInt(); //Choices System.out.println("Convert to "); System.out.println("[1] Binaryt[2] Octalt[3] Hexadecimal"); System.out.print(">>> "); int choice = input.nextInt(); int quotient = decimal; //equivalent in binary if (choice ==1){ while(quotient!=0){ binary[i++] = quotient%2; quotient = quotient/2;} System.out.print("Equivalent of " + decimal + " in Binary is "); for(int j=i-1; j>0; j--){ System.out.print(binary[j]);} System.out.println("");} //equivalent in octal else if (choice == 2){ while(quotient!=0){ octal[i++] = quotient%8; quotient = quotient/8;}
14. 14. System.out.print("Equivalent of " + decimal + " in Octal is "); for(int j = i-1 ; j> 0; j--){ System.out.print(octal[j]);} System.out.println("");} //equivalent in hexadecimal else if (choice == 3){ while(quotient!=0){ initial = quotient % 16; if( initial < 10) //to convert initial =initial + 48; else initial = initial + 55; hexa[i++] = (char) initial; quotient = quotient / 16;} System.out.print("Equivalent of " + decimal + " in Hexadecimal is "); for(int j = i -1 ;j> 0;j--){ System.out.print(hexa[j]);} System.out.println("");} else{System.out.println("!!!Invalid Entry!!!"); } } }
15. 15. Exercise #6.2 package oopexercise6.pkg2; importjava.util.Scanner; importjava.text.DecimalFormat; public class OOPExercise62 { public static void main(String[] args) { int total = 0; Scanner input = new Scanner(System.in); System.out.print("The number of integers that you will enter is:"); int in = input.nextInt(); int array[] = new int[in]; float percent[] = new float[in]; System.out.println("Enter " + in + " integers, one per line:" ); for (int i=0; i<array.length; i++) {
16. 16. array[i] = input.nextInt(); percent[i] = array[i]*100.0f; total = total + array[i];} System.out.println("The total is " + total +"."); DecimalFormatdf = new DecimalFormat("####.##"); System.out.println("The numbers are:"); for (int j=0; j<array.length ; j++){ System.out.println(array[j] + " which is " + df.format(percent[j]/total) + "% of the total."); } } }
17. 17. Exercise #6.3 package oopexercise6.pkg3; public class OOPExercise63 { public static void main(String[] args) { String [][] studentsarray = { {"Mateo", "Pedro", "Simon"}, {" 75", " 90", " 82"}, {" 69", " 88", " 87"}}; System.out.println("STUDENTS INFORMATION: GRADES AND AVERAGES"); System.out.println(studentsarray[0][0] + studentsarray[1][0] + studentsarray[2][0]); System.out.println(studentsarray[0][1] + studentsarray[1][1] + studentsarray[2][1]); System.out.println(studentsarray[0][2] + studentsarray[1][2] + studentsarray[2][2]); } } QUESTION AND ANSWER
18. 18. Introduction (Exercise 1) 1. What is your understanding about System.out.println()? System.out.println() is like printf in C++ it just print out what is inside the “”, ln is use to determine that you need to move in next line. 2. How does the Java Technology platform improve on other language platforms? The Java Technology platform improves on other language platforms in terms of flexibility because you can use different kinds of programming language on. Flow Controls (Exercise 5) 1. What is the significance of using control structures? The control structure is used in making decisions, choosing in different conditions that gives different output. 2. For you, which is preferably the most convenient control structure to be used in comparisons, IFELSE or SWITCH? For the most convenient control structure to be used in comparisons is switch. Array (Exercise 6) 1. Why is it necessary, being a programmer, to use arrays?. What are the risks of not using arrays? As a programmer it is necessary to use array because it shorten the program and lessen the chance of error in assigning a variable. The risks of not using arrays are you will make a too long program and there is a high chance of error in assigning variable. 2. When do usually single dimensional array is used? Single dimensional array is used in assigning a variable like students name, teachers name or any records.