SlideShare una empresa de Scribd logo
1 de 2
Descargar para leer sin conexión
To compile Java class: lic class Triangle { // Instance variables for 3 triangle sides private String
side1; private String side2; private String side3; // Constructors public Triangle() { // a default
triangle this("0", "0", "0"); }
public class Triangle {
// Instance variables for 3 triangle sides
private String side1;
private String side2;
private String side3;
// Constructors
public Triangle() {
// a default triangle
this("0", "0", "0");
}
public Triangle(String str1, String str2, String str3) {
this.side1 = str1;
this.side2 = str2;
this.side3 = str3;
}
// Instance methods
public String triangleType() {
String type = "";
int s1 = 0, s2 = 0, s3 = 0;
String errMessage = "";
try {
s1 = Integer.parseInt(side1);
} catch (NumberFormatException e) {
errMessage += "The side 1 is not an integer number.nn";
}
try {
s2 = Integer.parseInt(side2);
} catch (NumberFormatException e) {
errMessage += "The side 2 is not an integer number.nn";
}
try {
s3 = Integer.parseInt(side3);
} catch (NumberFormatException e) {
errMessage += "The side 3 is not an integer number.nn";
}
// Check for a negative side
if (s1 < 0 || s2 < 0 || s3 < 0) {
errMessage += "At least one side is negative!n";
}
// Check for vaide sides
if ((s1 + s2 <= s3) || (s1 + s3 <= s2) || (s2 + s3 <= s1)) {
errMessage += "Not a valid triangle!n";
}
if (s1 + s2 + s3 > 1000) {
errMessage += "This triangle is too big.n";
}
if (errMessage.length() > 0) {
type = errMessage ;
}
else {
if ((s1 == s2) && (s2 == s3)) {
type = "This is an equilateral triangle. ";
}
else if (( s1 == s2) || (s2 == s3) || (s1 == s3)) {
type = "This is an isosceles triangle. ";
}
else {
type = "This is a scalene triangle. ";
}
}
return type;
}
}
To compile Java class: javac Triangle.java
To compile JUnit test: javac -cp junit.jar;. TriangleTest.java
To run JUnit test: java -cp junit.jar;hamcrest-core.jar;. org.junit.runner.JUnitCore TriangleTest

Más contenido relacionado

Más de ajayadinathcomputers

True or False Please explain Consider the relationship betw.pdf
True or False Please explain Consider the relationship betw.pdfTrue or False Please explain Consider the relationship betw.pdf
True or False Please explain Consider the relationship betw.pdfajayadinathcomputers
 
True or False Four Asian Tigers Four Little Dragons we.pdf
True or False Four Asian Tigers Four Little Dragons we.pdfTrue or False Four Asian Tigers Four Little Dragons we.pdf
True or False Four Asian Tigers Four Little Dragons we.pdfajayadinathcomputers
 
Trinity Ltd owns a building which it acquired on 1 January 2.pdf
Trinity Ltd owns a building which it acquired on 1 January 2.pdfTrinity Ltd owns a building which it acquired on 1 January 2.pdf
Trinity Ltd owns a building which it acquired on 1 January 2.pdfajayadinathcomputers
 
Truck Inspection Violations The probabilities are 0301 a.pdf
Truck Inspection Violations The probabilities are 0301 a.pdfTruck Inspection Violations The probabilities are 0301 a.pdf
Truck Inspection Violations The probabilities are 0301 a.pdfajayadinathcomputers
 
Tres aos hace Mario se uni a MN Partnership aportando t.pdf
Tres aos hace Mario se uni a MN Partnership aportando t.pdfTres aos hace Mario se uni a MN Partnership aportando t.pdf
Tres aos hace Mario se uni a MN Partnership aportando t.pdfajayadinathcomputers
 
Trey Monson starts a merchandising business on December 1 an.pdf
Trey Monson starts a merchandising business on December 1 an.pdfTrey Monson starts a merchandising business on December 1 an.pdf
Trey Monson starts a merchandising business on December 1 an.pdfajayadinathcomputers
 
Trez Company began operations this year During this year t.pdf
Trez Company began operations this year During this year t.pdfTrez Company began operations this year During this year t.pdf
Trez Company began operations this year During this year t.pdfajayadinathcomputers
 
Tratando de atrapar el descanso Su amigo Jared est conster.pdf
Tratando de atrapar el descanso Su amigo Jared est conster.pdfTratando de atrapar el descanso Su amigo Jared est conster.pdf
Tratando de atrapar el descanso Su amigo Jared est conster.pdfajayadinathcomputers
 
Travis est haciendo sus compras de comestibles La sanda h.pdf
Travis est haciendo sus compras de comestibles La sanda h.pdfTravis est haciendo sus compras de comestibles La sanda h.pdf
Travis est haciendo sus compras de comestibles La sanda h.pdfajayadinathcomputers
 
Topic Obstructive Sleep Apnea Explain why this topic is imp.pdf
Topic Obstructive Sleep Apnea Explain why this topic is imp.pdfTopic Obstructive Sleep Apnea Explain why this topic is imp.pdf
Topic Obstructive Sleep Apnea Explain why this topic is imp.pdfajayadinathcomputers
 
Toplam operasyon planlamas iin kesvedene yntemini kullan.pdf
Toplam operasyon planlamas iin kesvedene yntemini kullan.pdfToplam operasyon planlamas iin kesvedene yntemini kullan.pdf
Toplam operasyon planlamas iin kesvedene yntemini kullan.pdfajayadinathcomputers
 
Tom est diseando una nueva planta qumica Una de sus resp.pdf
Tom est diseando una nueva planta qumica Una de sus resp.pdfTom est diseando una nueva planta qumica Una de sus resp.pdf
Tom est diseando una nueva planta qumica Una de sus resp.pdfajayadinathcomputers
 
Toplumsal bir soruna cinsiyet eitlii alk isizlik genli.pdf
Toplumsal bir soruna cinsiyet eitlii alk isizlik genli.pdfToplumsal bir soruna cinsiyet eitlii alk isizlik genli.pdf
Toplumsal bir soruna cinsiyet eitlii alk isizlik genli.pdfajayadinathcomputers
 
Todo lo siguiente es cierto sobre los Acuerdos de confidenci.pdf
Todo lo siguiente es cierto sobre los Acuerdos de confidenci.pdfTodo lo siguiente es cierto sobre los Acuerdos de confidenci.pdf
Todo lo siguiente es cierto sobre los Acuerdos de confidenci.pdfajayadinathcomputers
 
to thite decimol pacen a Ax4 b Ax8 5 2t points.pdf
to thite decimol pacen a Ax4 b Ax8  5 2t points.pdfto thite decimol pacen a Ax4 b Ax8  5 2t points.pdf
to thite decimol pacen a Ax4 b Ax8 5 2t points.pdfajayadinathcomputers
 
Todds Direct a major TV salos chain heedquartered in New O.pdf
Todds Direct a major TV salos chain heedquartered in New O.pdfTodds Direct a major TV salos chain heedquartered in New O.pdf
Todds Direct a major TV salos chain heedquartered in New O.pdfajayadinathcomputers
 
Toca el piano Georgianna afirma que en una pequea ciudad f.pdf
Toca el piano Georgianna afirma que en una pequea ciudad f.pdfToca el piano Georgianna afirma que en una pequea ciudad f.pdf
Toca el piano Georgianna afirma que en una pequea ciudad f.pdfajayadinathcomputers
 
Topics ifelse if Description Write a program that calculate.pdf
Topics ifelse if Description Write a program that calculate.pdfTopics ifelse if Description Write a program that calculate.pdf
Topics ifelse if Description Write a program that calculate.pdfajayadinathcomputers
 
TOPIC DEVELOPMENT OF A NEW MOBILE APPLICATION FOR A FITNESS.pdf
TOPIC DEVELOPMENT OF A NEW MOBILE APPLICATION FOR A FITNESS.pdfTOPIC DEVELOPMENT OF A NEW MOBILE APPLICATION FOR A FITNESS.pdf
TOPIC DEVELOPMENT OF A NEW MOBILE APPLICATION FOR A FITNESS.pdfajayadinathcomputers
 
Top managers of Kyler Industries predicted 2024 sales of 14.pdf
Top managers of Kyler Industries predicted 2024 sales of 14.pdfTop managers of Kyler Industries predicted 2024 sales of 14.pdf
Top managers of Kyler Industries predicted 2024 sales of 14.pdfajayadinathcomputers
 

Más de ajayadinathcomputers (20)

True or False Please explain Consider the relationship betw.pdf
True or False Please explain Consider the relationship betw.pdfTrue or False Please explain Consider the relationship betw.pdf
True or False Please explain Consider the relationship betw.pdf
 
True or False Four Asian Tigers Four Little Dragons we.pdf
True or False Four Asian Tigers Four Little Dragons we.pdfTrue or False Four Asian Tigers Four Little Dragons we.pdf
True or False Four Asian Tigers Four Little Dragons we.pdf
 
Trinity Ltd owns a building which it acquired on 1 January 2.pdf
Trinity Ltd owns a building which it acquired on 1 January 2.pdfTrinity Ltd owns a building which it acquired on 1 January 2.pdf
Trinity Ltd owns a building which it acquired on 1 January 2.pdf
 
Truck Inspection Violations The probabilities are 0301 a.pdf
Truck Inspection Violations The probabilities are 0301 a.pdfTruck Inspection Violations The probabilities are 0301 a.pdf
Truck Inspection Violations The probabilities are 0301 a.pdf
 
Tres aos hace Mario se uni a MN Partnership aportando t.pdf
Tres aos hace Mario se uni a MN Partnership aportando t.pdfTres aos hace Mario se uni a MN Partnership aportando t.pdf
Tres aos hace Mario se uni a MN Partnership aportando t.pdf
 
Trey Monson starts a merchandising business on December 1 an.pdf
Trey Monson starts a merchandising business on December 1 an.pdfTrey Monson starts a merchandising business on December 1 an.pdf
Trey Monson starts a merchandising business on December 1 an.pdf
 
Trez Company began operations this year During this year t.pdf
Trez Company began operations this year During this year t.pdfTrez Company began operations this year During this year t.pdf
Trez Company began operations this year During this year t.pdf
 
Tratando de atrapar el descanso Su amigo Jared est conster.pdf
Tratando de atrapar el descanso Su amigo Jared est conster.pdfTratando de atrapar el descanso Su amigo Jared est conster.pdf
Tratando de atrapar el descanso Su amigo Jared est conster.pdf
 
Travis est haciendo sus compras de comestibles La sanda h.pdf
Travis est haciendo sus compras de comestibles La sanda h.pdfTravis est haciendo sus compras de comestibles La sanda h.pdf
Travis est haciendo sus compras de comestibles La sanda h.pdf
 
Topic Obstructive Sleep Apnea Explain why this topic is imp.pdf
Topic Obstructive Sleep Apnea Explain why this topic is imp.pdfTopic Obstructive Sleep Apnea Explain why this topic is imp.pdf
Topic Obstructive Sleep Apnea Explain why this topic is imp.pdf
 
Toplam operasyon planlamas iin kesvedene yntemini kullan.pdf
Toplam operasyon planlamas iin kesvedene yntemini kullan.pdfToplam operasyon planlamas iin kesvedene yntemini kullan.pdf
Toplam operasyon planlamas iin kesvedene yntemini kullan.pdf
 
Tom est diseando una nueva planta qumica Una de sus resp.pdf
Tom est diseando una nueva planta qumica Una de sus resp.pdfTom est diseando una nueva planta qumica Una de sus resp.pdf
Tom est diseando una nueva planta qumica Una de sus resp.pdf
 
Toplumsal bir soruna cinsiyet eitlii alk isizlik genli.pdf
Toplumsal bir soruna cinsiyet eitlii alk isizlik genli.pdfToplumsal bir soruna cinsiyet eitlii alk isizlik genli.pdf
Toplumsal bir soruna cinsiyet eitlii alk isizlik genli.pdf
 
Todo lo siguiente es cierto sobre los Acuerdos de confidenci.pdf
Todo lo siguiente es cierto sobre los Acuerdos de confidenci.pdfTodo lo siguiente es cierto sobre los Acuerdos de confidenci.pdf
Todo lo siguiente es cierto sobre los Acuerdos de confidenci.pdf
 
to thite decimol pacen a Ax4 b Ax8 5 2t points.pdf
to thite decimol pacen a Ax4 b Ax8  5 2t points.pdfto thite decimol pacen a Ax4 b Ax8  5 2t points.pdf
to thite decimol pacen a Ax4 b Ax8 5 2t points.pdf
 
Todds Direct a major TV salos chain heedquartered in New O.pdf
Todds Direct a major TV salos chain heedquartered in New O.pdfTodds Direct a major TV salos chain heedquartered in New O.pdf
Todds Direct a major TV salos chain heedquartered in New O.pdf
 
Toca el piano Georgianna afirma que en una pequea ciudad f.pdf
Toca el piano Georgianna afirma que en una pequea ciudad f.pdfToca el piano Georgianna afirma que en una pequea ciudad f.pdf
Toca el piano Georgianna afirma que en una pequea ciudad f.pdf
 
Topics ifelse if Description Write a program that calculate.pdf
Topics ifelse if Description Write a program that calculate.pdfTopics ifelse if Description Write a program that calculate.pdf
Topics ifelse if Description Write a program that calculate.pdf
 
TOPIC DEVELOPMENT OF A NEW MOBILE APPLICATION FOR A FITNESS.pdf
TOPIC DEVELOPMENT OF A NEW MOBILE APPLICATION FOR A FITNESS.pdfTOPIC DEVELOPMENT OF A NEW MOBILE APPLICATION FOR A FITNESS.pdf
TOPIC DEVELOPMENT OF A NEW MOBILE APPLICATION FOR A FITNESS.pdf
 
Top managers of Kyler Industries predicted 2024 sales of 14.pdf
Top managers of Kyler Industries predicted 2024 sales of 14.pdfTop managers of Kyler Industries predicted 2024 sales of 14.pdf
Top managers of Kyler Industries predicted 2024 sales of 14.pdf
 

Último

Auchitya Theory by Kshemendra Indian Poetics
Auchitya Theory by Kshemendra Indian PoeticsAuchitya Theory by Kshemendra Indian Poetics
Auchitya Theory by Kshemendra Indian PoeticsDhatriParmar
 
How to Customise Quotation's Appearance Using PDF Quote Builder in Odoo 17
How to Customise Quotation's Appearance Using PDF Quote Builder in Odoo 17How to Customise Quotation's Appearance Using PDF Quote Builder in Odoo 17
How to Customise Quotation's Appearance Using PDF Quote Builder in Odoo 17Celine George
 
3.12.24 Freedom Summer in Mississippi.pptx
3.12.24 Freedom Summer in Mississippi.pptx3.12.24 Freedom Summer in Mississippi.pptx
3.12.24 Freedom Summer in Mississippi.pptxmary850239
 
2024.03.16 How to write better quality materials for your learners ELTABB San...
2024.03.16 How to write better quality materials for your learners ELTABB San...2024.03.16 How to write better quality materials for your learners ELTABB San...
2024.03.16 How to write better quality materials for your learners ELTABB San...Sandy Millin
 
Alamkara theory by Bhamaha Indian Poetics (1).pptx
Alamkara theory by Bhamaha Indian Poetics (1).pptxAlamkara theory by Bhamaha Indian Poetics (1).pptx
Alamkara theory by Bhamaha Indian Poetics (1).pptxDhatriParmar
 
Certification Study Group - Professional ML Engineer Session 3 (Machine Learn...
Certification Study Group - Professional ML Engineer Session 3 (Machine Learn...Certification Study Group - Professional ML Engineer Session 3 (Machine Learn...
Certification Study Group - Professional ML Engineer Session 3 (Machine Learn...gdgsurrey
 
3.14.24 The Selma March and the Voting Rights Act.pptx
3.14.24 The Selma March and the Voting Rights Act.pptx3.14.24 The Selma March and the Voting Rights Act.pptx
3.14.24 The Selma March and the Voting Rights Act.pptxmary850239
 
BÀI TẬP BỔ TRỢ TIẾNG ANH 11 THEO ĐƠN VỊ BÀI HỌC - CẢ NĂM - CÓ FILE NGHE (FRIE...
BÀI TẬP BỔ TRỢ TIẾNG ANH 11 THEO ĐƠN VỊ BÀI HỌC - CẢ NĂM - CÓ FILE NGHE (FRIE...BÀI TẬP BỔ TRỢ TIẾNG ANH 11 THEO ĐƠN VỊ BÀI HỌC - CẢ NĂM - CÓ FILE NGHE (FRIE...
BÀI TẬP BỔ TRỢ TIẾNG ANH 11 THEO ĐƠN VỊ BÀI HỌC - CẢ NĂM - CÓ FILE NGHE (FRIE...Nguyen Thanh Tu Collection
 
3.12.24 The Social Construction of Gender.pptx
3.12.24 The Social Construction of Gender.pptx3.12.24 The Social Construction of Gender.pptx
3.12.24 The Social Construction of Gender.pptxmary850239
 
BBA 205 BUSINESS ENVIRONMENT UNIT I.pptx
BBA 205 BUSINESS ENVIRONMENT UNIT I.pptxBBA 205 BUSINESS ENVIRONMENT UNIT I.pptx
BBA 205 BUSINESS ENVIRONMENT UNIT I.pptxProf. Kanchan Kumari
 
30-de-thi-vao-lop-10-mon-tieng-anh-co-dap-an.doc
30-de-thi-vao-lop-10-mon-tieng-anh-co-dap-an.doc30-de-thi-vao-lop-10-mon-tieng-anh-co-dap-an.doc
30-de-thi-vao-lop-10-mon-tieng-anh-co-dap-an.docdieu18
 
Dhavni Theory by Anandvardhana Indian Poetics
Dhavni Theory by Anandvardhana Indian PoeticsDhavni Theory by Anandvardhana Indian Poetics
Dhavni Theory by Anandvardhana Indian PoeticsDhatriParmar
 
EDD8524 The Future of Educational Leader
EDD8524 The Future of Educational LeaderEDD8524 The Future of Educational Leader
EDD8524 The Future of Educational LeaderDr. Bruce A. Johnson
 
Metabolism of lipoproteins & its disorders(Chylomicron & VLDL & LDL).pptx
Metabolism of  lipoproteins & its disorders(Chylomicron & VLDL & LDL).pptxMetabolism of  lipoproteins & its disorders(Chylomicron & VLDL & LDL).pptx
Metabolism of lipoproteins & its disorders(Chylomicron & VLDL & LDL).pptxDr. Santhosh Kumar. N
 
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - HK2 (...
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - HK2 (...HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - HK2 (...
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - HK2 (...Nguyen Thanh Tu Collection
 
ICS2208 Lecture4 Intelligent Interface Agents.pdf
ICS2208 Lecture4 Intelligent Interface Agents.pdfICS2208 Lecture4 Intelligent Interface Agents.pdf
ICS2208 Lecture4 Intelligent Interface Agents.pdfVanessa Camilleri
 
AUDIENCE THEORY - PARTICIPATORY - JENKINS.pptx
AUDIENCE THEORY - PARTICIPATORY - JENKINS.pptxAUDIENCE THEORY - PARTICIPATORY - JENKINS.pptx
AUDIENCE THEORY - PARTICIPATORY - JENKINS.pptxiammrhaywood
 
DNA and RNA , Structure, Functions, Types, difference, Similarities, Protein ...
DNA and RNA , Structure, Functions, Types, difference, Similarities, Protein ...DNA and RNA , Structure, Functions, Types, difference, Similarities, Protein ...
DNA and RNA , Structure, Functions, Types, difference, Similarities, Protein ...AKSHAYMAGAR17
 

Último (20)

Auchitya Theory by Kshemendra Indian Poetics
Auchitya Theory by Kshemendra Indian PoeticsAuchitya Theory by Kshemendra Indian Poetics
Auchitya Theory by Kshemendra Indian Poetics
 
How to Customise Quotation's Appearance Using PDF Quote Builder in Odoo 17
How to Customise Quotation's Appearance Using PDF Quote Builder in Odoo 17How to Customise Quotation's Appearance Using PDF Quote Builder in Odoo 17
How to Customise Quotation's Appearance Using PDF Quote Builder in Odoo 17
 
t-test Parametric test Biostatics and Research Methodology
t-test Parametric test Biostatics and Research Methodologyt-test Parametric test Biostatics and Research Methodology
t-test Parametric test Biostatics and Research Methodology
 
3.12.24 Freedom Summer in Mississippi.pptx
3.12.24 Freedom Summer in Mississippi.pptx3.12.24 Freedom Summer in Mississippi.pptx
3.12.24 Freedom Summer in Mississippi.pptx
 
Least Significance Difference:Biostatics and Research Methodology
Least Significance Difference:Biostatics and Research MethodologyLeast Significance Difference:Biostatics and Research Methodology
Least Significance Difference:Biostatics and Research Methodology
 
2024.03.16 How to write better quality materials for your learners ELTABB San...
2024.03.16 How to write better quality materials for your learners ELTABB San...2024.03.16 How to write better quality materials for your learners ELTABB San...
2024.03.16 How to write better quality materials for your learners ELTABB San...
 
Alamkara theory by Bhamaha Indian Poetics (1).pptx
Alamkara theory by Bhamaha Indian Poetics (1).pptxAlamkara theory by Bhamaha Indian Poetics (1).pptx
Alamkara theory by Bhamaha Indian Poetics (1).pptx
 
Certification Study Group - Professional ML Engineer Session 3 (Machine Learn...
Certification Study Group - Professional ML Engineer Session 3 (Machine Learn...Certification Study Group - Professional ML Engineer Session 3 (Machine Learn...
Certification Study Group - Professional ML Engineer Session 3 (Machine Learn...
 
3.14.24 The Selma March and the Voting Rights Act.pptx
3.14.24 The Selma March and the Voting Rights Act.pptx3.14.24 The Selma March and the Voting Rights Act.pptx
3.14.24 The Selma March and the Voting Rights Act.pptx
 
BÀI TẬP BỔ TRỢ TIẾNG ANH 11 THEO ĐƠN VỊ BÀI HỌC - CẢ NĂM - CÓ FILE NGHE (FRIE...
BÀI TẬP BỔ TRỢ TIẾNG ANH 11 THEO ĐƠN VỊ BÀI HỌC - CẢ NĂM - CÓ FILE NGHE (FRIE...BÀI TẬP BỔ TRỢ TIẾNG ANH 11 THEO ĐƠN VỊ BÀI HỌC - CẢ NĂM - CÓ FILE NGHE (FRIE...
BÀI TẬP BỔ TRỢ TIẾNG ANH 11 THEO ĐƠN VỊ BÀI HỌC - CẢ NĂM - CÓ FILE NGHE (FRIE...
 
3.12.24 The Social Construction of Gender.pptx
3.12.24 The Social Construction of Gender.pptx3.12.24 The Social Construction of Gender.pptx
3.12.24 The Social Construction of Gender.pptx
 
BBA 205 BUSINESS ENVIRONMENT UNIT I.pptx
BBA 205 BUSINESS ENVIRONMENT UNIT I.pptxBBA 205 BUSINESS ENVIRONMENT UNIT I.pptx
BBA 205 BUSINESS ENVIRONMENT UNIT I.pptx
 
30-de-thi-vao-lop-10-mon-tieng-anh-co-dap-an.doc
30-de-thi-vao-lop-10-mon-tieng-anh-co-dap-an.doc30-de-thi-vao-lop-10-mon-tieng-anh-co-dap-an.doc
30-de-thi-vao-lop-10-mon-tieng-anh-co-dap-an.doc
 
Dhavni Theory by Anandvardhana Indian Poetics
Dhavni Theory by Anandvardhana Indian PoeticsDhavni Theory by Anandvardhana Indian Poetics
Dhavni Theory by Anandvardhana Indian Poetics
 
EDD8524 The Future of Educational Leader
EDD8524 The Future of Educational LeaderEDD8524 The Future of Educational Leader
EDD8524 The Future of Educational Leader
 
Metabolism of lipoproteins & its disorders(Chylomicron & VLDL & LDL).pptx
Metabolism of  lipoproteins & its disorders(Chylomicron & VLDL & LDL).pptxMetabolism of  lipoproteins & its disorders(Chylomicron & VLDL & LDL).pptx
Metabolism of lipoproteins & its disorders(Chylomicron & VLDL & LDL).pptx
 
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - HK2 (...
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - HK2 (...HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - HK2 (...
HỌC TỐT TIẾNG ANH 11 THEO CHƯƠNG TRÌNH GLOBAL SUCCESS ĐÁP ÁN CHI TIẾT - HK2 (...
 
ICS2208 Lecture4 Intelligent Interface Agents.pdf
ICS2208 Lecture4 Intelligent Interface Agents.pdfICS2208 Lecture4 Intelligent Interface Agents.pdf
ICS2208 Lecture4 Intelligent Interface Agents.pdf
 
AUDIENCE THEORY - PARTICIPATORY - JENKINS.pptx
AUDIENCE THEORY - PARTICIPATORY - JENKINS.pptxAUDIENCE THEORY - PARTICIPATORY - JENKINS.pptx
AUDIENCE THEORY - PARTICIPATORY - JENKINS.pptx
 
DNA and RNA , Structure, Functions, Types, difference, Similarities, Protein ...
DNA and RNA , Structure, Functions, Types, difference, Similarities, Protein ...DNA and RNA , Structure, Functions, Types, difference, Similarities, Protein ...
DNA and RNA , Structure, Functions, Types, difference, Similarities, Protein ...
 

To compile Java class lic class Triangle Instance vari.pdf

  • 1. To compile Java class: lic class Triangle { // Instance variables for 3 triangle sides private String side1; private String side2; private String side3; // Constructors public Triangle() { // a default triangle this("0", "0", "0"); } public class Triangle { // Instance variables for 3 triangle sides private String side1; private String side2; private String side3; // Constructors public Triangle() { // a default triangle this("0", "0", "0"); } public Triangle(String str1, String str2, String str3) { this.side1 = str1; this.side2 = str2; this.side3 = str3; } // Instance methods public String triangleType() { String type = ""; int s1 = 0, s2 = 0, s3 = 0; String errMessage = ""; try { s1 = Integer.parseInt(side1); } catch (NumberFormatException e) { errMessage += "The side 1 is not an integer number.nn"; } try { s2 = Integer.parseInt(side2); } catch (NumberFormatException e) { errMessage += "The side 2 is not an integer number.nn"; } try { s3 = Integer.parseInt(side3); } catch (NumberFormatException e) { errMessage += "The side 3 is not an integer number.nn"; }
  • 2. // Check for a negative side if (s1 < 0 || s2 < 0 || s3 < 0) { errMessage += "At least one side is negative!n"; } // Check for vaide sides if ((s1 + s2 <= s3) || (s1 + s3 <= s2) || (s2 + s3 <= s1)) { errMessage += "Not a valid triangle!n"; } if (s1 + s2 + s3 > 1000) { errMessage += "This triangle is too big.n"; } if (errMessage.length() > 0) { type = errMessage ; } else { if ((s1 == s2) && (s2 == s3)) { type = "This is an equilateral triangle. "; } else if (( s1 == s2) || (s2 == s3) || (s1 == s3)) { type = "This is an isosceles triangle. "; } else { type = "This is a scalene triangle. "; } } return type; } } To compile Java class: javac Triangle.java To compile JUnit test: javac -cp junit.jar;. TriangleTest.java To run JUnit test: java -cp junit.jar;hamcrest-core.jar;. org.junit.runner.JUnitCore TriangleTest