0% found this document useful (0 votes)
40 views6 pages

OOP Practice With Java Full Ch1

OOP Practice With Java Full Ch1
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF or read online on Scribd
0% found this document useful (0 votes)
40 views6 pages

OOP Practice With Java Full Ch1

OOP Practice With Java Full Ch1
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF or read online on Scribd
DAI HOC DA NANG . TRUONG DAI HOC CONG NGHE THONG TIN VA TRUYEN THONG VIET - HAN SSS vietnam - Korea University of Information and Communication Technology OBJECT ORIENTED PROGRAMMING PRACTICE WITH JAVA HUYNH CONG PHAP, Assoc. Prof, PhD. Danang, 2021 DAI HOC DA NANG TRUONG DAI HOC CONG NGHE THONG TIN VA TRUYEN THONG VIET - HAN SSS vietnam - Korea University of Information and Communication Technology Table of Contents Chapter 1. Introduction to Java and Eclipse .......sseseeeeeeeee 3 I. Exercises with solutions . Il. Do it yourself -6 Chapter 2. Basic Object Oriented Programming Concepts.........+ 7 1. Exercises with solutions ............0ceceeeeeeee esse seen 8 Tis Doni teyourse| threecteeeerte seer rer ete eeree renee ncrcr 15 Chapter 3. Java fundamentals and control structures........... 7 L. Exercises with solutions ............cseseseeee esse seen es 18 18 [) fha §-T1r 4 ananenoocosossconoudadadsonoseonencobodods 21 Chapter 4. Java methods, arrays and references . L. Exercises with solutions IIs Dowi ty younse Ltienee ners seems at eee ease eee eer 32 Chapter 5. Implementation of Abstraction and Encapsulation. L Exercises with solutions . Il. Do it yourself Chapter 6, Implementation of Inheritance and Polymorphism..... 55 I. Exercises with solutions . I. Do il yourself Chapter 7. Exception Handling .. I. Exercises with solutions ........0.sss0seeeeeseeeeeeeeeee Il. Do it yOUrSe]F ... ec. cee cee eee eee ee es eee ee eee sense ee eee 76 Chapter 8. GUI programming with Java........sceeeeeeeeeeee sees 7 I. Exercises with SOLUtIONS .......cecseseeeeeeee sense eee ees 78 Igo} thyourse Leneintest erect er enter et eee cere etre 78 Chapter 9, Java Database Connectivity I. Exercises with solutions .... Il. Do it YOUrSELF .. ee cece eee eeee cece ee eee ee eeeeeeee ee eee 80 OOP Practice with Java Huynh Céng Phap DAI HOC DA NANG . TRUONG DAI HOC CONG NGHE THONG TIN VA TRUYEN THONG VIET - HAN SSS vietnam - Korea University of Information and Communication Technology Chapter 1. Introduction to Java and Eclipse OOP Practice with Java 3 Huynh Céng Phap DAI HOC DA NANG . VKU TRUONG DAI HOC CONG NGHE THONG TIN VA TRUYEN THONG VIET - HAN SSS vietnam - Korea University of Information and Communication Technology I. Exercises with solutions 1. Install Eclipse I ttps://www.tute int.com/« stallation.htm, 2. Write a java program pirinting out: “Hello VKU freshmen!” public class DataPrinting ( 4 public static void main(String[] args) ( 5 6 System. out.print1n("Hello VKU freshmen"); 3. Write a java application allowing user to input a byte number N (32s N <255) and printing out its corresponding character. Fi import javasutil-r Public class Exercise? { public static void nain(striag[) args) ( ‘Scanner keyboard = new Scanner (System. tn); System.out.print ("Input an ASCII code: "); code = keyboard.nextByte (); System.out.printIn ("ASCII code "+ ASCIicode +" is " + (char) ASCrIcode) {cts bmn Cr emlpreonsoco rea as AST Pppve OE ay Da Toput an ASCr? code! cS ASEIE code 65 is A 4. Write a java application allowing user to input a character and printing out its corresponding ASCII code. OOP Practice with Java 4 Huynh Céng Phap DAI HOC DA NANG . VK TRUGNG DAI HOC CONG NGHE THONG TIN VA TRUYEN THONG VI SSS vietnam - Korea University of Information and Communication Technology Import java-util.Scanners 2 public class Exercises ( oPUIpublic static void main(String(] args) ( char < Scanner keyboard ~ new Scannor (System. a) + 6 system.out.print ("rnput a character: *) ch = kayboard.next () -charAt (0); System.oue.printin ("ascii coze of "sch 4" ig" 4 (byteyen); o 4 10) tes «ia @ nn Dee nee ‘nput a character: 2 =“ . SCII code of a is 97 5. Write a java application allowing user to input two integer numbers (a and b) then print out results of the following expressions: a+b; a-b; a*b; a/b; a%b i import java.util.*; 2 public class Exorcisod { 3° public static void main(String[] args) ( 4 Scanner k-new Scanner (System. im); 5 System.out.print1n("Input two int numbers: "); 6 int a=k.nextInt (); 7 int b=k.nextint ()7 8 System.out.printIn(at" + "tht" = "+(atb)); 9 System.out.printin(at" - "+tb#" = "+(a-b)); Lo System.out.printIn(at" x "+tbt" = "tatb); hi System.out.printIn(at" / "+tb#" = "+a/b); 2 System.out.printIn(at" mod "tht" = "tatb); [Proname 6 inadoc Oacuaton Q Canta 1 «tem Exerc [ve Appcaton er cpap 2p les eeu pei opt eli, 641602. input two int numbers: yeuBwE aw 6. Write a java program allowing user to input a circle radius and calculating the circle’s area and perimeter. OOP Practice with Java 5 Huynh Céng Phap DAI HOC DA NANG . TRUONG DAI HOC CONG NGHE THONG TIN VA TRUYEN THONG VIET - HAN SSE vietnam - Korea University of Information and Communication Technology import java.util.Scanner; 2 public class Exercise5 { - public static void main(string[] args) ( double r; final float pi=3.1415f; Scanner k=new Scanner (System. in) ; System.out.print ("Input radius r=k.nextDouble () ; System.out.printIn("Circle erea = "tr*r*pi); System.out.printIn ("Circle perimeter — "12*r+pi); , [Srobens inaeoc @ Dxizaton const H -temints> aren Appt) Ceca pool plo clipe ope opt flnin295 614025202102 input radius r= > Circle area = 78.53749990463257 Circle perimeter — 31.414999961853027 Il. Do it yourself 1. Write a java application allowing user to input a number (7) then print out results of the following expressions: sin(n), cos(n). vn Hint: Use the Math class 2. Write a java application allowing user to input a string and printing out the number of characters of the given string Hint: Use the String class and length method 3. Write a java program allowing user to input width and high of a rectangle and calculating the rectangle’s area and perimeter. 4. Explorer the online document hittps://www.codecademy.com/learn/learn-java OOP Practice with Java 6 Huynh Céng Phap

You might also like