SlideShare ist ein Scribd-Unternehmen logo
1 von 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();
}
}

Weitere ähnliche Inhalte

Was ist angesagt?

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
 

Was ist angesagt? (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
 

Ähnlich wie 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
 

Ähnlich wie 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
 

Mehr von 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ế
 

Kürzlich hochgeladen

Maximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxMaximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxOnBoard
 
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
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Allon Mureinik
 
Pigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions
 
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
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsMark Billinghurst
 
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
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxKatpro Technologies
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking MenDelhi Call girls
 
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024BookNet Canada
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticscarlostorres15106
 
SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024Scott Keck-Warren
 
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersEnhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersThousandEyes
 
Benefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksBenefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksSoftradix Technologies
 
AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsMemoori
 
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Alan Dix
 
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
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machinePadma Pradeep
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsEnterprise Knowledge
 

Kürzlich hochgeladen (20)

Maximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxMaximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptx
 
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
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)
 
Pigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food Manufacturing
 
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
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR Systems
 
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
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
 
SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024
 
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersEnhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
 
Benefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksBenefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other Frameworks
 
AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial Buildings
 
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
 
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
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machine
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 

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