SlideShare ist ein Scribd-Unternehmen logo
1 von 18
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
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
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
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);
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); }
}
EXERCISE #5.1
package javaapplication16;
importjava.io.BufferedReader;
importjava.io.InputStreamReader;
importjava.io.IOException;
public class JavaApplication16 {
public static void main(String[] args) throws Exception {
InputStreamReader g1 = new InputStreamReader( System.in);
BufferedReadergd = new BufferedReader(g1);
BufferedReaderdataIn = new BufferedReader(new InputStreamReader( System.in) );
String name = "";
System.out.print("nntt Please Enter Your Name:");
try{
name = dataIn.readLine();
}catch( IOException e ){
System.out.println("Error!");}
System.out.println("nntt Hello " + name +"!");
System.out.println("ntt^_^Lets Compute the Average of your Grade ^_^");
System.out.print("n n t t Enter your 1st grade: ");
String grade1 = gd.readLine();
System.out.print("t t Enter your 2nd grade: ");
String grade2 = gd.readLine();
System.out.print("t t Enter your 3rd grade: ");
String grade3 = gd.readLine();
intgt = Integer.parseInt(grade1)+Integer.parseInt(grade2)+Integer.parseInt(grade3), ave;
ave = gt/3;
System.out.println("t t Your Average is: " + ave);
if (ave>=60) {
System.out.println("t:)");}
else{
System.out.println("t:(");}
}
}

EXERCISE #5.2
package javaapplication20;
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));
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;
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"; }
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;
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];
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;}
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!!!"); }
}
}
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++) {
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.");
}
}
}
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
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.

Weitere ähnliche Inhalte

Was ist angesagt?

Java Puzzle
Java PuzzleJava Puzzle
Java PuzzleSFilipp
 
New Java Date/Time API
New Java Date/Time APINew Java Date/Time API
New Java Date/Time APIJuliet Nkwor
 
The Groovy Puzzlers – The Complete 01 and 02 Seasons
The Groovy Puzzlers – The Complete 01 and 02 SeasonsThe Groovy Puzzlers – The Complete 01 and 02 Seasons
The Groovy Puzzlers – The Complete 01 and 02 SeasonsBaruch Sadogursky
 
JFokus 2016 - Beyond Lambdas - the Aftermath
JFokus 2016 - Beyond Lambdas - the AftermathJFokus 2016 - Beyond Lambdas - the Aftermath
JFokus 2016 - Beyond Lambdas - the AftermathDaniel Sawano
 
GeeCon 2016 - Beyond Lambdas, the Aftermath
GeeCon 2016 - Beyond Lambdas, the AftermathGeeCon 2016 - Beyond Lambdas, the Aftermath
GeeCon 2016 - Beyond Lambdas, the AftermathDaniel Sawano
 
Best Java Problems and Solutions
Best Java Problems and SolutionsBest Java Problems and Solutions
Best Java Problems and SolutionsJava Projects
 
Core java pract_sem iii
Core java pract_sem iiiCore java pract_sem iii
Core java pract_sem iiiNiraj Bharambe
 
Java 8 Puzzlers [as presented at OSCON 2016]
Java 8 Puzzlers [as presented at  OSCON 2016]Java 8 Puzzlers [as presented at  OSCON 2016]
Java 8 Puzzlers [as presented at OSCON 2016]Baruch Sadogursky
 
VISUALIZAR REGISTROS EN UN JTABLE
VISUALIZAR REGISTROS EN UN JTABLEVISUALIZAR REGISTROS EN UN JTABLE
VISUALIZAR REGISTROS EN UN JTABLEDarwin Durand
 

Was ist angesagt? (18)

Studyx4
Studyx4Studyx4
Studyx4
 
Java Puzzle
Java PuzzleJava Puzzle
Java Puzzle
 
Exceptional exceptions
Exceptional exceptionsExceptional exceptions
Exceptional exceptions
 
Java puzzles
Java puzzlesJava puzzles
Java puzzles
 
New Java Date/Time API
New Java Date/Time APINew Java Date/Time API
New Java Date/Time API
 
The Groovy Puzzlers – The Complete 01 and 02 Seasons
The Groovy Puzzlers – The Complete 01 and 02 SeasonsThe Groovy Puzzlers – The Complete 01 and 02 Seasons
The Groovy Puzzlers – The Complete 01 and 02 Seasons
 
JFokus 2016 - Beyond Lambdas - the Aftermath
JFokus 2016 - Beyond Lambdas - the AftermathJFokus 2016 - Beyond Lambdas - the Aftermath
JFokus 2016 - Beyond Lambdas - the Aftermath
 
Studyx1
Studyx1Studyx1
Studyx1
 
Sam wd programs
Sam wd programsSam wd programs
Sam wd programs
 
GeeCon 2016 - Beyond Lambdas, the Aftermath
GeeCon 2016 - Beyond Lambdas, the AftermathGeeCon 2016 - Beyond Lambdas, the Aftermath
GeeCon 2016 - Beyond Lambdas, the Aftermath
 
Oop lecture9 13
Oop lecture9 13Oop lecture9 13
Oop lecture9 13
 
Best Java Problems and Solutions
Best Java Problems and SolutionsBest Java Problems and Solutions
Best Java Problems and Solutions
 
Scala introduction
Scala introductionScala introduction
Scala introduction
 
Core java pract_sem iii
Core java pract_sem iiiCore java pract_sem iii
Core java pract_sem iii
 
Java Puzzlers
Java PuzzlersJava Puzzlers
Java Puzzlers
 
Ocr code
Ocr codeOcr code
Ocr code
 
Java 8 Puzzlers [as presented at OSCON 2016]
Java 8 Puzzlers [as presented at  OSCON 2016]Java 8 Puzzlers [as presented at  OSCON 2016]
Java 8 Puzzlers [as presented at OSCON 2016]
 
VISUALIZAR REGISTROS EN UN JTABLE
VISUALIZAR REGISTROS EN UN JTABLEVISUALIZAR REGISTROS EN UN JTABLE
VISUALIZAR REGISTROS EN UN JTABLE
 

Ähnlich wie Ann

JAVA PRACTICE QUESTIONS v1.4.pdf
JAVA PRACTICE QUESTIONS v1.4.pdfJAVA PRACTICE QUESTIONS v1.4.pdf
JAVA PRACTICE QUESTIONS v1.4.pdfRohitkumarYadav80
 
C Programming Language Part 8
C Programming Language Part 8C Programming Language Part 8
C Programming Language Part 8Rumman Ansari
 
Import java
Import javaImport java
Import javaheni2121
 
import java.util.Scanner;public class Main {    public static in.pdf
import java.util.Scanner;public class Main {    public static in.pdfimport java.util.Scanner;public class Main {    public static in.pdf
import java.util.Scanner;public class Main {    public static in.pdfanwarsadath111
 
Find the output of the following code (Java for ICSE)
Find the output of the following code (Java for ICSE)Find the output of the following code (Java for ICSE)
Find the output of the following code (Java for ICSE)Mokshya Priyadarshee
 
Java programming lab manual
Java programming lab manualJava programming lab manual
Java programming lab manualsameer farooq
 
WINSEM2020-21_STS3105_SS_VL2020210500169_Reference_Material_I_15-Feb-2021_L6-...
WINSEM2020-21_STS3105_SS_VL2020210500169_Reference_Material_I_15-Feb-2021_L6-...WINSEM2020-21_STS3105_SS_VL2020210500169_Reference_Material_I_15-Feb-2021_L6-...
WINSEM2020-21_STS3105_SS_VL2020210500169_Reference_Material_I_15-Feb-2021_L6-...MaruMengesha
 
Code javascript
Code javascriptCode javascript
Code javascriptRay Ray
 
Lab01.pptx
Lab01.pptxLab01.pptx
Lab01.pptxKimVeeL
 
Java AssignmentWrite a program using sortingsorting bubble,sele.pdf
Java AssignmentWrite a program using sortingsorting bubble,sele.pdfJava AssignmentWrite a program using sortingsorting bubble,sele.pdf
Java AssignmentWrite a program using sortingsorting bubble,sele.pdfeyewatchsystems
 
java program assigment -2
java program assigment -2java program assigment -2
java program assigment -2Ankit Gupta
 
PrintDiamond.javaimport java.util.Scanner;class PrintDiamond.pdf
 PrintDiamond.javaimport java.util.Scanner;class PrintDiamond.pdf PrintDiamond.javaimport java.util.Scanner;class PrintDiamond.pdf
PrintDiamond.javaimport java.util.Scanner;class PrintDiamond.pdfapexelectronices01
 

Ähnlich wie Ann (20)

Java file
Java fileJava file
Java file
 
JAVA PRACTICE QUESTIONS v1.4.pdf
JAVA PRACTICE QUESTIONS v1.4.pdfJAVA PRACTICE QUESTIONS v1.4.pdf
JAVA PRACTICE QUESTIONS v1.4.pdf
 
WAP to add two given matrices in Java
WAP to add two given matrices in JavaWAP to add two given matrices in Java
WAP to add two given matrices in Java
 
C Programming Language Part 8
C Programming Language Part 8C Programming Language Part 8
C Programming Language Part 8
 
Import java
Import javaImport java
Import java
 
import java.util.Scanner;public class Main {    public static in.pdf
import java.util.Scanner;public class Main {    public static in.pdfimport java.util.Scanner;public class Main {    public static in.pdf
import java.util.Scanner;public class Main {    public static in.pdf
 
Utility.ppt
Utility.pptUtility.ppt
Utility.ppt
 
Find the output of the following code (Java for ICSE)
Find the output of the following code (Java for ICSE)Find the output of the following code (Java for ICSE)
Find the output of the following code (Java for ICSE)
 
ADA FILE
ADA FILEADA FILE
ADA FILE
 
Java programming lab manual
Java programming lab manualJava programming lab manual
Java programming lab manual
 
WINSEM2020-21_STS3105_SS_VL2020210500169_Reference_Material_I_15-Feb-2021_L6-...
WINSEM2020-21_STS3105_SS_VL2020210500169_Reference_Material_I_15-Feb-2021_L6-...WINSEM2020-21_STS3105_SS_VL2020210500169_Reference_Material_I_15-Feb-2021_L6-...
WINSEM2020-21_STS3105_SS_VL2020210500169_Reference_Material_I_15-Feb-2021_L6-...
 
Pnno
PnnoPnno
Pnno
 
JAVA.pdf
JAVA.pdfJAVA.pdf
JAVA.pdf
 
Code javascript
Code javascriptCode javascript
Code javascript
 
Lab01.pptx
Lab01.pptxLab01.pptx
Lab01.pptx
 
Java AssignmentWrite a program using sortingsorting bubble,sele.pdf
Java AssignmentWrite a program using sortingsorting bubble,sele.pdfJava AssignmentWrite a program using sortingsorting bubble,sele.pdf
Java AssignmentWrite a program using sortingsorting bubble,sele.pdf
 
java program assigment -2
java program assigment -2java program assigment -2
java program assigment -2
 
2D array
2D array2D array
2D array
 
PrintDiamond.javaimport java.util.Scanner;class PrintDiamond.pdf
 PrintDiamond.javaimport java.util.Scanner;class PrintDiamond.pdf PrintDiamond.javaimport java.util.Scanner;class PrintDiamond.pdf
PrintDiamond.javaimport java.util.Scanner;class PrintDiamond.pdf
 
Cpds lab
Cpds labCpds lab
Cpds lab
 

Kürzlich hochgeladen

Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactPECB
 
The byproduct of sericulture in different industries.pptx
The byproduct of sericulture in different industries.pptxThe byproduct of sericulture in different industries.pptx
The byproduct of sericulture in different industries.pptxShobhayan Kirtania
 
Mastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionMastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionSafetyChain Software
 
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...Sapna Thakur
 
9548086042 for call girls in Indira Nagar with room service
9548086042  for call girls in Indira Nagar  with room service9548086042  for call girls in Indira Nagar  with room service
9548086042 for call girls in Indira Nagar with room servicediscovermytutordmt
 
mini mental status format.docx
mini    mental       status     format.docxmini    mental       status     format.docx
mini mental status format.docxPoojaSen20
 
Web & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfWeb & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfJayanti Pande
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfsanyamsingh5019
 
Z Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphZ Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphThiyagu K
 
Interactive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationInteractive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationnomboosow
 
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...fonyou31
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptxVS Mahajan Coaching Centre
 
Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Disha Kariya
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdfQucHHunhnh
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Krashi Coaching
 
APM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAPM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAssociation for Project Management
 
Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3JemimahLaneBuaron
 

Kürzlich hochgeladen (20)

Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global Impact
 
The byproduct of sericulture in different industries.pptx
The byproduct of sericulture in different industries.pptxThe byproduct of sericulture in different industries.pptx
The byproduct of sericulture in different industries.pptx
 
Mastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionMastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory Inspection
 
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
 
9548086042 for call girls in Indira Nagar with room service
9548086042  for call girls in Indira Nagar  with room service9548086042  for call girls in Indira Nagar  with room service
9548086042 for call girls in Indira Nagar with room service
 
mini mental status format.docx
mini    mental       status     format.docxmini    mental       status     format.docx
mini mental status format.docx
 
Web & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfWeb & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdf
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdf
 
Z Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphZ Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot Graph
 
Interactive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationInteractive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communication
 
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
 
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
 
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptxINDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
 
Advance Mobile Application Development class 07
Advance Mobile Application Development class 07Advance Mobile Application Development class 07
Advance Mobile Application Development class 07
 
Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdf
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
 
APM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAPM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across Sectors
 
Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3
 

Ann

  • 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. 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. 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. 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. 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); } }
  • 6. EXERCISE #5.1 package javaapplication16; importjava.io.BufferedReader; importjava.io.InputStreamReader; importjava.io.IOException; public class JavaApplication16 { public static void main(String[] args) throws Exception { InputStreamReader g1 = new InputStreamReader( System.in); BufferedReadergd = new BufferedReader(g1); BufferedReaderdataIn = new BufferedReader(new InputStreamReader( System.in) ); String name = ""; System.out.print("nntt Please Enter Your Name:"); try{ name = dataIn.readLine(); }catch( IOException e ){ System.out.println("Error!");} System.out.println("nntt Hello " + name +"!"); System.out.println("ntt^_^Lets Compute the Average of your Grade ^_^"); System.out.print("n n t t Enter your 1st grade: "); String grade1 = gd.readLine();
  • 7. System.out.print("t t Enter your 2nd grade: "); String grade2 = gd.readLine(); System.out.print("t t Enter your 3rd grade: "); String grade3 = gd.readLine(); intgt = Integer.parseInt(grade1)+Integer.parseInt(grade2)+Integer.parseInt(grade3), ave; ave = gt/3; System.out.println("t t Your Average is: " + ave); if (ave>=60) { System.out.println("t:)");} else{ System.out.println("t:(");} } } EXERCISE #5.2 package javaapplication20;
  • 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. 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. 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. 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. 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. 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. 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. 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. 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. 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. 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.