SlideShare une entreprise Scribd logo
1  sur  7
//https://code.google.com/p/fresher01dn/source/browse/trunk/?r=13#trunk
%2FJavaEE_Day03%2Fsrc%2Fpk%2Fassignment01
public class Main {
private Shape shapeArray[];
private TwoDimensionalShape twoDArray[];
private ThreeDimensionalShape threeDimensionalShape[];
public Main() {
shapeArray = new Shape[6];
twoDArray = new TwoDimensionalShape[3];
threeDimensionalShape = new ThreeDimensionalShape[3];
Circle circle = new Circle(5);
Square square = new Square(5);
Triangle triangle = new Triangle(3, 4, 5);
Sphere sphere = new Sphere(5);
Cube cube = new Cube(3, 4);
Tetrahedron tetrahedron = new Tetrahedron(3, 5, 6);
shapeArray[0] = circle;
twoDArray[0] = circle;
shapeArray[1] = square;
twoDArray[1] = square;
shapeArray[2] = triangle;
twoDArray[2] = triangle;
shapeArray[3] = sphere;
threeDimensionalShape[0] = sphere;
shapeArray[4] = cube;
threeDimensionalShape[1] = sphere;
shapeArray[5] = sphere;
threeDimensionalShape[2] = tetrahedron;
}
public void displayShapeInfo() {
for (int i = 0; i < shapeArray.length; i++) {
System.out.print(shapeArray[i].getName() + " ");
shapeArray[i].print();
}
System.out.println("============================================");
for (int i = 0; i < twoDArray.length; i++) {
System.out.println(twoDArray[i].getName() + " co dien tich : "
+ twoDArray[i].getArea());
}
for (int i = 0; i < threeDimensionalShape.length; i++) {
System.out.println(threeDimensionalShape[i].getName() +" co
the tich "+ threeDimensionalShape[i].getVolume());
}
}
public static void main(String[] args) {
Main m = new Main();
m.displayShapeInfo();
}

}
============================================
public abstract class Shape {
// abstract methods
public abstract String getName();
public abstract void print();

}
=================================================
public abstract class TwoDimensionalShape extends Shape {
private int s1, s2,s3;
public TwoDimensionalShape( int s1, int s2,int s3) {
this.s1 = s1;
this.s2 = s2;
this.s3 = s3;
}
public int getS1() {
return s1;
}
public void setS1(int s1) {
this.s1 = s1;
}
public int getS3() {
return s3;
}
public void setS3(int s3) {
this.s3 = s3;
}
public int getS2() {
return s2;
}
public void setS2(int s2) {
this.s2 = s2;
}
public abstract int getArea();
}
class Circle extends TwoDimensionalShape{
public Circle( int radius) {
super( radius, radius,radius);
}
@Override
public int getArea() {
return (int)Math.PI *super.getS1()*super.getS1();
}
@Override
public String getName() {
// TODO Auto-generated method stub
return "Hinh tron";
}
@Override
public void print() {
}

System.out.println("co ban kinh = " + super.getS1()+" ");

}
class Square extends TwoDimensionalShape{
public Square(int canh) {
super(canh, canh,canh);
}
@Override
public int getArea() {
return super.getS1()*super.getS1();
}
@Override
public String getName() {
// TODO Auto-generated method stub
return "Hinh vuong";
}
@Override
public void print() {
// TODO Auto-generated method stub
System.out.println("Co canh = "+ super.getS1());
}
}
class Triangle extends TwoDimensionalShape{
public Triangle(int canh1, int canh2,int canh3) {
super(canh1, canh2, canh3);
// TODO Auto-generated constructor stub
}
@Override
public int getArea() {
// TODO Auto-generated method stub
int sTamGiac = 0;
//
s = căn[p.(p - a)(p - b)(p - c)]
//
trong ăó p = (a + b + c)2
float p = (super.getS1()+super.getS2()+super.getS3())/2;
sTamGiac =(int) Math.sqrt(p*( p -super.getS1())*(psuper.getS2())*(p-super.getS3()));
return sTamGiac;
}
@Override
public String getName() {
// TODO Auto-generated method stub
return "Hinh tam giac";
}
@Override
public void print() {
// TODO Auto-generated method stub
System.out.println("Co canh 1 = " +super.getS1() +" Canh 2 = "+
super.getS2() + " Canh 3 = "+ super.getS3());
}
}
====================================================
public abstract class ThreeDimensionalShape extends Shape {
public int getS1() {
return s1;
}
public void setS1(int s1) {
this.s1 = s1;
}
public int getS2() {
return s2;
}
public void setS2(int s2) {
this.s2 = s2;
}
public int getS3() {
return s3;
}
public void setS3(int s3) {
this.s3 = s3;
}
int s1, s2, s3;
public ThreeDimensionalShape(int s1, int s2, int s3) {
this.s1 = s1;
this.s2 = s2;
this.s3 = s3;
}
public abstract int getVolume();
}
class Sphere extends ThreeDimensionalShape {
public Sphere(int randius) {
super(randius, randius, randius);
}
@Override
public int getVolume() {
return (int) ((int) Math.PI * super.s1 * super.s1 * super.s1 *
0.75);
}
@Override
public String getName() {
return "Hinh cau ";
}
@Override
public void print() {
// TODO Auto-generated method stub
System.out.println("Co ban kinh = " + super.getS1());
}
}
class Cube extends ThreeDimensionalShape {
public Cube(int s1, int s2) {
super(s1, s2, 0);
}
@Override
public int getVolume() {
return (int) (Math.PI * super.s1 * super.s1 * super.s2);
}
@Override
public String getName() {
return "Hinh tru";
}
@Override
public void print() {
System.out.println("Co ban kinh
"

= " + super.getS1() + " chieu cao =

+ super.getS2());
}

}
class Tetrahedron extends ThreeDimensionalShape {
public Tetrahedron(int s1, int s2, int s3) {
super(s1, s2, s3);
// TODO Auto-generated constructor stub
}
@Override
public int getVolume() {
return super.s1 * super.s2 * super.s3;
}
@Override
public String getName() {
return "Hinh hop";
}
@Override
public void print() {
System.out.println("Chieu rong = " + super.s1 + " chiue dai = "
+ super.s2 + " chieu cao " + super.s3);
}
}
================================================================================
========
Cau 2
package pk.assignment02;
import java.util.ArrayList;
public class MyCharSequence implements CharSequence {
private ArrayList<Character> data = null;
public MyCharSequence() {
this.setData(new String());
}
@Override
public char charAt(int index) {
char c = (char) this.getData().get(index);
return c;
}
@Override
public int length() {
return getData().size();
}
@Override
public CharSequence subSequence(int start, int end) {
if (start < 0) {
throw new StringIndexOutOfBoundsException(start);
}
if (end > getData().size()) {
throw new StringIndexOutOfBoundsException(end);
}
if (start > end) {
throw new StringIndexOutOfBoundsException(start - end);
}

}

MyCharSequence ch = new MyCharSequence();
ch.setData(ch.getData().subList(start, end).toString());
return ch;

@Override
public String toString() {
String str = this.getData().toString();
return str;
}
public void setData(String data) {
ArrayList<Character> ar = new ArrayList<Character>();
char[] cArray = data.toCharArray();
for (int i = 0; i < cArray.length; i++) {
ar.add(cArray[i]);
}
this.data = ar;
}
public ArrayList<Character> getData() {
return data;
}
}
**
* Write a class that implements the CharSequence interface found in the
* java.lang package. (Javadoc API:
* http://download.oracle.com/javase/6/docs/api/java/lang/CharSequence.html)
* Your implementation should return the string backwards (in reverse order).
* Select one of the sentences from this home work to use as the data.
* Write a small main method to test your class; make sure to call all four
* methods.
*/
package pk.assignment02;
public class Program {
/**
* @param args
*/
public static void main(String[] args) {
MyCharSequence mcs = new MyCharSequence();
mcs.setData("Fresher01DN");
char c = mcs.charAt(2);
MyCharSequence mcs2 = (MyCharSequence) mcs.subSequence(0, 4);
String str = mcs.toString();
int mcsLength = mcs.length();
}
}

Contenu connexe

Tendances

The Ring programming language version 1.5.1 book - Part 44 of 180
The Ring programming language version 1.5.1 book - Part 44 of 180The Ring programming language version 1.5.1 book - Part 44 of 180
The Ring programming language version 1.5.1 book - Part 44 of 180Mahmoud Samir Fayed
 
Class Customization and Better Code
Class Customization and Better CodeClass Customization and Better Code
Class Customization and Better CodeStronnics
 
QA Auotmation Java programs,theory
QA Auotmation Java programs,theory QA Auotmation Java programs,theory
QA Auotmation Java programs,theory archana singh
 
Math quota-cmu-g-455
Math quota-cmu-g-455Math quota-cmu-g-455
Math quota-cmu-g-455Rungroj Ssan
 
Rデバッグあれこれ
RデバッグあれこれRデバッグあれこれ
RデバッグあれこれTakeshi Arabiki
 
The Ring programming language version 1.5.2 book - Part 24 of 181
The Ring programming language version 1.5.2 book - Part 24 of 181The Ring programming language version 1.5.2 book - Part 24 of 181
The Ring programming language version 1.5.2 book - Part 24 of 181Mahmoud Samir Fayed
 
Clustering com numpy e cython
Clustering com numpy e cythonClustering com numpy e cython
Clustering com numpy e cythonAnderson Dantas
 
The Ring programming language version 1.5.3 book - Part 44 of 184
The Ring programming language version 1.5.3 book - Part 44 of 184The Ring programming language version 1.5.3 book - Part 44 of 184
The Ring programming language version 1.5.3 book - Part 44 of 184Mahmoud Samir Fayed
 
関数潮流(Function Tendency)
関数潮流(Function Tendency)関数潮流(Function Tendency)
関数潮流(Function Tendency)riue
 
ゼロから始めるScala文法
ゼロから始めるScala文法ゼロから始めるScala文法
ゼロから始めるScala文法Ryuichi ITO
 
Map/reduce, geospatial indexing, and other cool features (Kristina Chodorow)
Map/reduce, geospatial indexing, and other cool features (Kristina Chodorow)Map/reduce, geospatial indexing, and other cool features (Kristina Chodorow)
Map/reduce, geospatial indexing, and other cool features (Kristina Chodorow)MongoSF
 
Rのスコープとフレームと環境と
Rのスコープとフレームと環境とRのスコープとフレームと環境と
Rのスコープとフレームと環境とTakeshi Arabiki
 
Functional microscope - Lenses in C++
Functional microscope - Lenses in C++Functional microscope - Lenses in C++
Functional microscope - Lenses in C++Alexander Granin
 
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
 
Building Real Time Systems on MongoDB Using the Oplog at Stripe
Building Real Time Systems on MongoDB Using the Oplog at StripeBuilding Real Time Systems on MongoDB Using the Oplog at Stripe
Building Real Time Systems on MongoDB Using the Oplog at StripeMongoDB
 
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
 
Mobile Game and Application with J2ME
Mobile Gameand Application with J2MEMobile Gameand Application with J2ME
Mobile Game and Application with J2MEJenchoke Tachagomain
 
Mobile Game and Application with J2ME - Collision Detection
Mobile Gameand Application withJ2ME  - Collision DetectionMobile Gameand Application withJ2ME  - Collision Detection
Mobile Game and Application with J2ME - Collision DetectionJenchoke Tachagomain
 
Bank management system project in c++ with graphics
Bank management system project in c++ with graphicsBank management system project in c++ with graphics
Bank management system project in c++ with graphicsVtech Academy of Computers
 

Tendances (20)

The Ring programming language version 1.5.1 book - Part 44 of 180
The Ring programming language version 1.5.1 book - Part 44 of 180The Ring programming language version 1.5.1 book - Part 44 of 180
The Ring programming language version 1.5.1 book - Part 44 of 180
 
Class Customization and Better Code
Class Customization and Better CodeClass Customization and Better Code
Class Customization and Better Code
 
QA Auotmation Java programs,theory
QA Auotmation Java programs,theory QA Auotmation Java programs,theory
QA Auotmation Java programs,theory
 
Math quota-cmu-g-455
Math quota-cmu-g-455Math quota-cmu-g-455
Math quota-cmu-g-455
 
Rデバッグあれこれ
RデバッグあれこれRデバッグあれこれ
Rデバッグあれこれ
 
The Ring programming language version 1.5.2 book - Part 24 of 181
The Ring programming language version 1.5.2 book - Part 24 of 181The Ring programming language version 1.5.2 book - Part 24 of 181
The Ring programming language version 1.5.2 book - Part 24 of 181
 
Clustering com numpy e cython
Clustering com numpy e cythonClustering com numpy e cython
Clustering com numpy e cython
 
The Ring programming language version 1.5.3 book - Part 44 of 184
The Ring programming language version 1.5.3 book - Part 44 of 184The Ring programming language version 1.5.3 book - Part 44 of 184
The Ring programming language version 1.5.3 book - Part 44 of 184
 
関数潮流(Function Tendency)
関数潮流(Function Tendency)関数潮流(Function Tendency)
関数潮流(Function Tendency)
 
ゼロから始めるScala文法
ゼロから始めるScala文法ゼロから始めるScala文法
ゼロから始めるScala文法
 
Map/reduce, geospatial indexing, and other cool features (Kristina Chodorow)
Map/reduce, geospatial indexing, and other cool features (Kristina Chodorow)Map/reduce, geospatial indexing, and other cool features (Kristina Chodorow)
Map/reduce, geospatial indexing, and other cool features (Kristina Chodorow)
 
Rのスコープとフレームと環境と
Rのスコープとフレームと環境とRのスコープとフレームと環境と
Rのスコープとフレームと環境と
 
Functional microscope - Lenses in C++
Functional microscope - Lenses in C++Functional microscope - Lenses in C++
Functional microscope - Lenses in C++
 
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
 
Rkf
RkfRkf
Rkf
 
Building Real Time Systems on MongoDB Using the Oplog at Stripe
Building Real Time Systems on MongoDB Using the Oplog at StripeBuilding Real Time Systems on MongoDB Using the Oplog at Stripe
Building Real Time Systems on MongoDB Using the Oplog at Stripe
 
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]
 
Mobile Game and Application with J2ME
Mobile Gameand Application with J2MEMobile Gameand Application with J2ME
Mobile Game and Application with J2ME
 
Mobile Game and Application with J2ME - Collision Detection
Mobile Gameand Application withJ2ME  - Collision DetectionMobile Gameand Application withJ2ME  - Collision Detection
Mobile Game and Application with J2ME - Collision Detection
 
Bank management system project in c++ with graphics
Bank management system project in c++ with graphicsBank management system project in c++ with graphics
Bank management system project in c++ with graphics
 

Similaire à Ass2 1 (2)

Im trying again -Okay, Im in need of some help - this is the c.pdf
Im trying again -Okay, Im in need of some help - this is the c.pdfIm trying again -Okay, Im in need of some help - this is the c.pdf
Im trying again -Okay, Im in need of some help - this is the c.pdfeyeonsecuritysystems
 
Java осень 2012 лекция 2
Java осень 2012 лекция 2Java осень 2012 лекция 2
Java осень 2012 лекция 2Technopark
 
include ltiostreamgt include ltstringgt include .pdf
include ltiostreamgt include ltstringgt include .pdfinclude ltiostreamgt include ltstringgt include .pdf
include ltiostreamgt include ltstringgt include .pdfcontact32
 
i need an input of this program.  anything good or bad.  what could .docx
i need an input of this program.  anything good or bad.  what could .docxi need an input of this program.  anything good or bad.  what could .docx
i need an input of this program.  anything good or bad.  what could .docxursabrooks36447
 
TypeScript Introduction
TypeScript IntroductionTypeScript Introduction
TypeScript IntroductionDmitry Sheiko
 
NewTetrisScore.cppNewTetrisScore.cpp newTetris.cpp  Defines t.docx
NewTetrisScore.cppNewTetrisScore.cpp newTetris.cpp  Defines t.docxNewTetrisScore.cppNewTetrisScore.cpp newTetris.cpp  Defines t.docx
NewTetrisScore.cppNewTetrisScore.cpp newTetris.cpp  Defines t.docxcurwenmichaela
 
Java весна 2013 лекция 2
Java весна 2013 лекция 2Java весна 2013 лекция 2
Java весна 2013 лекция 2Technopark
 
source-code-program-menghitung-gaji-pegawai
source-code-program-menghitung-gaji-pegawaisource-code-program-menghitung-gaji-pegawai
source-code-program-menghitung-gaji-pegawaiKang Fatur
 
Data Structures Using C Practical File
Data Structures Using C Practical File Data Structures Using C Practical File
Data Structures Using C Practical File Rahul Chugh
 
連邦の白いヤツ 「Objective-C」
連邦の白いヤツ 「Objective-C」連邦の白いヤツ 「Objective-C」
連邦の白いヤツ 「Objective-C」matuura_core
 
TDC2016POA | Trilha .NET - CQRS e ES na prática com RavenDB
TDC2016POA | Trilha .NET - CQRS e ES na prática com RavenDBTDC2016POA | Trilha .NET - CQRS e ES na prática com RavenDB
TDC2016POA | Trilha .NET - CQRS e ES na prática com RavenDBtdc-globalcode
 
Kotlin @ Coupang Backend 2017
Kotlin @ Coupang Backend 2017Kotlin @ Coupang Backend 2017
Kotlin @ Coupang Backend 2017Sunghyouk Bae
 

Similaire à Ass2 1 (2) (20)

Im trying again -Okay, Im in need of some help - this is the c.pdf
Im trying again -Okay, Im in need of some help - this is the c.pdfIm trying again -Okay, Im in need of some help - this is the c.pdf
Im trying again -Okay, Im in need of some help - this is the c.pdf
 
C++ programs
C++ programsC++ programs
C++ programs
 
Java осень 2012 лекция 2
Java осень 2012 лекция 2Java осень 2012 лекция 2
Java осень 2012 лекция 2
 
include ltiostreamgt include ltstringgt include .pdf
include ltiostreamgt include ltstringgt include .pdfinclude ltiostreamgt include ltstringgt include .pdf
include ltiostreamgt include ltstringgt include .pdf
 
Stop Monkeys Fall
Stop Monkeys FallStop Monkeys Fall
Stop Monkeys Fall
 
i need an input of this program.  anything good or bad.  what could .docx
i need an input of this program.  anything good or bad.  what could .docxi need an input of this program.  anything good or bad.  what could .docx
i need an input of this program.  anything good or bad.  what could .docx
 
Java VS Python
Java VS PythonJava VS Python
Java VS Python
 
TypeScript Introduction
TypeScript IntroductionTypeScript Introduction
TypeScript Introduction
 
NewTetrisScore.cppNewTetrisScore.cpp newTetris.cpp  Defines t.docx
NewTetrisScore.cppNewTetrisScore.cpp newTetris.cpp  Defines t.docxNewTetrisScore.cppNewTetrisScore.cpp newTetris.cpp  Defines t.docx
NewTetrisScore.cppNewTetrisScore.cpp newTetris.cpp  Defines t.docx
 
Anti patterns
Anti patternsAnti patterns
Anti patterns
 
Java весна 2013 лекция 2
Java весна 2013 лекция 2Java весна 2013 лекция 2
Java весна 2013 лекция 2
 
source-code-program-menghitung-gaji-pegawai
source-code-program-menghitung-gaji-pegawaisource-code-program-menghitung-gaji-pegawai
source-code-program-menghitung-gaji-pegawai
 
Data Structures Using C Practical File
Data Structures Using C Practical File Data Structures Using C Practical File
Data Structures Using C Practical File
 
7 inheritance
7 inheritance7 inheritance
7 inheritance
 
連邦の白いヤツ 「Objective-C」
連邦の白いヤツ 「Objective-C」連邦の白いヤツ 「Objective-C」
連邦の白いヤツ 「Objective-C」
 
Blocks+gcd入門
Blocks+gcd入門Blocks+gcd入門
Blocks+gcd入門
 
14 thread
14 thread14 thread
14 thread
 
TDC2016POA | Trilha .NET - CQRS e ES na prática com RavenDB
TDC2016POA | Trilha .NET - CQRS e ES na prática com RavenDBTDC2016POA | Trilha .NET - CQRS e ES na prática com RavenDB
TDC2016POA | Trilha .NET - CQRS e ES na prática com RavenDB
 
Tugas 2
Tugas 2Tugas 2
Tugas 2
 
Kotlin @ Coupang Backend 2017
Kotlin @ Coupang Backend 2017Kotlin @ Coupang Backend 2017
Kotlin @ Coupang Backend 2017
 

Plus de vacbalolenvadi90 (7)

Java day9n
Java day9nJava day9n
Java day9n
 
Quiz test JDBC
Quiz test JDBCQuiz test JDBC
Quiz test JDBC
 
Bai day1
Bai day1Bai day1
Bai day1
 
Final
FinalFinal
Final
 
sqlKey
sqlKeysqlKey
sqlKey
 
Abcxyz
AbcxyzAbcxyz
Abcxyz
 
SQL DdaHKH Huế
SQL DdaHKH HuếSQL DdaHKH Huế
SQL DdaHKH Huế
 

Dernier

2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...Martijn de Jong
 
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...gurkirankumar98700
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024Rafal Los
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountPuma Security, LLC
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processorsdebabhi2
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking MenDelhi Call girls
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonetsnaman860154
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsMaria Levchenko
 
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live StreamsTop 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live StreamsRoshan Dwivedi
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptxHampshireHUG
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024The Digital Insurer
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking MenDelhi Call girls
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityPrincipled Technologies
 
Developing An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of BrazilDeveloping An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of BrazilV3cube
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreternaman860154
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024The Digital Insurer
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationRadu Cotescu
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘RTylerCroy
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Scriptwesley chun
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...Neo4j
 

Dernier (20)

2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path Mount
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live StreamsTop 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
Developing An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of BrazilDeveloping An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of Brazil
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 

Ass2 1 (2)

  • 1. //https://code.google.com/p/fresher01dn/source/browse/trunk/?r=13#trunk %2FJavaEE_Day03%2Fsrc%2Fpk%2Fassignment01 public class Main { private Shape shapeArray[]; private TwoDimensionalShape twoDArray[]; private ThreeDimensionalShape threeDimensionalShape[]; public Main() { shapeArray = new Shape[6]; twoDArray = new TwoDimensionalShape[3]; threeDimensionalShape = new ThreeDimensionalShape[3]; Circle circle = new Circle(5); Square square = new Square(5); Triangle triangle = new Triangle(3, 4, 5); Sphere sphere = new Sphere(5); Cube cube = new Cube(3, 4); Tetrahedron tetrahedron = new Tetrahedron(3, 5, 6); shapeArray[0] = circle; twoDArray[0] = circle; shapeArray[1] = square; twoDArray[1] = square; shapeArray[2] = triangle; twoDArray[2] = triangle; shapeArray[3] = sphere; threeDimensionalShape[0] = sphere; shapeArray[4] = cube; threeDimensionalShape[1] = sphere; shapeArray[5] = sphere; threeDimensionalShape[2] = tetrahedron; } public void displayShapeInfo() { for (int i = 0; i < shapeArray.length; i++) { System.out.print(shapeArray[i].getName() + " "); shapeArray[i].print(); } System.out.println("============================================"); for (int i = 0; i < twoDArray.length; i++) { System.out.println(twoDArray[i].getName() + " co dien tich : " + twoDArray[i].getArea()); } for (int i = 0; i < threeDimensionalShape.length; i++) { System.out.println(threeDimensionalShape[i].getName() +" co the tich "+ threeDimensionalShape[i].getVolume()); } } public static void main(String[] args) { Main m = new Main(); m.displayShapeInfo(); } } ============================================ public abstract class Shape { // abstract methods public abstract String getName(); public abstract void print(); } ================================================= public abstract class TwoDimensionalShape extends Shape {
  • 2. private int s1, s2,s3; public TwoDimensionalShape( int s1, int s2,int s3) { this.s1 = s1; this.s2 = s2; this.s3 = s3; } public int getS1() { return s1; } public void setS1(int s1) { this.s1 = s1; } public int getS3() { return s3; } public void setS3(int s3) { this.s3 = s3; } public int getS2() { return s2; } public void setS2(int s2) { this.s2 = s2; } public abstract int getArea(); } class Circle extends TwoDimensionalShape{ public Circle( int radius) { super( radius, radius,radius); } @Override public int getArea() { return (int)Math.PI *super.getS1()*super.getS1(); } @Override public String getName() { // TODO Auto-generated method stub return "Hinh tron"; } @Override public void print() { } System.out.println("co ban kinh = " + super.getS1()+" "); } class Square extends TwoDimensionalShape{ public Square(int canh) { super(canh, canh,canh);
  • 3. } @Override public int getArea() { return super.getS1()*super.getS1(); } @Override public String getName() { // TODO Auto-generated method stub return "Hinh vuong"; } @Override public void print() { // TODO Auto-generated method stub System.out.println("Co canh = "+ super.getS1()); } } class Triangle extends TwoDimensionalShape{ public Triangle(int canh1, int canh2,int canh3) { super(canh1, canh2, canh3); // TODO Auto-generated constructor stub } @Override public int getArea() { // TODO Auto-generated method stub int sTamGiac = 0; // s = căn[p.(p - a)(p - b)(p - c)] // trong ăó p = (a + b + c)2 float p = (super.getS1()+super.getS2()+super.getS3())/2; sTamGiac =(int) Math.sqrt(p*( p -super.getS1())*(psuper.getS2())*(p-super.getS3())); return sTamGiac; } @Override public String getName() { // TODO Auto-generated method stub return "Hinh tam giac"; } @Override public void print() { // TODO Auto-generated method stub System.out.println("Co canh 1 = " +super.getS1() +" Canh 2 = "+ super.getS2() + " Canh 3 = "+ super.getS3()); } } ==================================================== public abstract class ThreeDimensionalShape extends Shape { public int getS1() { return s1; } public void setS1(int s1) { this.s1 = s1; }
  • 4. public int getS2() { return s2; } public void setS2(int s2) { this.s2 = s2; } public int getS3() { return s3; } public void setS3(int s3) { this.s3 = s3; } int s1, s2, s3; public ThreeDimensionalShape(int s1, int s2, int s3) { this.s1 = s1; this.s2 = s2; this.s3 = s3; } public abstract int getVolume(); } class Sphere extends ThreeDimensionalShape { public Sphere(int randius) { super(randius, randius, randius); } @Override public int getVolume() { return (int) ((int) Math.PI * super.s1 * super.s1 * super.s1 * 0.75); } @Override public String getName() { return "Hinh cau "; } @Override public void print() { // TODO Auto-generated method stub System.out.println("Co ban kinh = " + super.getS1()); } } class Cube extends ThreeDimensionalShape { public Cube(int s1, int s2) { super(s1, s2, 0); } @Override public int getVolume() { return (int) (Math.PI * super.s1 * super.s1 * super.s2); }
  • 5. @Override public String getName() { return "Hinh tru"; } @Override public void print() { System.out.println("Co ban kinh " = " + super.getS1() + " chieu cao = + super.getS2()); } } class Tetrahedron extends ThreeDimensionalShape { public Tetrahedron(int s1, int s2, int s3) { super(s1, s2, s3); // TODO Auto-generated constructor stub } @Override public int getVolume() { return super.s1 * super.s2 * super.s3; } @Override public String getName() { return "Hinh hop"; } @Override public void print() { System.out.println("Chieu rong = " + super.s1 + " chiue dai = " + super.s2 + " chieu cao " + super.s3); } } ================================================================================ ======== Cau 2 package pk.assignment02; import java.util.ArrayList; public class MyCharSequence implements CharSequence { private ArrayList<Character> data = null; public MyCharSequence() { this.setData(new String()); } @Override public char charAt(int index) { char c = (char) this.getData().get(index); return c; } @Override public int length() { return getData().size(); }
  • 6. @Override public CharSequence subSequence(int start, int end) { if (start < 0) { throw new StringIndexOutOfBoundsException(start); } if (end > getData().size()) { throw new StringIndexOutOfBoundsException(end); } if (start > end) { throw new StringIndexOutOfBoundsException(start - end); } } MyCharSequence ch = new MyCharSequence(); ch.setData(ch.getData().subList(start, end).toString()); return ch; @Override public String toString() { String str = this.getData().toString(); return str; } public void setData(String data) { ArrayList<Character> ar = new ArrayList<Character>(); char[] cArray = data.toCharArray(); for (int i = 0; i < cArray.length; i++) { ar.add(cArray[i]); } this.data = ar; } public ArrayList<Character> getData() { return data; } } ** * Write a class that implements the CharSequence interface found in the * java.lang package. (Javadoc API: * http://download.oracle.com/javase/6/docs/api/java/lang/CharSequence.html) * Your implementation should return the string backwards (in reverse order). * Select one of the sentences from this home work to use as the data. * Write a small main method to test your class; make sure to call all four * methods. */ package pk.assignment02; public class Program { /** * @param args */ public static void main(String[] args) { MyCharSequence mcs = new MyCharSequence(); mcs.setData("Fresher01DN"); char c = mcs.charAt(2); MyCharSequence mcs2 = (MyCharSequence) mcs.subSequence(0, 4); String str = mcs.toString(); int mcsLength = mcs.length(); }
  • 7. }