SlideShare a Scribd company logo
import java.util.Scanner;
public class Bottle {
private static final int MAX=100; //max constant
private static final int MIN=0; // min constant
static Scanner scan = new Scanner(System.in);
private int noOfBottle=0;
//method 1 to read the value form console
public void read()
{
int x = scan.nextInt();
noOfBottle=x;
}
//method 2 to set the no of bottle property of bottle class
public void set(int a)
{
if(a<=MAX)
{
noOfBottle=a;
}else
{
System.out.println("number is greater than max value");
}
}
//method 3 to set the noOfBottle property from bottle object
public void setBottle(Bottle a)
{
if(a.noOfBottle<=MAX)
{
noOfBottle=a.noOfBottle;
}else
{
System.out.println("number is greater than max value");
}
}
//method 4 to get he noOfBottle value
public int get()
{
return this.noOfBottle;
}
//method 5 addition of bottle objects
public Bottle add(Bottle bottle)
{
if(this.noOfBottle+bottle.noOfBottle<=MAX)
{
this.noOfBottle=this.noOfBottle+bottle.noOfBottle;
}
else
{
System.out.println("Alert : addition excedding the maximum number ");
}
return this;
}
//method 6 subtraction of bottle objects
public Bottle subtract(Bottle bottle)
{
if(this.noOfBottle-bottle.noOfBottle>=MIN)
{
this.noOfBottle=this.noOfBottle-bottle.noOfBottle;
}
else
{
System.out.println("Alert : Subtraction reducing the bottle to below min range possible
");
}
return this;
}
//method 7 multiplication of bottle objects
public Bottle multiply(Bottle bottle)
{
if(this.noOfBottle*bottle.noOfBottle<=MAX)
{
this.noOfBottle=this.noOfBottle*bottle.noOfBottle;
}
else
{
System.out.println("Alert : Multiplication exceeding MAX value ");
}
return this;
}
//method 8 division of bopttle objects
public Bottle divide(Bottle bottle)
{
try{
if(this.noOfBottle/bottle.noOfBottle>=MIN)
{
this.noOfBottle=this.noOfBottle/bottle.noOfBottle;
}
else
{
System.out.println("Alert : Division reducing to possible MIN value ");
}
}catch(Exception e)
{
System.out.println("/ By zero error");
e.printStackTrace();
}
return this;
}
//method 9 addition of int value to bottle noOfObject property
public Bottle add(int a)
{
if(this.noOfBottle+a<=MAX)
{
this.noOfBottle=this.noOfBottle+a;
}
else
{
System.out.println("Alert : addition excedding the maximum number ");
}
return this;
}
//method 10 subtraction of bottle noOfObject property
public Bottle subtract(int a)
{
if(this.noOfBottle-a>=MIN)
{
this.noOfBottle=this.noOfBottle-a;
}
else
{
System.out.println("Alert : Subtraction reducing the bottle to below min range possible
");
}
return this;
}
//method 11 multiplication of bottle noOfObject property
public Bottle multiply(int a)
{
if(this.noOfBottle*a<=MAX)
{
this.noOfBottle=this.noOfBottle*a;
}
else
{
System.out.println("Alert : Multiplication exceeding MAX value ");
}
return this;
}
//method 12 d of bottle noOfObject property
public Bottle divide(int a)
{
try{
if(this.noOfBottle/a>=MIN)
{
this.noOfBottle=this.noOfBottle/a;
}
else
{
System.out.println("Alert : Division reducing below to possible MIN value  ");
}
}
catch(Exception e)
{
System.out.println("/by zero error");
e.printStackTrace();
}
return this;
}
//method 13
public boolean equals(Bottle bottle)
{
if(this.noOfBottle==bottle.noOfBottle)
{
return true;
}
else
{
return false;
}
}
//method 14
@Override
public String toString()
{
return "Bottle: "+noOfBottle;
}
public static void main(String[] args)
{
int x;
Bottle bottle1 = new Bottle();
Bottle bottle2 = new Bottle();
Bottle bottle3 = new Bottle();
Bottle bottle4 = new Bottle();
Bottle bottle5 = new Bottle();
System.out.println("please enter a number for bottle1:");
bottle1.read();
System.out.println("Bottle1 is this value " + bottle1 + ".");
System.out.println("Please enter a number for bottle2:");
bottle2.read();
bottle3.set(1);
bottle3 = bottle3.add(bottle1);
bottle3 = bottle3.add(bottle2);
bottle3 = bottle3.divide(2);
System.out.println("The 2 bottle average is: " + bottle3 + ".");
System.out.print("Subtracting bottle1 from bottle2 is: " );
bottle3 = bottle2.subtract(bottle1);
System.out.println( bottle3);
bottle3 = bottle2.divide(bottle1);
System.out.println("Dividing bottle2 with bottle1 is: " + bottle3 + ".");
if (bottle1.equals(bottle2))
{
System.out.println("Bottle1 and bottle2 are equal.");
}
else { System.out.println("Bottle1 and bottle2 are not equal.");
}
System.out.println("Bottle4 is now given the value of 10 with the set() method.");
bottle4.set(10);
System.out.println("The value of bottle4 is " + bottle4 + ".");
System.out.println("Bottle4 is now multiplied with bottle1. The value is placed in bottle5.");
bottle5 = bottle1.multiply(bottle4);
System.out.println("The value of bottle5 is " + bottle5 + ".");
System.out.println("Enter an integer to add to the value bottle1 has.");
System.out.println("The sum will be put in bottle3.");
x = scan.nextInt();
bottle3 = bottle1.add(x);
System.out.println("Adding your number " + x + " to bottle1 gives a new Bottle with " +
bottle3 + " in it.");
System.out.print("Adding the number " + bottle2 + " which is the number" + " in bottle2 to
the number in ");
bottle2 = bottle1.add(bottle2);
System.out.println("bottle1 which is " + bottle1 +" gives " + bottle2 + ".");
}
}
Solution
import java.util.Scanner;
public class Bottle {
private static final int MAX=100; //max constant
private static final int MIN=0; // min constant
static Scanner scan = new Scanner(System.in);
private int noOfBottle=0;
//method 1 to read the value form console
public void read()
{
int x = scan.nextInt();
noOfBottle=x;
}
//method 2 to set the no of bottle property of bottle class
public void set(int a)
{
if(a<=MAX)
{
noOfBottle=a;
}else
{
System.out.println("number is greater than max value");
}
}
//method 3 to set the noOfBottle property from bottle object
public void setBottle(Bottle a)
{
if(a.noOfBottle<=MAX)
{
noOfBottle=a.noOfBottle;
}else
{
System.out.println("number is greater than max value");
}
}
//method 4 to get he noOfBottle value
public int get()
{
return this.noOfBottle;
}
//method 5 addition of bottle objects
public Bottle add(Bottle bottle)
{
if(this.noOfBottle+bottle.noOfBottle<=MAX)
{
this.noOfBottle=this.noOfBottle+bottle.noOfBottle;
}
else
{
System.out.println("Alert : addition excedding the maximum number ");
}
return this;
}
//method 6 subtraction of bottle objects
public Bottle subtract(Bottle bottle)
{
if(this.noOfBottle-bottle.noOfBottle>=MIN)
{
this.noOfBottle=this.noOfBottle-bottle.noOfBottle;
}
else
{
System.out.println("Alert : Subtraction reducing the bottle to below min range possible
");
}
return this;
}
//method 7 multiplication of bottle objects
public Bottle multiply(Bottle bottle)
{
if(this.noOfBottle*bottle.noOfBottle<=MAX)
{
this.noOfBottle=this.noOfBottle*bottle.noOfBottle;
}
else
{
System.out.println("Alert : Multiplication exceeding MAX value ");
}
return this;
}
//method 8 division of bopttle objects
public Bottle divide(Bottle bottle)
{
try{
if(this.noOfBottle/bottle.noOfBottle>=MIN)
{
this.noOfBottle=this.noOfBottle/bottle.noOfBottle;
}
else
{
System.out.println("Alert : Division reducing to possible MIN value ");
}
}catch(Exception e)
{
System.out.println("/ By zero error");
e.printStackTrace();
}
return this;
}
//method 9 addition of int value to bottle noOfObject property
public Bottle add(int a)
{
if(this.noOfBottle+a<=MAX)
{
this.noOfBottle=this.noOfBottle+a;
}
else
{
System.out.println("Alert : addition excedding the maximum number ");
}
return this;
}
//method 10 subtraction of bottle noOfObject property
public Bottle subtract(int a)
{
if(this.noOfBottle-a>=MIN)
{
this.noOfBottle=this.noOfBottle-a;
}
else
{
System.out.println("Alert : Subtraction reducing the bottle to below min range possible
");
}
return this;
}
//method 11 multiplication of bottle noOfObject property
public Bottle multiply(int a)
{
if(this.noOfBottle*a<=MAX)
{
this.noOfBottle=this.noOfBottle*a;
}
else
{
System.out.println("Alert : Multiplication exceeding MAX value ");
}
return this;
}
//method 12 d of bottle noOfObject property
public Bottle divide(int a)
{
try{
if(this.noOfBottle/a>=MIN)
{
this.noOfBottle=this.noOfBottle/a;
}
else
{
System.out.println("Alert : Division reducing below to possible MIN value  ");
}
}
catch(Exception e)
{
System.out.println("/by zero error");
e.printStackTrace();
}
return this;
}
//method 13
public boolean equals(Bottle bottle)
{
if(this.noOfBottle==bottle.noOfBottle)
{
return true;
}
else
{
return false;
}
}
//method 14
@Override
public String toString()
{
return "Bottle: "+noOfBottle;
}
public static void main(String[] args)
{
int x;
Bottle bottle1 = new Bottle();
Bottle bottle2 = new Bottle();
Bottle bottle3 = new Bottle();
Bottle bottle4 = new Bottle();
Bottle bottle5 = new Bottle();
System.out.println("please enter a number for bottle1:");
bottle1.read();
System.out.println("Bottle1 is this value " + bottle1 + ".");
System.out.println("Please enter a number for bottle2:");
bottle2.read();
bottle3.set(1);
bottle3 = bottle3.add(bottle1);
bottle3 = bottle3.add(bottle2);
bottle3 = bottle3.divide(2);
System.out.println("The 2 bottle average is: " + bottle3 + ".");
System.out.print("Subtracting bottle1 from bottle2 is: " );
bottle3 = bottle2.subtract(bottle1);
System.out.println( bottle3);
bottle3 = bottle2.divide(bottle1);
System.out.println("Dividing bottle2 with bottle1 is: " + bottle3 + ".");
if (bottle1.equals(bottle2))
{
System.out.println("Bottle1 and bottle2 are equal.");
}
else { System.out.println("Bottle1 and bottle2 are not equal.");
}
System.out.println("Bottle4 is now given the value of 10 with the set() method.");
bottle4.set(10);
System.out.println("The value of bottle4 is " + bottle4 + ".");
System.out.println("Bottle4 is now multiplied with bottle1. The value is placed in bottle5.");
bottle5 = bottle1.multiply(bottle4);
System.out.println("The value of bottle5 is " + bottle5 + ".");
System.out.println("Enter an integer to add to the value bottle1 has.");
System.out.println("The sum will be put in bottle3.");
x = scan.nextInt();
bottle3 = bottle1.add(x);
System.out.println("Adding your number " + x + " to bottle1 gives a new Bottle with " +
bottle3 + " in it.");
System.out.print("Adding the number " + bottle2 + " which is the number" + " in bottle2 to
the number in ");
bottle2 = bottle1.add(bottle2);
System.out.println("bottle1 which is " + bottle1 +" gives " + bottle2 + ".");
}
}

More Related Content

Similar to import java.util.Scanner;public class Bottle {    private stat.pdf

Write a class that implements the BagInterface. BagInterface should .pdf
Write a class that implements the BagInterface.  BagInterface should .pdfWrite a class that implements the BagInterface.  BagInterface should .pdf
Write a class that implements the BagInterface. BagInterface should .pdf
fashiongallery1
 
Hello need help on this lab- what you need to do is add a code to Arra.pdf
Hello need help on this lab- what you need to do is add a code to Arra.pdfHello need help on this lab- what you need to do is add a code to Arra.pdf
Hello need help on this lab- what you need to do is add a code to Arra.pdf
Ian0J2Bondo
 
Kotlin Generation
Kotlin GenerationKotlin Generation
Kotlin Generation
Minseo Chayabanjonglerd
 
New folderjsjfArrayStack.classpackage jsjf;publicsynchronize.docx
New folderjsjfArrayStack.classpackage jsjf;publicsynchronize.docxNew folderjsjfArrayStack.classpackage jsjf;publicsynchronize.docx
New folderjsjfArrayStack.classpackage jsjf;publicsynchronize.docx
curwenmichaela
 
Presentation on template and exception
Presentation  on template and exceptionPresentation  on template and exception
Presentation on template and exception
Sajid Alee Mosavi
 

Similar to import java.util.Scanner;public class Bottle {    private stat.pdf (7)

Write a class that implements the BagInterface. BagInterface should .pdf
Write a class that implements the BagInterface.  BagInterface should .pdfWrite a class that implements the BagInterface.  BagInterface should .pdf
Write a class that implements the BagInterface. BagInterface should .pdf
 
Hello need help on this lab- what you need to do is add a code to Arra.pdf
Hello need help on this lab- what you need to do is add a code to Arra.pdfHello need help on this lab- what you need to do is add a code to Arra.pdf
Hello need help on this lab- what you need to do is add a code to Arra.pdf
 
Kotlin Generation
Kotlin GenerationKotlin Generation
Kotlin Generation
 
New folderjsjfArrayStack.classpackage jsjf;publicsynchronize.docx
New folderjsjfArrayStack.classpackage jsjf;publicsynchronize.docxNew folderjsjfArrayStack.classpackage jsjf;publicsynchronize.docx
New folderjsjfArrayStack.classpackage jsjf;publicsynchronize.docx
 
Presentation on template and exception
Presentation  on template and exceptionPresentation  on template and exception
Presentation on template and exception
 
Pre zen ta sion
Pre zen ta sionPre zen ta sion
Pre zen ta sion
 
New text document
New text documentNew text document
New text document
 

More from annesmkt

#include iostream #include fstream #include cstdlib #.pdf
 #include iostream #include fstream #include cstdlib #.pdf #include iostream #include fstream #include cstdlib #.pdf
#include iostream #include fstream #include cstdlib #.pdf
annesmkt
 
six lone pairs (each F has three lone pairs) nit.pdf
                     six lone pairs (each F has three lone pairs)  nit.pdf                     six lone pairs (each F has three lone pairs)  nit.pdf
six lone pairs (each F has three lone pairs) nit.pdf
annesmkt
 
silver cyanide i think coz HCN will be formed whi.pdf
                     silver cyanide i think coz HCN will be formed whi.pdf                     silver cyanide i think coz HCN will be formed whi.pdf
silver cyanide i think coz HCN will be formed whi.pdf
annesmkt
 
Rh (Rhodium) is the answer. Solution .pdf
                     Rh (Rhodium) is the answer.  Solution        .pdf                     Rh (Rhodium) is the answer.  Solution        .pdf
Rh (Rhodium) is the answer. Solution .pdf
annesmkt
 
please rate me.... .pdf
                     please rate me....                               .pdf                     please rate me....                               .pdf
please rate me.... .pdf
annesmkt
 
No. The Mo is in +3 oxidation state and thus its .pdf
                     No. The Mo is in +3 oxidation state and thus its .pdf                     No. The Mo is in +3 oxidation state and thus its .pdf
No. The Mo is in +3 oxidation state and thus its .pdf
annesmkt
 
In the automata theory, a nondeterministic finite.pdf
                     In the automata theory, a nondeterministic finite.pdf                     In the automata theory, a nondeterministic finite.pdf
In the automata theory, a nondeterministic finite.pdf
annesmkt
 
Formaldehyde is an organic compound with the form.pdf
                     Formaldehyde is an organic compound with the form.pdf                     Formaldehyde is an organic compound with the form.pdf
Formaldehyde is an organic compound with the form.pdf
annesmkt
 
d. the molecular orbital diagram for O2. .pdf
                     d. the molecular orbital diagram for O2.         .pdf                     d. the molecular orbital diagram for O2.         .pdf
d. the molecular orbital diagram for O2. .pdf
annesmkt
 
Water molecules do not participate in acid base neutralization react.pdf
Water molecules do not participate in acid base neutralization react.pdfWater molecules do not participate in acid base neutralization react.pdf
Water molecules do not participate in acid base neutralization react.pdf
annesmkt
 
The Mouse and the track ball uses pointing and dragging tasks.The ac.pdf
The Mouse and the track ball uses pointing and dragging tasks.The ac.pdfThe Mouse and the track ball uses pointing and dragging tasks.The ac.pdf
The Mouse and the track ball uses pointing and dragging tasks.The ac.pdf
annesmkt
 
The employer must estimate the total cost of the benefits promised a.pdf
The employer must estimate the total cost of the benefits promised a.pdfThe employer must estimate the total cost of the benefits promised a.pdf
The employer must estimate the total cost of the benefits promised a.pdf
annesmkt
 
slopeSolutionslope.pdf
slopeSolutionslope.pdfslopeSolutionslope.pdf
slopeSolutionslope.pdf
annesmkt
 
Plz send the clear image to me...so that i can solve it..Solutio.pdf
Plz send the clear image to me...so that i can solve it..Solutio.pdfPlz send the clear image to me...so that i can solve it..Solutio.pdf
Plz send the clear image to me...so that i can solve it..Solutio.pdf
annesmkt
 
public class Passenger {    public static enum Section {        .pdf
public class Passenger {    public static enum Section {        .pdfpublic class Passenger {    public static enum Section {        .pdf
public class Passenger {    public static enum Section {        .pdf
annesmkt
 
Prior to 2010, the United States banned HIV-positive individuals fro.pdf
Prior to 2010, the United States banned HIV-positive individuals fro.pdfPrior to 2010, the United States banned HIV-positive individuals fro.pdf
Prior to 2010, the United States banned HIV-positive individuals fro.pdf
annesmkt
 
option (e) is correct.the feature that distinguishes fluorescence .pdf
option (e) is correct.the feature that distinguishes fluorescence .pdfoption (e) is correct.the feature that distinguishes fluorescence .pdf
option (e) is correct.the feature that distinguishes fluorescence .pdf
annesmkt
 
NADP is the source of electrons for the light reactionsThe electro.pdf
NADP is the source of electrons for the light reactionsThe electro.pdfNADP is the source of electrons for the light reactionsThe electro.pdf
NADP is the source of electrons for the light reactionsThe electro.pdf
annesmkt
 
In previous year, 2 birthdays were on tuesday but this year theres.pdf
In previous year, 2 birthdays were on tuesday but this year theres.pdfIn previous year, 2 birthdays were on tuesday but this year theres.pdf
In previous year, 2 birthdays were on tuesday but this year theres.pdf
annesmkt
 
Homology is defined as structures which are derived from a common an.pdf
Homology is defined as structures which are derived from a common an.pdfHomology is defined as structures which are derived from a common an.pdf
Homology is defined as structures which are derived from a common an.pdf
annesmkt
 

More from annesmkt (20)

#include iostream #include fstream #include cstdlib #.pdf
 #include iostream #include fstream #include cstdlib #.pdf #include iostream #include fstream #include cstdlib #.pdf
#include iostream #include fstream #include cstdlib #.pdf
 
six lone pairs (each F has three lone pairs) nit.pdf
                     six lone pairs (each F has three lone pairs)  nit.pdf                     six lone pairs (each F has three lone pairs)  nit.pdf
six lone pairs (each F has three lone pairs) nit.pdf
 
silver cyanide i think coz HCN will be formed whi.pdf
                     silver cyanide i think coz HCN will be formed whi.pdf                     silver cyanide i think coz HCN will be formed whi.pdf
silver cyanide i think coz HCN will be formed whi.pdf
 
Rh (Rhodium) is the answer. Solution .pdf
                     Rh (Rhodium) is the answer.  Solution        .pdf                     Rh (Rhodium) is the answer.  Solution        .pdf
Rh (Rhodium) is the answer. Solution .pdf
 
please rate me.... .pdf
                     please rate me....                               .pdf                     please rate me....                               .pdf
please rate me.... .pdf
 
No. The Mo is in +3 oxidation state and thus its .pdf
                     No. The Mo is in +3 oxidation state and thus its .pdf                     No. The Mo is in +3 oxidation state and thus its .pdf
No. The Mo is in +3 oxidation state and thus its .pdf
 
In the automata theory, a nondeterministic finite.pdf
                     In the automata theory, a nondeterministic finite.pdf                     In the automata theory, a nondeterministic finite.pdf
In the automata theory, a nondeterministic finite.pdf
 
Formaldehyde is an organic compound with the form.pdf
                     Formaldehyde is an organic compound with the form.pdf                     Formaldehyde is an organic compound with the form.pdf
Formaldehyde is an organic compound with the form.pdf
 
d. the molecular orbital diagram for O2. .pdf
                     d. the molecular orbital diagram for O2.         .pdf                     d. the molecular orbital diagram for O2.         .pdf
d. the molecular orbital diagram for O2. .pdf
 
Water molecules do not participate in acid base neutralization react.pdf
Water molecules do not participate in acid base neutralization react.pdfWater molecules do not participate in acid base neutralization react.pdf
Water molecules do not participate in acid base neutralization react.pdf
 
The Mouse and the track ball uses pointing and dragging tasks.The ac.pdf
The Mouse and the track ball uses pointing and dragging tasks.The ac.pdfThe Mouse and the track ball uses pointing and dragging tasks.The ac.pdf
The Mouse and the track ball uses pointing and dragging tasks.The ac.pdf
 
The employer must estimate the total cost of the benefits promised a.pdf
The employer must estimate the total cost of the benefits promised a.pdfThe employer must estimate the total cost of the benefits promised a.pdf
The employer must estimate the total cost of the benefits promised a.pdf
 
slopeSolutionslope.pdf
slopeSolutionslope.pdfslopeSolutionslope.pdf
slopeSolutionslope.pdf
 
Plz send the clear image to me...so that i can solve it..Solutio.pdf
Plz send the clear image to me...so that i can solve it..Solutio.pdfPlz send the clear image to me...so that i can solve it..Solutio.pdf
Plz send the clear image to me...so that i can solve it..Solutio.pdf
 
public class Passenger {    public static enum Section {        .pdf
public class Passenger {    public static enum Section {        .pdfpublic class Passenger {    public static enum Section {        .pdf
public class Passenger {    public static enum Section {        .pdf
 
Prior to 2010, the United States banned HIV-positive individuals fro.pdf
Prior to 2010, the United States banned HIV-positive individuals fro.pdfPrior to 2010, the United States banned HIV-positive individuals fro.pdf
Prior to 2010, the United States banned HIV-positive individuals fro.pdf
 
option (e) is correct.the feature that distinguishes fluorescence .pdf
option (e) is correct.the feature that distinguishes fluorescence .pdfoption (e) is correct.the feature that distinguishes fluorescence .pdf
option (e) is correct.the feature that distinguishes fluorescence .pdf
 
NADP is the source of electrons for the light reactionsThe electro.pdf
NADP is the source of electrons for the light reactionsThe electro.pdfNADP is the source of electrons for the light reactionsThe electro.pdf
NADP is the source of electrons for the light reactionsThe electro.pdf
 
In previous year, 2 birthdays were on tuesday but this year theres.pdf
In previous year, 2 birthdays were on tuesday but this year theres.pdfIn previous year, 2 birthdays were on tuesday but this year theres.pdf
In previous year, 2 birthdays were on tuesday but this year theres.pdf
 
Homology is defined as structures which are derived from a common an.pdf
Homology is defined as structures which are derived from a common an.pdfHomology is defined as structures which are derived from a common an.pdf
Homology is defined as structures which are derived from a common an.pdf
 

Recently uploaded

A Strategic Approach: GenAI in Education
A Strategic Approach: GenAI in EducationA Strategic Approach: GenAI in Education
A Strategic Approach: GenAI in Education
Peter Windle
 
The approach at University of Liverpool.pptx
The approach at University of Liverpool.pptxThe approach at University of Liverpool.pptx
The approach at University of Liverpool.pptx
Jisc
 
The French Revolution Class 9 Study Material pdf free download
The French Revolution Class 9 Study Material pdf free downloadThe French Revolution Class 9 Study Material pdf free download
The French Revolution Class 9 Study Material pdf free download
Vivekanand Anglo Vedic Academy
 
Francesca Gottschalk - How can education support child empowerment.pptx
Francesca Gottschalk - How can education support child empowerment.pptxFrancesca Gottschalk - How can education support child empowerment.pptx
Francesca Gottschalk - How can education support child empowerment.pptx
EduSkills OECD
 
MASS MEDIA STUDIES-835-CLASS XI Resource Material.pdf
MASS MEDIA STUDIES-835-CLASS XI Resource Material.pdfMASS MEDIA STUDIES-835-CLASS XI Resource Material.pdf
MASS MEDIA STUDIES-835-CLASS XI Resource Material.pdf
goswamiyash170123
 
Best Digital Marketing Institute In NOIDA
Best Digital Marketing Institute In NOIDABest Digital Marketing Institute In NOIDA
Best Digital Marketing Institute In NOIDA
deeptiverma2406
 
Multithreading_in_C++ - std::thread, race condition
Multithreading_in_C++ - std::thread, race conditionMultithreading_in_C++ - std::thread, race condition
Multithreading_in_C++ - std::thread, race condition
Mohammed Sikander
 
Digital Artifact 2 - Investigating Pavilion Designs
Digital Artifact 2 - Investigating Pavilion DesignsDigital Artifact 2 - Investigating Pavilion Designs
Digital Artifact 2 - Investigating Pavilion Designs
chanes7
 
2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...
Sandy Millin
 
Thesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.pptThesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.ppt
EverAndrsGuerraGuerr
 
Supporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptxSupporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptx
Jisc
 
Marketing internship report file for MBA
Marketing internship report file for MBAMarketing internship report file for MBA
Marketing internship report file for MBA
gb193092
 
How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...
Jisc
 
Chapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptxChapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptx
Mohd Adib Abd Muin, Senior Lecturer at Universiti Utara Malaysia
 
Acetabularia Information For Class 9 .docx
Acetabularia Information For Class 9  .docxAcetabularia Information For Class 9  .docx
Acetabularia Information For Class 9 .docx
vaibhavrinwa19
 
Model Attribute Check Company Auto Property
Model Attribute  Check Company Auto PropertyModel Attribute  Check Company Auto Property
Model Attribute Check Company Auto Property
Celine George
 
Advantages and Disadvantages of CMS from an SEO Perspective
Advantages and Disadvantages of CMS from an SEO PerspectiveAdvantages and Disadvantages of CMS from an SEO Perspective
Advantages and Disadvantages of CMS from an SEO Perspective
Krisztián Száraz
 
Normal Labour/ Stages of Labour/ Mechanism of Labour
Normal Labour/ Stages of Labour/ Mechanism of LabourNormal Labour/ Stages of Labour/ Mechanism of Labour
Normal Labour/ Stages of Labour/ Mechanism of Labour
Wasim Ak
 
Unit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdfUnit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdf
Thiyagu K
 
Digital Tools and AI for Teaching Learning and Research
Digital Tools and AI for Teaching Learning and ResearchDigital Tools and AI for Teaching Learning and Research
Digital Tools and AI for Teaching Learning and Research
Vikramjit Singh
 

Recently uploaded (20)

A Strategic Approach: GenAI in Education
A Strategic Approach: GenAI in EducationA Strategic Approach: GenAI in Education
A Strategic Approach: GenAI in Education
 
The approach at University of Liverpool.pptx
The approach at University of Liverpool.pptxThe approach at University of Liverpool.pptx
The approach at University of Liverpool.pptx
 
The French Revolution Class 9 Study Material pdf free download
The French Revolution Class 9 Study Material pdf free downloadThe French Revolution Class 9 Study Material pdf free download
The French Revolution Class 9 Study Material pdf free download
 
Francesca Gottschalk - How can education support child empowerment.pptx
Francesca Gottschalk - How can education support child empowerment.pptxFrancesca Gottschalk - How can education support child empowerment.pptx
Francesca Gottschalk - How can education support child empowerment.pptx
 
MASS MEDIA STUDIES-835-CLASS XI Resource Material.pdf
MASS MEDIA STUDIES-835-CLASS XI Resource Material.pdfMASS MEDIA STUDIES-835-CLASS XI Resource Material.pdf
MASS MEDIA STUDIES-835-CLASS XI Resource Material.pdf
 
Best Digital Marketing Institute In NOIDA
Best Digital Marketing Institute In NOIDABest Digital Marketing Institute In NOIDA
Best Digital Marketing Institute In NOIDA
 
Multithreading_in_C++ - std::thread, race condition
Multithreading_in_C++ - std::thread, race conditionMultithreading_in_C++ - std::thread, race condition
Multithreading_in_C++ - std::thread, race condition
 
Digital Artifact 2 - Investigating Pavilion Designs
Digital Artifact 2 - Investigating Pavilion DesignsDigital Artifact 2 - Investigating Pavilion Designs
Digital Artifact 2 - Investigating Pavilion Designs
 
2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...
 
Thesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.pptThesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.ppt
 
Supporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptxSupporting (UKRI) OA monographs at Salford.pptx
Supporting (UKRI) OA monographs at Salford.pptx
 
Marketing internship report file for MBA
Marketing internship report file for MBAMarketing internship report file for MBA
Marketing internship report file for MBA
 
How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...
 
Chapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptxChapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptx
 
Acetabularia Information For Class 9 .docx
Acetabularia Information For Class 9  .docxAcetabularia Information For Class 9  .docx
Acetabularia Information For Class 9 .docx
 
Model Attribute Check Company Auto Property
Model Attribute  Check Company Auto PropertyModel Attribute  Check Company Auto Property
Model Attribute Check Company Auto Property
 
Advantages and Disadvantages of CMS from an SEO Perspective
Advantages and Disadvantages of CMS from an SEO PerspectiveAdvantages and Disadvantages of CMS from an SEO Perspective
Advantages and Disadvantages of CMS from an SEO Perspective
 
Normal Labour/ Stages of Labour/ Mechanism of Labour
Normal Labour/ Stages of Labour/ Mechanism of LabourNormal Labour/ Stages of Labour/ Mechanism of Labour
Normal Labour/ Stages of Labour/ Mechanism of Labour
 
Unit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdfUnit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdf
 
Digital Tools and AI for Teaching Learning and Research
Digital Tools and AI for Teaching Learning and ResearchDigital Tools and AI for Teaching Learning and Research
Digital Tools and AI for Teaching Learning and Research
 

import java.util.Scanner;public class Bottle {    private stat.pdf

  • 1. import java.util.Scanner; public class Bottle { private static final int MAX=100; //max constant private static final int MIN=0; // min constant static Scanner scan = new Scanner(System.in); private int noOfBottle=0; //method 1 to read the value form console public void read() { int x = scan.nextInt(); noOfBottle=x; } //method 2 to set the no of bottle property of bottle class public void set(int a) { if(a<=MAX) { noOfBottle=a; }else { System.out.println("number is greater than max value"); } } //method 3 to set the noOfBottle property from bottle object public void setBottle(Bottle a) { if(a.noOfBottle<=MAX) { noOfBottle=a.noOfBottle; }else { System.out.println("number is greater than max value");
  • 2. } } //method 4 to get he noOfBottle value public int get() { return this.noOfBottle; } //method 5 addition of bottle objects public Bottle add(Bottle bottle) { if(this.noOfBottle+bottle.noOfBottle<=MAX) { this.noOfBottle=this.noOfBottle+bottle.noOfBottle; } else { System.out.println("Alert : addition excedding the maximum number "); } return this; } //method 6 subtraction of bottle objects public Bottle subtract(Bottle bottle) { if(this.noOfBottle-bottle.noOfBottle>=MIN) { this.noOfBottle=this.noOfBottle-bottle.noOfBottle; } else { System.out.println("Alert : Subtraction reducing the bottle to below min range possible "); } return this;
  • 3. } //method 7 multiplication of bottle objects public Bottle multiply(Bottle bottle) { if(this.noOfBottle*bottle.noOfBottle<=MAX) { this.noOfBottle=this.noOfBottle*bottle.noOfBottle; } else { System.out.println("Alert : Multiplication exceeding MAX value "); } return this; } //method 8 division of bopttle objects public Bottle divide(Bottle bottle) { try{ if(this.noOfBottle/bottle.noOfBottle>=MIN) { this.noOfBottle=this.noOfBottle/bottle.noOfBottle; } else { System.out.println("Alert : Division reducing to possible MIN value "); } }catch(Exception e) { System.out.println("/ By zero error"); e.printStackTrace(); } return this; } //method 9 addition of int value to bottle noOfObject property public Bottle add(int a) {
  • 4. if(this.noOfBottle+a<=MAX) { this.noOfBottle=this.noOfBottle+a; } else { System.out.println("Alert : addition excedding the maximum number "); } return this; } //method 10 subtraction of bottle noOfObject property public Bottle subtract(int a) { if(this.noOfBottle-a>=MIN) { this.noOfBottle=this.noOfBottle-a; } else { System.out.println("Alert : Subtraction reducing the bottle to below min range possible "); } return this; } //method 11 multiplication of bottle noOfObject property public Bottle multiply(int a) { if(this.noOfBottle*a<=MAX) { this.noOfBottle=this.noOfBottle*a; } else { System.out.println("Alert : Multiplication exceeding MAX value "); } return this;
  • 5. } //method 12 d of bottle noOfObject property public Bottle divide(int a) { try{ if(this.noOfBottle/a>=MIN) { this.noOfBottle=this.noOfBottle/a; } else { System.out.println("Alert : Division reducing below to possible MIN value "); } } catch(Exception e) { System.out.println("/by zero error"); e.printStackTrace(); } return this; } //method 13 public boolean equals(Bottle bottle) { if(this.noOfBottle==bottle.noOfBottle) { return true; } else { return false; } } //method 14 @Override public String toString()
  • 6. { return "Bottle: "+noOfBottle; } public static void main(String[] args) { int x; Bottle bottle1 = new Bottle(); Bottle bottle2 = new Bottle(); Bottle bottle3 = new Bottle(); Bottle bottle4 = new Bottle(); Bottle bottle5 = new Bottle(); System.out.println("please enter a number for bottle1:"); bottle1.read(); System.out.println("Bottle1 is this value " + bottle1 + "."); System.out.println("Please enter a number for bottle2:"); bottle2.read(); bottle3.set(1); bottle3 = bottle3.add(bottle1); bottle3 = bottle3.add(bottle2); bottle3 = bottle3.divide(2); System.out.println("The 2 bottle average is: " + bottle3 + "."); System.out.print("Subtracting bottle1 from bottle2 is: " ); bottle3 = bottle2.subtract(bottle1); System.out.println( bottle3); bottle3 = bottle2.divide(bottle1); System.out.println("Dividing bottle2 with bottle1 is: " + bottle3 + "."); if (bottle1.equals(bottle2)) { System.out.println("Bottle1 and bottle2 are equal."); }
  • 7. else { System.out.println("Bottle1 and bottle2 are not equal."); } System.out.println("Bottle4 is now given the value of 10 with the set() method."); bottle4.set(10); System.out.println("The value of bottle4 is " + bottle4 + "."); System.out.println("Bottle4 is now multiplied with bottle1. The value is placed in bottle5."); bottle5 = bottle1.multiply(bottle4); System.out.println("The value of bottle5 is " + bottle5 + "."); System.out.println("Enter an integer to add to the value bottle1 has."); System.out.println("The sum will be put in bottle3."); x = scan.nextInt(); bottle3 = bottle1.add(x); System.out.println("Adding your number " + x + " to bottle1 gives a new Bottle with " + bottle3 + " in it."); System.out.print("Adding the number " + bottle2 + " which is the number" + " in bottle2 to the number in "); bottle2 = bottle1.add(bottle2); System.out.println("bottle1 which is " + bottle1 +" gives " + bottle2 + "."); } } Solution import java.util.Scanner; public class Bottle { private static final int MAX=100; //max constant private static final int MIN=0; // min constant static Scanner scan = new Scanner(System.in); private int noOfBottle=0; //method 1 to read the value form console public void read() { int x = scan.nextInt();
  • 8. noOfBottle=x; } //method 2 to set the no of bottle property of bottle class public void set(int a) { if(a<=MAX) { noOfBottle=a; }else { System.out.println("number is greater than max value"); } } //method 3 to set the noOfBottle property from bottle object public void setBottle(Bottle a) { if(a.noOfBottle<=MAX) { noOfBottle=a.noOfBottle; }else { System.out.println("number is greater than max value"); } } //method 4 to get he noOfBottle value public int get() { return this.noOfBottle; } //method 5 addition of bottle objects public Bottle add(Bottle bottle) {
  • 9. if(this.noOfBottle+bottle.noOfBottle<=MAX) { this.noOfBottle=this.noOfBottle+bottle.noOfBottle; } else { System.out.println("Alert : addition excedding the maximum number "); } return this; } //method 6 subtraction of bottle objects public Bottle subtract(Bottle bottle) { if(this.noOfBottle-bottle.noOfBottle>=MIN) { this.noOfBottle=this.noOfBottle-bottle.noOfBottle; } else { System.out.println("Alert : Subtraction reducing the bottle to below min range possible "); } return this; } //method 7 multiplication of bottle objects public Bottle multiply(Bottle bottle) { if(this.noOfBottle*bottle.noOfBottle<=MAX) { this.noOfBottle=this.noOfBottle*bottle.noOfBottle; } else { System.out.println("Alert : Multiplication exceeding MAX value "); } return this;
  • 10. } //method 8 division of bopttle objects public Bottle divide(Bottle bottle) { try{ if(this.noOfBottle/bottle.noOfBottle>=MIN) { this.noOfBottle=this.noOfBottle/bottle.noOfBottle; } else { System.out.println("Alert : Division reducing to possible MIN value "); } }catch(Exception e) { System.out.println("/ By zero error"); e.printStackTrace(); } return this; } //method 9 addition of int value to bottle noOfObject property public Bottle add(int a) { if(this.noOfBottle+a<=MAX) { this.noOfBottle=this.noOfBottle+a; } else { System.out.println("Alert : addition excedding the maximum number "); } return this; } //method 10 subtraction of bottle noOfObject property public Bottle subtract(int a) {
  • 11. if(this.noOfBottle-a>=MIN) { this.noOfBottle=this.noOfBottle-a; } else { System.out.println("Alert : Subtraction reducing the bottle to below min range possible "); } return this; } //method 11 multiplication of bottle noOfObject property public Bottle multiply(int a) { if(this.noOfBottle*a<=MAX) { this.noOfBottle=this.noOfBottle*a; } else { System.out.println("Alert : Multiplication exceeding MAX value "); } return this; } //method 12 d of bottle noOfObject property public Bottle divide(int a) { try{ if(this.noOfBottle/a>=MIN) { this.noOfBottle=this.noOfBottle/a; } else { System.out.println("Alert : Division reducing below to possible MIN value "); }
  • 12. } catch(Exception e) { System.out.println("/by zero error"); e.printStackTrace(); } return this; } //method 13 public boolean equals(Bottle bottle) { if(this.noOfBottle==bottle.noOfBottle) { return true; } else { return false; } } //method 14 @Override public String toString() { return "Bottle: "+noOfBottle; } public static void main(String[] args) { int x; Bottle bottle1 = new Bottle(); Bottle bottle2 = new Bottle(); Bottle bottle3 = new Bottle();
  • 13. Bottle bottle4 = new Bottle(); Bottle bottle5 = new Bottle(); System.out.println("please enter a number for bottle1:"); bottle1.read(); System.out.println("Bottle1 is this value " + bottle1 + "."); System.out.println("Please enter a number for bottle2:"); bottle2.read(); bottle3.set(1); bottle3 = bottle3.add(bottle1); bottle3 = bottle3.add(bottle2); bottle3 = bottle3.divide(2); System.out.println("The 2 bottle average is: " + bottle3 + "."); System.out.print("Subtracting bottle1 from bottle2 is: " ); bottle3 = bottle2.subtract(bottle1); System.out.println( bottle3); bottle3 = bottle2.divide(bottle1); System.out.println("Dividing bottle2 with bottle1 is: " + bottle3 + "."); if (bottle1.equals(bottle2)) { System.out.println("Bottle1 and bottle2 are equal."); } else { System.out.println("Bottle1 and bottle2 are not equal."); } System.out.println("Bottle4 is now given the value of 10 with the set() method."); bottle4.set(10); System.out.println("The value of bottle4 is " + bottle4 + "."); System.out.println("Bottle4 is now multiplied with bottle1. The value is placed in bottle5."); bottle5 = bottle1.multiply(bottle4); System.out.println("The value of bottle5 is " + bottle5 + "."); System.out.println("Enter an integer to add to the value bottle1 has."); System.out.println("The sum will be put in bottle3."); x = scan.nextInt(); bottle3 = bottle1.add(x); System.out.println("Adding your number " + x + " to bottle1 gives a new Bottle with " +
  • 14. bottle3 + " in it."); System.out.print("Adding the number " + bottle2 + " which is the number" + " in bottle2 to the number in "); bottle2 = bottle1.add(bottle2); System.out.println("bottle1 which is " + bottle1 +" gives " + bottle2 + "."); } }