SlideShare a Scribd company logo
1 of 6
Download to read offline
MultiSphere.java
public class MultiSphere
{
public static void main (String[] args)
{
Sphere sphere1 = new Sphere (12, "blue"); //blue);
Sphere sphere2 = new Sphere (13, "green"); //green);
Sphere sphere3 = new Sphere (10, "purple"); //purple);
System.out.println("Sphere 1:");
System.out.println(sphere1);
System.out.println("Sphere 2:");
System.out.println(sphere2);
System.out.println("Sphere 3:");
System.out.println(sphere3);
}
}
Sphere.java
import java.text.*;
public class Sphere
{
DecimalFormat df = new DecimalFormat("##.##");
double radius;
String colors;
public Sphere (double num, String color)
{
radius = num;
colors = color;
}
public void setRadius (double rad)
{
radius = rad;
}
public double getRadius()
{
return radius;
}
public Sphere (String Str)
{
colors = Str;
}
public void setColors (String color)
{
colors = color;
}
public String getColors()
{
return colors;
}
//calculate volume
public double SphereVolume()
{
double v = 4 * Math.PI * radius*radius*radius;
double vol = v / 3; // * Math.PI * radius*radius*radius;
return vol;
}
//calculate area
public double SphereArea()
{
double sa = 4 * Math.PI * radius*radius;
return sa;
}
public String toString()
{
String desp="";
desp+="radius :"+radius + " ";
desp+="colors :"+colors + " ";
desp+="volume :"+ df.format(SphereVolume())+ " ";
desp+="area :"+ df.format(SphereArea())+ " ";
return desp;
}
}
Output:
Sphere 1:
radius :12.0
colors :blue
volume :7238.23
area :1809.56
Sphere 2:
radius :13.0
colors :green
volume :9202.77
area :2123.72
Sphere 3:
radius :10.0
colors :purple
volume :4188.79
area :1256.64
Solution
MultiSphere.java
public class MultiSphere
{
public static void main (String[] args)
{
Sphere sphere1 = new Sphere (12, "blue"); //blue);
Sphere sphere2 = new Sphere (13, "green"); //green);
Sphere sphere3 = new Sphere (10, "purple"); //purple);
System.out.println("Sphere 1:");
System.out.println(sphere1);
System.out.println("Sphere 2:");
System.out.println(sphere2);
System.out.println("Sphere 3:");
System.out.println(sphere3);
}
}
Sphere.java
import java.text.*;
public class Sphere
{
DecimalFormat df = new DecimalFormat("##.##");
double radius;
String colors;
public Sphere (double num, String color)
{
radius = num;
colors = color;
}
public void setRadius (double rad)
{
radius = rad;
}
public double getRadius()
{
return radius;
}
public Sphere (String Str)
{
colors = Str;
}
public void setColors (String color)
{
colors = color;
}
public String getColors()
{
return colors;
}
//calculate volume
public double SphereVolume()
{
double v = 4 * Math.PI * radius*radius*radius;
double vol = v / 3; // * Math.PI * radius*radius*radius;
return vol;
}
//calculate area
public double SphereArea()
{
double sa = 4 * Math.PI * radius*radius;
return sa;
}
public String toString()
{
String desp="";
desp+="radius :"+radius + " ";
desp+="colors :"+colors + " ";
desp+="volume :"+ df.format(SphereVolume())+ " ";
desp+="area :"+ df.format(SphereArea())+ " ";
return desp;
}
}
Output:
Sphere 1:
radius :12.0
colors :blue
volume :7238.23
area :1809.56
Sphere 2:
radius :13.0
colors :green
volume :9202.77
area :2123.72
Sphere 3:
radius :10.0
colors :purple
volume :4188.79
area :1256.64

More Related Content

Similar to MultiSphere.java public class MultiSphere { public static vo.pdf

The Future of JVM Languages
The Future of JVM Languages The Future of JVM Languages
The Future of JVM Languages VictorSzoltysek
 
Laporan ai modul 2-if b 2014-14102055-deprilana ego prakasa
Laporan ai modul 2-if b 2014-14102055-deprilana ego prakasaLaporan ai modul 2-if b 2014-14102055-deprilana ego prakasa
Laporan ai modul 2-if b 2014-14102055-deprilana ego prakasaDeprilana Ego Prakasa
 
JRuby: Apples and Oranges
JRuby: Apples and OrangesJRuby: Apples and Oranges
JRuby: Apples and OrangesEngine Yard
 
Best of build 2021 - C# 10 & .NET 6
Best of build 2021 -  C# 10 & .NET 6Best of build 2021 -  C# 10 & .NET 6
Best of build 2021 - C# 10 & .NET 6Moaid Hathot
 
Groovy ネタ NGK 忘年会2009 ライトニングトーク
Groovy ネタ NGK 忘年会2009 ライトニングトークGroovy ネタ NGK 忘年会2009 ライトニングトーク
Groovy ネタ NGK 忘年会2009 ライトニングトークTsuyoshi Yamamoto
 
OracleCode One 2018: Java 5, 6, 7, 8, 9, 10, 11: What Did You Miss?
OracleCode One 2018: Java 5, 6, 7, 8, 9, 10, 11: What Did You Miss?OracleCode One 2018: Java 5, 6, 7, 8, 9, 10, 11: What Did You Miss?
OracleCode One 2018: Java 5, 6, 7, 8, 9, 10, 11: What Did You Miss?Henri Tremblay
 
多治見IT勉強会 Groovy Grails
多治見IT勉強会 Groovy Grails多治見IT勉強会 Groovy Grails
多治見IT勉強会 Groovy GrailsTsuyoshi Yamamoto
 
java question Fill the add statement areaProject is to wo.pdf
java question Fill the add statement areaProject is to wo.pdfjava question Fill the add statement areaProject is to wo.pdf
java question Fill the add statement areaProject is to wo.pdfdbrienmhompsonkath75
 
Type script by Howard
Type script by HowardType script by Howard
Type script by HowardLearningTech
 
ikh331-06-distributed-programming
ikh331-06-distributed-programmingikh331-06-distributed-programming
ikh331-06-distributed-programmingAnung Ariwibowo
 
CodeCamp Iasi 10 march 2012 - Practical Groovy
CodeCamp Iasi 10 march 2012 - Practical GroovyCodeCamp Iasi 10 march 2012 - Practical Groovy
CodeCamp Iasi 10 march 2012 - Practical GroovyCodecamp Romania
 
Modify HuffmanTree.java and HuffmanNode.java to allow the user to se.pdf
Modify HuffmanTree.java and HuffmanNode.java to allow the user to se.pdfModify HuffmanTree.java and HuffmanNode.java to allow the user to se.pdf
Modify HuffmanTree.java and HuffmanNode.java to allow the user to se.pdfarjuncorner565
 
TypeScript by Howard
TypeScript by HowardTypeScript by Howard
TypeScript by HowardLearningTech
 

Similar to MultiSphere.java public class MultiSphere { public static vo.pdf (20)

Inheritance.pptx
Inheritance.pptxInheritance.pptx
Inheritance.pptx
 
Class 5 2ciclo
Class 5 2cicloClass 5 2ciclo
Class 5 2ciclo
 
C# example (Polymorphesim)
C# example (Polymorphesim)C# example (Polymorphesim)
C# example (Polymorphesim)
 
The Future of JVM Languages
The Future of JVM Languages The Future of JVM Languages
The Future of JVM Languages
 
Laporan ai modul 2-if b 2014-14102055-deprilana ego prakasa
Laporan ai modul 2-if b 2014-14102055-deprilana ego prakasaLaporan ai modul 2-if b 2014-14102055-deprilana ego prakasa
Laporan ai modul 2-if b 2014-14102055-deprilana ego prakasa
 
JDK 8
JDK 8JDK 8
JDK 8
 
Java Class Design
Java Class DesignJava Class Design
Java Class Design
 
JRuby: Apples and Oranges
JRuby: Apples and OrangesJRuby: Apples and Oranges
JRuby: Apples and Oranges
 
Best of build 2021 - C# 10 & .NET 6
Best of build 2021 -  C# 10 & .NET 6Best of build 2021 -  C# 10 & .NET 6
Best of build 2021 - C# 10 & .NET 6
 
Groovy ネタ NGK 忘年会2009 ライトニングトーク
Groovy ネタ NGK 忘年会2009 ライトニングトークGroovy ネタ NGK 忘年会2009 ライトニングトーク
Groovy ネタ NGK 忘年会2009 ライトニングトーク
 
Learn Java 3D
Learn Java 3D Learn Java 3D
Learn Java 3D
 
OracleCode One 2018: Java 5, 6, 7, 8, 9, 10, 11: What Did You Miss?
OracleCode One 2018: Java 5, 6, 7, 8, 9, 10, 11: What Did You Miss?OracleCode One 2018: Java 5, 6, 7, 8, 9, 10, 11: What Did You Miss?
OracleCode One 2018: Java 5, 6, 7, 8, 9, 10, 11: What Did You Miss?
 
多治見IT勉強会 Groovy Grails
多治見IT勉強会 Groovy Grails多治見IT勉強会 Groovy Grails
多治見IT勉強会 Groovy Grails
 
java question Fill the add statement areaProject is to wo.pdf
java question Fill the add statement areaProject is to wo.pdfjava question Fill the add statement areaProject is to wo.pdf
java question Fill the add statement areaProject is to wo.pdf
 
Type script by Howard
Type script by HowardType script by Howard
Type script by Howard
 
ikh331-06-distributed-programming
ikh331-06-distributed-programmingikh331-06-distributed-programming
ikh331-06-distributed-programming
 
CodeCamp Iasi 10 march 2012 - Practical Groovy
CodeCamp Iasi 10 march 2012 - Practical GroovyCodeCamp Iasi 10 march 2012 - Practical Groovy
CodeCamp Iasi 10 march 2012 - Practical Groovy
 
Php 5.6
Php 5.6Php 5.6
Php 5.6
 
Modify HuffmanTree.java and HuffmanNode.java to allow the user to se.pdf
Modify HuffmanTree.java and HuffmanNode.java to allow the user to se.pdfModify HuffmanTree.java and HuffmanNode.java to allow the user to se.pdf
Modify HuffmanTree.java and HuffmanNode.java to allow the user to se.pdf
 
TypeScript by Howard
TypeScript by HowardTypeScript by Howard
TypeScript by Howard
 

Recently uploaded

Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactPECB
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13Steve Thomason
 
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...fonyou31
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxheathfieldcps1
 
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...Sapna Thakur
 
Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3JemimahLaneBuaron
 
social pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajansocial pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajanpragatimahajan3
 
JAPAN: ORGANISATION OF PMDA, PHARMACEUTICAL LAWS & REGULATIONS, TYPES OF REGI...
JAPAN: ORGANISATION OF PMDA, PHARMACEUTICAL LAWS & REGULATIONS, TYPES OF REGI...JAPAN: ORGANISATION OF PMDA, PHARMACEUTICAL LAWS & REGULATIONS, TYPES OF REGI...
JAPAN: ORGANISATION OF PMDA, PHARMACEUTICAL LAWS & REGULATIONS, TYPES OF REGI...anjaliyadav012327
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingTechSoup
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityGeoBlogs
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdfQucHHunhnh
 
Measures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDMeasures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDThiyagu K
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Sapana Sha
 
Student login on Anyboli platform.helpin
Student login on Anyboli platform.helpinStudent login on Anyboli platform.helpin
Student login on Anyboli platform.helpinRaunakKeshri1
 
Arihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfArihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfchloefrazer622
 
9548086042 for call girls in Indira Nagar with room service
9548086042  for call girls in Indira Nagar  with room service9548086042  for call girls in Indira Nagar  with room service
9548086042 for call girls in Indira Nagar with room servicediscovermytutordmt
 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxGaneshChakor2
 
Separation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesSeparation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesFatimaKhan178732
 

Recently uploaded (20)

Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global Impact
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13
 
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptx
 
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
 
Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3
 
social pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajansocial pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajan
 
JAPAN: ORGANISATION OF PMDA, PHARMACEUTICAL LAWS & REGULATIONS, TYPES OF REGI...
JAPAN: ORGANISATION OF PMDA, PHARMACEUTICAL LAWS & REGULATIONS, TYPES OF REGI...JAPAN: ORGANISATION OF PMDA, PHARMACEUTICAL LAWS & REGULATIONS, TYPES OF REGI...
JAPAN: ORGANISATION OF PMDA, PHARMACEUTICAL LAWS & REGULATIONS, TYPES OF REGI...
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy Consulting
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activity
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdf
 
Measures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDMeasures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SD
 
Advance Mobile Application Development class 07
Advance Mobile Application Development class 07Advance Mobile Application Development class 07
Advance Mobile Application Development class 07
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
 
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptxINDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
 
Student login on Anyboli platform.helpin
Student login on Anyboli platform.helpinStudent login on Anyboli platform.helpin
Student login on Anyboli platform.helpin
 
Arihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfArihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdf
 
9548086042 for call girls in Indira Nagar with room service
9548086042  for call girls in Indira Nagar  with room service9548086042  for call girls in Indira Nagar  with room service
9548086042 for call girls in Indira Nagar with room service
 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptx
 
Separation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesSeparation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and Actinides
 

MultiSphere.java public class MultiSphere { public static vo.pdf

  • 1. MultiSphere.java public class MultiSphere { public static void main (String[] args) { Sphere sphere1 = new Sphere (12, "blue"); //blue); Sphere sphere2 = new Sphere (13, "green"); //green); Sphere sphere3 = new Sphere (10, "purple"); //purple); System.out.println("Sphere 1:"); System.out.println(sphere1); System.out.println("Sphere 2:"); System.out.println(sphere2); System.out.println("Sphere 3:"); System.out.println(sphere3); } } Sphere.java import java.text.*; public class Sphere { DecimalFormat df = new DecimalFormat("##.##"); double radius; String colors; public Sphere (double num, String color) { radius = num; colors = color; } public void setRadius (double rad) {
  • 2. radius = rad; } public double getRadius() { return radius; } public Sphere (String Str) { colors = Str; } public void setColors (String color) { colors = color; } public String getColors() { return colors; } //calculate volume public double SphereVolume() { double v = 4 * Math.PI * radius*radius*radius; double vol = v / 3; // * Math.PI * radius*radius*radius; return vol; } //calculate area public double SphereArea() { double sa = 4 * Math.PI * radius*radius; return sa;
  • 3. } public String toString() { String desp=""; desp+="radius :"+radius + " "; desp+="colors :"+colors + " "; desp+="volume :"+ df.format(SphereVolume())+ " "; desp+="area :"+ df.format(SphereArea())+ " "; return desp; } } Output: Sphere 1: radius :12.0 colors :blue volume :7238.23 area :1809.56 Sphere 2: radius :13.0 colors :green volume :9202.77 area :2123.72 Sphere 3: radius :10.0 colors :purple volume :4188.79 area :1256.64 Solution MultiSphere.java public class MultiSphere { public static void main (String[] args)
  • 4. { Sphere sphere1 = new Sphere (12, "blue"); //blue); Sphere sphere2 = new Sphere (13, "green"); //green); Sphere sphere3 = new Sphere (10, "purple"); //purple); System.out.println("Sphere 1:"); System.out.println(sphere1); System.out.println("Sphere 2:"); System.out.println(sphere2); System.out.println("Sphere 3:"); System.out.println(sphere3); } } Sphere.java import java.text.*; public class Sphere { DecimalFormat df = new DecimalFormat("##.##"); double radius; String colors; public Sphere (double num, String color) { radius = num; colors = color; } public void setRadius (double rad) { radius = rad; } public double getRadius() { return radius;
  • 5. } public Sphere (String Str) { colors = Str; } public void setColors (String color) { colors = color; } public String getColors() { return colors; } //calculate volume public double SphereVolume() { double v = 4 * Math.PI * radius*radius*radius; double vol = v / 3; // * Math.PI * radius*radius*radius; return vol; } //calculate area public double SphereArea() { double sa = 4 * Math.PI * radius*radius; return sa; } public String toString() { String desp=""; desp+="radius :"+radius + " ";
  • 6. desp+="colors :"+colors + " "; desp+="volume :"+ df.format(SphereVolume())+ " "; desp+="area :"+ df.format(SphereArea())+ " "; return desp; } } Output: Sphere 1: radius :12.0 colors :blue volume :7238.23 area :1809.56 Sphere 2: radius :13.0 colors :green volume :9202.77 area :2123.72 Sphere 3: radius :10.0 colors :purple volume :4188.79 area :1256.64