SlideShare a Scribd company logo
//**************************** PickerApp
CLass******************************************************
package increment.pick;
import java.util.Random;
public class PickerApp {
private int upperLimit;
private int number;
private int guessCount;
/**
* Default constructor
*/
public PickerApp() {
this(50);
}
/**
* Parameterized constructor
* param upperLimit
*/
public PickerApp(int upperLimit) {
this.upperLimit = upperLimit;
Random random = new Random();
number = random.nextInt(upperLimit - 1) + 1;
guessCount = 1;
}
public int getNumber() {
return number;
}
public int getGuessCount() {
return guessCount;
}
public int getUpperLimit() {
return upperLimit;
}
public void incrementGuessCount() {
guessCount = guessCount + 1;
}
}
//********************************** PICK
CLass****************************************************
package increment.pick;
import java.util.Scanner;
public class Pick {
public static void main(String args[]) {
System.out.println("Hello ");
System.out.println();
Scanner sc = new Scanner(System.in);
PickerApp game = new PickerApp();
System.out.println("I have selected a number between 0 and " + game.getUpperLimit());
System.out.println();
while(true) {
System.out.print("Enter your guess: "); //A) a)
int guess = 0;
try { //C) g)
guess = Integer.parseInt(sc.nextLine()); //A) a)
} catch(NumberFormatException nfe) {
System.out.println("Invalid number");
continue;
}
//D) i)
if((guess <= 0) || (guess >= game.getUpperLimit()))
System.out.println("Enter a between 0 and " + game.getUpperLimit() + " both
exclusive");
else {
if(guess == game.getNumber()) //A) b) If user guesses the correct number break
break;
else if (guess > (game.getNumber() + 10)) { //B) d)
System.out.println("Way too high! ");
}
else if (guess < game.getNumber()) {
System.out.println("Your guess is too low. ");
} else if (guess > game.getNumber()) {
System.out.println("Your guess is too high. ");
}
}
game.incrementGuessCount();
}
//B) e)
if(game.getGuessCount() <= 3)
System.out.println("Great work! You are a mathematical wizard.");
else if((game.getGuessCount() > 3) && (game.getGuessCount() <= 7))
System.out.println("Not too bad! You've got some potential.");
else if(game.getGuessCount() > 7)
System.out.println("What took so you so long? Maybe you shoould take some
lessons");
//Close scanner
sc.close();
}
}
SAMPLE OUTPUT:
Hello
I have selected a number between 0 and 50
Enter your guess: 0
Enter a between 0 and 50 both exclusive
Enter your guess: 50
Enter a between 0 and 50 both exclusive
Enter your guess: 2
Great work! You are a mathematical wizard.
Solution
//**************************** PickerApp
CLass******************************************************
package increment.pick;
import java.util.Random;
public class PickerApp {
private int upperLimit;
private int number;
private int guessCount;
/**
* Default constructor
*/
public PickerApp() {
this(50);
}
/**
* Parameterized constructor
* param upperLimit
*/
public PickerApp(int upperLimit) {
this.upperLimit = upperLimit;
Random random = new Random();
number = random.nextInt(upperLimit - 1) + 1;
guessCount = 1;
}
public int getNumber() {
return number;
}
public int getGuessCount() {
return guessCount;
}
public int getUpperLimit() {
return upperLimit;
}
public void incrementGuessCount() {
guessCount = guessCount + 1;
}
}
//********************************** PICK
CLass****************************************************
package increment.pick;
import java.util.Scanner;
public class Pick {
public static void main(String args[]) {
System.out.println("Hello ");
System.out.println();
Scanner sc = new Scanner(System.in);
PickerApp game = new PickerApp();
System.out.println("I have selected a number between 0 and " + game.getUpperLimit());
System.out.println();
while(true) {
System.out.print("Enter your guess: "); //A) a)
int guess = 0;
try { //C) g)
guess = Integer.parseInt(sc.nextLine()); //A) a)
} catch(NumberFormatException nfe) {
System.out.println("Invalid number");
continue;
}
//D) i)
if((guess <= 0) || (guess >= game.getUpperLimit()))
System.out.println("Enter a between 0 and " + game.getUpperLimit() + " both
exclusive");
else {
if(guess == game.getNumber()) //A) b) If user guesses the correct number break
break;
else if (guess > (game.getNumber() + 10)) { //B) d)
System.out.println("Way too high! ");
}
else if (guess < game.getNumber()) {
System.out.println("Your guess is too low. ");
} else if (guess > game.getNumber()) {
System.out.println("Your guess is too high. ");
}
}
game.incrementGuessCount();
}
//B) e)
if(game.getGuessCount() <= 3)
System.out.println("Great work! You are a mathematical wizard.");
else if((game.getGuessCount() > 3) && (game.getGuessCount() <= 7))
System.out.println("Not too bad! You've got some potential.");
else if(game.getGuessCount() > 7)
System.out.println("What took so you so long? Maybe you shoould take some
lessons");
//Close scanner
sc.close();
}
}
SAMPLE OUTPUT:
Hello
I have selected a number between 0 and 50
Enter your guess: 0
Enter a between 0 and 50 both exclusive
Enter your guess: 50
Enter a between 0 and 50 both exclusive
Enter your guess: 2
Great work! You are a mathematical wizard.

More Related Content

Similar to PickerApp CLass.pdf

Problemas secuenciales.
Problemas secuenciales.Problemas secuenciales.
Problemas secuenciales.
Erika Susan Villcas
 
Problemas secuenciales.
Problemas secuenciales.Problemas secuenciales.
Problemas secuenciales.
Erika Susan Villcas
 
Problemas secuenciales.
Problemas secuenciales.Problemas secuenciales.
Problemas secuenciales.
Erika Susan Villcas
 
Problemas secuenciales.
Problemas secuenciales.Problemas secuenciales.
Problemas secuenciales.
Erika Susan Villcas
 
Microsoft word java
Microsoft word   javaMicrosoft word   java
Microsoft word java
Ravi Purohit
 
1 The goal is to implement DataStructuresArrayStack accor.pdf
1 The goal is to implement DataStructuresArrayStack accor.pdf1 The goal is to implement DataStructuresArrayStack accor.pdf
1 The goal is to implement DataStructuresArrayStack accor.pdf
saradashata
 
PrimeRange.java import java.util.Scanner;public class PrimeRan.pdf
PrimeRange.java import java.util.Scanner;public class PrimeRan.pdfPrimeRange.java import java.util.Scanner;public class PrimeRan.pdf
PrimeRange.java import java.util.Scanner;public class PrimeRan.pdf
Ankitchhabra28
 
Using NetBeansImplement a queue named QueueLL using a Linked List .pdf
Using NetBeansImplement a queue named QueueLL using a Linked List .pdfUsing NetBeansImplement a queue named QueueLL using a Linked List .pdf
Using NetBeansImplement a queue named QueueLL using a Linked List .pdf
siennatimbok52331
 
BasicPizza.javapublic class BasicPizza { Declaring instance .pdf
BasicPizza.javapublic class BasicPizza { Declaring instance .pdfBasicPizza.javapublic class BasicPizza { Declaring instance .pdf
BasicPizza.javapublic class BasicPizza { Declaring instance .pdf
ankitmobileshop235
 
@author public class Person{   String sname, .pdf
  @author   public class Person{   String sname, .pdf  @author   public class Person{   String sname, .pdf
@author public class Person{   String sname, .pdf
aplolomedicalstoremr
 
Estructura secuencial -garcia
Estructura secuencial -garciaEstructura secuencial -garcia
Estructura secuencial -garcia
Daneziita Laulate Flores
 
import java.util.Scanner;public class Fraction {   instan.pdf
import java.util.Scanner;public class Fraction {    instan.pdfimport java.util.Scanner;public class Fraction {    instan.pdf
import java.util.Scanner;public class Fraction {   instan.pdf
apleathers
 
public class Point {   Insert your name here    private dou.pdf
public class Point {    Insert your name here    private dou.pdfpublic class Point {    Insert your name here    private dou.pdf
public class Point {   Insert your name here    private dou.pdf
anandshingavi23
 
import java.util.Random;ASSIGNMENT #2 MATRIX ARITHMETIC Cla.pdf
import java.util.Random;ASSIGNMENT #2 MATRIX ARITHMETIC Cla.pdfimport java.util.Random;ASSIGNMENT #2 MATRIX ARITHMETIC Cla.pdf
import java.util.Random;ASSIGNMENT #2 MATRIX ARITHMETIC Cla.pdf
aquacareser
 
import java.util.Scanner;public class HornersPolynomial {   .pdf
import java.util.Scanner;public class HornersPolynomial {   .pdfimport java.util.Scanner;public class HornersPolynomial {   .pdf
import java.util.Scanner;public class HornersPolynomial {   .pdf
aptex1
 
Frequency .java Word frequency counter package frequ.pdf
Frequency .java  Word frequency counter  package frequ.pdfFrequency .java  Word frequency counter  package frequ.pdf
Frequency .java Word frequency counter package frequ.pdf
arshiartpalace
 
Tested on EclipseBoth class should be in same package.pdf
Tested on EclipseBoth class should be in same package.pdfTested on EclipseBoth class should be in same package.pdf
Tested on EclipseBoth class should be in same package.pdf
anupamagarud8
 

Similar to PickerApp CLass.pdf (20)

Problemas secuenciales.
Problemas secuenciales.Problemas secuenciales.
Problemas secuenciales.
 
Problemas secuenciales.
Problemas secuenciales.Problemas secuenciales.
Problemas secuenciales.
 
Problemas secuenciales.
Problemas secuenciales.Problemas secuenciales.
Problemas secuenciales.
 
Problemas secuenciales.
Problemas secuenciales.Problemas secuenciales.
Problemas secuenciales.
 
Problemas secuenciales.
Problemas secuenciales.Problemas secuenciales.
Problemas secuenciales.
 
Microsoft word java
Microsoft word   javaMicrosoft word   java
Microsoft word java
 
1 The goal is to implement DataStructuresArrayStack accor.pdf
1 The goal is to implement DataStructuresArrayStack accor.pdf1 The goal is to implement DataStructuresArrayStack accor.pdf
1 The goal is to implement DataStructuresArrayStack accor.pdf
 
ETM Server
ETM ServerETM Server
ETM Server
 
PrimeRange.java import java.util.Scanner;public class PrimeRan.pdf
PrimeRange.java import java.util.Scanner;public class PrimeRan.pdfPrimeRange.java import java.util.Scanner;public class PrimeRan.pdf
PrimeRange.java import java.util.Scanner;public class PrimeRan.pdf
 
Using NetBeansImplement a queue named QueueLL using a Linked List .pdf
Using NetBeansImplement a queue named QueueLL using a Linked List .pdfUsing NetBeansImplement a queue named QueueLL using a Linked List .pdf
Using NetBeansImplement a queue named QueueLL using a Linked List .pdf
 
BasicPizza.javapublic class BasicPizza { Declaring instance .pdf
BasicPizza.javapublic class BasicPizza { Declaring instance .pdfBasicPizza.javapublic class BasicPizza { Declaring instance .pdf
BasicPizza.javapublic class BasicPizza { Declaring instance .pdf
 
@author public class Person{   String sname, .pdf
  @author   public class Person{   String sname, .pdf  @author   public class Person{   String sname, .pdf
@author public class Person{   String sname, .pdf
 
Estructura secuencial -garcia
Estructura secuencial -garciaEstructura secuencial -garcia
Estructura secuencial -garcia
 
import java.util.Scanner;public class Fraction {   instan.pdf
import java.util.Scanner;public class Fraction {    instan.pdfimport java.util.Scanner;public class Fraction {    instan.pdf
import java.util.Scanner;public class Fraction {   instan.pdf
 
public class Point {   Insert your name here    private dou.pdf
public class Point {    Insert your name here    private dou.pdfpublic class Point {    Insert your name here    private dou.pdf
public class Point {   Insert your name here    private dou.pdf
 
import java.util.Random;ASSIGNMENT #2 MATRIX ARITHMETIC Cla.pdf
import java.util.Random;ASSIGNMENT #2 MATRIX ARITHMETIC Cla.pdfimport java.util.Random;ASSIGNMENT #2 MATRIX ARITHMETIC Cla.pdf
import java.util.Random;ASSIGNMENT #2 MATRIX ARITHMETIC Cla.pdf
 
import java.util.Scanner;public class HornersPolynomial {   .pdf
import java.util.Scanner;public class HornersPolynomial {   .pdfimport java.util.Scanner;public class HornersPolynomial {   .pdf
import java.util.Scanner;public class HornersPolynomial {   .pdf
 
Mamdani
MamdaniMamdani
Mamdani
 
Frequency .java Word frequency counter package frequ.pdf
Frequency .java  Word frequency counter  package frequ.pdfFrequency .java  Word frequency counter  package frequ.pdf
Frequency .java Word frequency counter package frequ.pdf
 
Tested on EclipseBoth class should be in same package.pdf
Tested on EclipseBoth class should be in same package.pdfTested on EclipseBoth class should be in same package.pdf
Tested on EclipseBoth class should be in same package.pdf
 

More from ankitcom

using the equation P1V1T1 = P2V2T2 we have .pdf
                     using the equation P1V1T1 = P2V2T2  we have  .pdf                     using the equation P1V1T1 = P2V2T2  we have  .pdf
using the equation P1V1T1 = P2V2T2 we have .pdf
ankitcom
 
Yes, theyre right. .pdf
                     Yes, theyre right.                             .pdf                     Yes, theyre right.                             .pdf
Yes, theyre right. .pdf
ankitcom
 
we do not have rights to delete questionsSolutionwe do not hav.pdf
we do not have rights to delete questionsSolutionwe do not hav.pdfwe do not have rights to delete questionsSolutionwe do not hav.pdf
we do not have rights to delete questionsSolutionwe do not hav.pdf
ankitcom
 
The most iteresting or surprising fact about microbiology is the exi.pdf
The most iteresting or surprising fact about microbiology is the exi.pdfThe most iteresting or surprising fact about microbiology is the exi.pdf
The most iteresting or surprising fact about microbiology is the exi.pdf
ankitcom
 
The electrophilic aromatic substitution decreases ifelectron with dr.pdf
The electrophilic aromatic substitution decreases ifelectron with dr.pdfThe electrophilic aromatic substitution decreases ifelectron with dr.pdf
The electrophilic aromatic substitution decreases ifelectron with dr.pdf
ankitcom
 
The buffer solution contains the following species in solutionHCH.pdf
The buffer solution contains the following species in solutionHCH.pdfThe buffer solution contains the following species in solutionHCH.pdf
The buffer solution contains the following species in solutionHCH.pdf
ankitcom
 
That is Distributive propertySolutionThat is Distributive prop.pdf
That is Distributive propertySolutionThat is Distributive prop.pdfThat is Distributive propertySolutionThat is Distributive prop.pdf
That is Distributive propertySolutionThat is Distributive prop.pdf
ankitcom
 
System Maintenance         System maintenance is a current action,.pdf
System Maintenance         System maintenance is a current action,.pdfSystem Maintenance         System maintenance is a current action,.pdf
System Maintenance         System maintenance is a current action,.pdf
ankitcom
 
Sr(OH)2 Solution Sr(OH)2.pdf
                     Sr(OH)2  Solution                     Sr(OH)2.pdf                     Sr(OH)2  Solution                     Sr(OH)2.pdf
Sr(OH)2 Solution Sr(OH)2.pdf
ankitcom
 
sol It says that it absorbs 322 J of heat, there.pdf
                     sol It says that it absorbs 322 J of heat, there.pdf                     sol It says that it absorbs 322 J of heat, there.pdf
sol It says that it absorbs 322 J of heat, there.pdf
ankitcom
 
Reverse transcriptase is an enzyme present in some of the virses whi.pdf
Reverse transcriptase is an enzyme present in some of the virses whi.pdfReverse transcriptase is an enzyme present in some of the virses whi.pdf
Reverse transcriptase is an enzyme present in some of the virses whi.pdf
ankitcom
 
public class InsufficientFundsException extends Exception{Insuffic.pdf
public class InsufficientFundsException extends Exception{Insuffic.pdfpublic class InsufficientFundsException extends Exception{Insuffic.pdf
public class InsufficientFundsException extends Exception{Insuffic.pdf
ankitcom
 
Plug in real numbers for a and b.Since it isnSolutionPlug in.pdf
Plug in real numbers for a and b.Since it isnSolutionPlug in.pdfPlug in real numbers for a and b.Since it isnSolutionPlug in.pdf
Plug in real numbers for a and b.Since it isnSolutionPlug in.pdf
ankitcom
 
momSolutionmom.pdf
momSolutionmom.pdfmomSolutionmom.pdf
momSolutionmom.pdf
ankitcom
 
Retention factor (Rƒ) is the distance travelled b.pdf
                     Retention factor (Rƒ) is the distance travelled b.pdf                     Retention factor (Rƒ) is the distance travelled b.pdf
Retention factor (Rƒ) is the distance travelled b.pdf
ankitcom
 
Java doesnt support multiple inheritance, therefore a class cannot.pdf
Java doesnt support multiple inheritance, therefore a class cannot.pdfJava doesnt support multiple inheritance, therefore a class cannot.pdf
Java doesnt support multiple inheritance, therefore a class cannot.pdf
ankitcom
 
In pc engineering, pc design is that the abstract style and elementa.pdf
In pc engineering, pc design is that the abstract style and elementa.pdfIn pc engineering, pc design is that the abstract style and elementa.pdf
In pc engineering, pc design is that the abstract style and elementa.pdf
ankitcom
 
In the year 1900, the maximum number of deaths occurred due to infec.pdf
In the year 1900, the maximum number of deaths occurred due to infec.pdfIn the year 1900, the maximum number of deaths occurred due to infec.pdf
In the year 1900, the maximum number of deaths occurred due to infec.pdf
ankitcom
 
home.htmlStarted!DOCTYPE html html la.pdf
home.htmlStarted!DOCTYPE html html la.pdfhome.htmlStarted!DOCTYPE html html la.pdf
home.htmlStarted!DOCTYPE html html la.pdf
ankitcom
 
Pb3O4 -- PbO + Pb2O3 hence the mole ratio of le.pdf
                     Pb3O4 -- PbO + Pb2O3  hence the mole ratio of le.pdf                     Pb3O4 -- PbO + Pb2O3  hence the mole ratio of le.pdf
Pb3O4 -- PbO + Pb2O3 hence the mole ratio of le.pdf
ankitcom
 

More from ankitcom (20)

using the equation P1V1T1 = P2V2T2 we have .pdf
                     using the equation P1V1T1 = P2V2T2  we have  .pdf                     using the equation P1V1T1 = P2V2T2  we have  .pdf
using the equation P1V1T1 = P2V2T2 we have .pdf
 
Yes, theyre right. .pdf
                     Yes, theyre right.                             .pdf                     Yes, theyre right.                             .pdf
Yes, theyre right. .pdf
 
we do not have rights to delete questionsSolutionwe do not hav.pdf
we do not have rights to delete questionsSolutionwe do not hav.pdfwe do not have rights to delete questionsSolutionwe do not hav.pdf
we do not have rights to delete questionsSolutionwe do not hav.pdf
 
The most iteresting or surprising fact about microbiology is the exi.pdf
The most iteresting or surprising fact about microbiology is the exi.pdfThe most iteresting or surprising fact about microbiology is the exi.pdf
The most iteresting or surprising fact about microbiology is the exi.pdf
 
The electrophilic aromatic substitution decreases ifelectron with dr.pdf
The electrophilic aromatic substitution decreases ifelectron with dr.pdfThe electrophilic aromatic substitution decreases ifelectron with dr.pdf
The electrophilic aromatic substitution decreases ifelectron with dr.pdf
 
The buffer solution contains the following species in solutionHCH.pdf
The buffer solution contains the following species in solutionHCH.pdfThe buffer solution contains the following species in solutionHCH.pdf
The buffer solution contains the following species in solutionHCH.pdf
 
That is Distributive propertySolutionThat is Distributive prop.pdf
That is Distributive propertySolutionThat is Distributive prop.pdfThat is Distributive propertySolutionThat is Distributive prop.pdf
That is Distributive propertySolutionThat is Distributive prop.pdf
 
System Maintenance         System maintenance is a current action,.pdf
System Maintenance         System maintenance is a current action,.pdfSystem Maintenance         System maintenance is a current action,.pdf
System Maintenance         System maintenance is a current action,.pdf
 
Sr(OH)2 Solution Sr(OH)2.pdf
                     Sr(OH)2  Solution                     Sr(OH)2.pdf                     Sr(OH)2  Solution                     Sr(OH)2.pdf
Sr(OH)2 Solution Sr(OH)2.pdf
 
sol It says that it absorbs 322 J of heat, there.pdf
                     sol It says that it absorbs 322 J of heat, there.pdf                     sol It says that it absorbs 322 J of heat, there.pdf
sol It says that it absorbs 322 J of heat, there.pdf
 
Reverse transcriptase is an enzyme present in some of the virses whi.pdf
Reverse transcriptase is an enzyme present in some of the virses whi.pdfReverse transcriptase is an enzyme present in some of the virses whi.pdf
Reverse transcriptase is an enzyme present in some of the virses whi.pdf
 
public class InsufficientFundsException extends Exception{Insuffic.pdf
public class InsufficientFundsException extends Exception{Insuffic.pdfpublic class InsufficientFundsException extends Exception{Insuffic.pdf
public class InsufficientFundsException extends Exception{Insuffic.pdf
 
Plug in real numbers for a and b.Since it isnSolutionPlug in.pdf
Plug in real numbers for a and b.Since it isnSolutionPlug in.pdfPlug in real numbers for a and b.Since it isnSolutionPlug in.pdf
Plug in real numbers for a and b.Since it isnSolutionPlug in.pdf
 
momSolutionmom.pdf
momSolutionmom.pdfmomSolutionmom.pdf
momSolutionmom.pdf
 
Retention factor (Rƒ) is the distance travelled b.pdf
                     Retention factor (Rƒ) is the distance travelled b.pdf                     Retention factor (Rƒ) is the distance travelled b.pdf
Retention factor (Rƒ) is the distance travelled b.pdf
 
Java doesnt support multiple inheritance, therefore a class cannot.pdf
Java doesnt support multiple inheritance, therefore a class cannot.pdfJava doesnt support multiple inheritance, therefore a class cannot.pdf
Java doesnt support multiple inheritance, therefore a class cannot.pdf
 
In pc engineering, pc design is that the abstract style and elementa.pdf
In pc engineering, pc design is that the abstract style and elementa.pdfIn pc engineering, pc design is that the abstract style and elementa.pdf
In pc engineering, pc design is that the abstract style and elementa.pdf
 
In the year 1900, the maximum number of deaths occurred due to infec.pdf
In the year 1900, the maximum number of deaths occurred due to infec.pdfIn the year 1900, the maximum number of deaths occurred due to infec.pdf
In the year 1900, the maximum number of deaths occurred due to infec.pdf
 
home.htmlStarted!DOCTYPE html html la.pdf
home.htmlStarted!DOCTYPE html html la.pdfhome.htmlStarted!DOCTYPE html html la.pdf
home.htmlStarted!DOCTYPE html html la.pdf
 
Pb3O4 -- PbO + Pb2O3 hence the mole ratio of le.pdf
                     Pb3O4 -- PbO + Pb2O3  hence the mole ratio of le.pdf                     Pb3O4 -- PbO + Pb2O3  hence the mole ratio of le.pdf
Pb3O4 -- PbO + Pb2O3 hence the mole ratio of le.pdf
 

Recently uploaded

Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...
Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...
Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...
Dr. Vinod Kumar Kanvaria
 
Assignment_4_ArianaBusciglio Marvel(1).docx
Assignment_4_ArianaBusciglio Marvel(1).docxAssignment_4_ArianaBusciglio Marvel(1).docx
Assignment_4_ArianaBusciglio Marvel(1).docx
ArianaBusciglio
 
PCOS corelations and management through Ayurveda.
PCOS corelations and management through Ayurveda.PCOS corelations and management through Ayurveda.
PCOS corelations and management through Ayurveda.
Dr. Shivangi Singh Parihar
 
What is the purpose of studying mathematics.pptx
What is the purpose of studying mathematics.pptxWhat is the purpose of studying mathematics.pptx
What is the purpose of studying mathematics.pptx
christianmathematics
 
বাংলাদেশ অর্থনৈতিক সমীক্ষা (Economic Review) ২০২৪ UJS App.pdf
বাংলাদেশ অর্থনৈতিক সমীক্ষা (Economic Review) ২০২৪ UJS App.pdfবাংলাদেশ অর্থনৈতিক সমীক্ষা (Economic Review) ২০২৪ UJS App.pdf
বাংলাদেশ অর্থনৈতিক সমীক্ষা (Economic Review) ২০২৪ UJS App.pdf
eBook.com.bd (প্রয়োজনীয় বাংলা বই)
 
Reflective and Evaluative Practice...pdf
Reflective and Evaluative Practice...pdfReflective and Evaluative Practice...pdf
Reflective and Evaluative Practice...pdf
amberjdewit93
 
Reflective and Evaluative Practice PowerPoint
Reflective and Evaluative Practice PowerPointReflective and Evaluative Practice PowerPoint
Reflective and Evaluative Practice PowerPoint
amberjdewit93
 
Introduction to AI for Nonprofits with Tapp Network
Introduction to AI for Nonprofits with Tapp NetworkIntroduction to AI for Nonprofits with Tapp Network
Introduction to AI for Nonprofits with Tapp Network
TechSoup
 
Natural birth techniques - Mrs.Akanksha Trivedi Rama University
Natural birth techniques - Mrs.Akanksha Trivedi Rama UniversityNatural birth techniques - Mrs.Akanksha Trivedi Rama University
Natural birth techniques - Mrs.Akanksha Trivedi Rama University
Akanksha trivedi rama nursing college kanpur.
 
MERN Stack Developer Roadmap By ScholarHat PDF
MERN Stack Developer Roadmap By ScholarHat PDFMERN Stack Developer Roadmap By ScholarHat PDF
MERN Stack Developer Roadmap By ScholarHat PDF
scholarhattraining
 
World environment day ppt For 5 June 2024
World environment day ppt For 5 June 2024World environment day ppt For 5 June 2024
World environment day ppt For 5 June 2024
ak6969907
 
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
 
Your Skill Boost Masterclass: Strategies for Effective Upskilling
Your Skill Boost Masterclass: Strategies for Effective UpskillingYour Skill Boost Masterclass: Strategies for Effective Upskilling
Your Skill Boost Masterclass: Strategies for Effective Upskilling
Excellence Foundation for South Sudan
 
kitab khulasah nurul yaqin jilid 1 - 2.pptx
kitab khulasah nurul yaqin jilid 1 - 2.pptxkitab khulasah nurul yaqin jilid 1 - 2.pptx
kitab khulasah nurul yaqin jilid 1 - 2.pptx
datarid22
 
PIMS Job Advertisement 2024.pdf Islamabad
PIMS Job Advertisement 2024.pdf IslamabadPIMS Job Advertisement 2024.pdf Islamabad
PIMS Job Advertisement 2024.pdf Islamabad
AyyanKhan40
 
S1-Introduction-Biopesticides in ICM.pptx
S1-Introduction-Biopesticides in ICM.pptxS1-Introduction-Biopesticides in ICM.pptx
S1-Introduction-Biopesticides in ICM.pptx
tarandeep35
 
The basics of sentences session 5pptx.pptx
The basics of sentences session 5pptx.pptxThe basics of sentences session 5pptx.pptx
The basics of sentences session 5pptx.pptx
heathfieldcps1
 
Pollock and Snow "DEIA in the Scholarly Landscape, Session One: Setting Expec...
Pollock and Snow "DEIA in the Scholarly Landscape, Session One: Setting Expec...Pollock and Snow "DEIA in the Scholarly Landscape, Session One: Setting Expec...
Pollock and Snow "DEIA in the Scholarly Landscape, Session One: Setting Expec...
National Information Standards Organization (NISO)
 
Digital Artifact 1 - 10VCD Environments Unit
Digital Artifact 1 - 10VCD Environments UnitDigital Artifact 1 - 10VCD Environments Unit
Digital Artifact 1 - 10VCD Environments Unit
chanes7
 
"Protectable subject matters, Protection in biotechnology, Protection of othe...
"Protectable subject matters, Protection in biotechnology, Protection of othe..."Protectable subject matters, Protection in biotechnology, Protection of othe...
"Protectable subject matters, Protection in biotechnology, Protection of othe...
SACHIN R KONDAGURI
 

Recently uploaded (20)

Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...
Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...
Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...
 
Assignment_4_ArianaBusciglio Marvel(1).docx
Assignment_4_ArianaBusciglio Marvel(1).docxAssignment_4_ArianaBusciglio Marvel(1).docx
Assignment_4_ArianaBusciglio Marvel(1).docx
 
PCOS corelations and management through Ayurveda.
PCOS corelations and management through Ayurveda.PCOS corelations and management through Ayurveda.
PCOS corelations and management through Ayurveda.
 
What is the purpose of studying mathematics.pptx
What is the purpose of studying mathematics.pptxWhat is the purpose of studying mathematics.pptx
What is the purpose of studying mathematics.pptx
 
বাংলাদেশ অর্থনৈতিক সমীক্ষা (Economic Review) ২০২৪ UJS App.pdf
বাংলাদেশ অর্থনৈতিক সমীক্ষা (Economic Review) ২০২৪ UJS App.pdfবাংলাদেশ অর্থনৈতিক সমীক্ষা (Economic Review) ২০২৪ UJS App.pdf
বাংলাদেশ অর্থনৈতিক সমীক্ষা (Economic Review) ২০২৪ UJS App.pdf
 
Reflective and Evaluative Practice...pdf
Reflective and Evaluative Practice...pdfReflective and Evaluative Practice...pdf
Reflective and Evaluative Practice...pdf
 
Reflective and Evaluative Practice PowerPoint
Reflective and Evaluative Practice PowerPointReflective and Evaluative Practice PowerPoint
Reflective and Evaluative Practice PowerPoint
 
Introduction to AI for Nonprofits with Tapp Network
Introduction to AI for Nonprofits with Tapp NetworkIntroduction to AI for Nonprofits with Tapp Network
Introduction to AI for Nonprofits with Tapp Network
 
Natural birth techniques - Mrs.Akanksha Trivedi Rama University
Natural birth techniques - Mrs.Akanksha Trivedi Rama UniversityNatural birth techniques - Mrs.Akanksha Trivedi Rama University
Natural birth techniques - Mrs.Akanksha Trivedi Rama University
 
MERN Stack Developer Roadmap By ScholarHat PDF
MERN Stack Developer Roadmap By ScholarHat PDFMERN Stack Developer Roadmap By ScholarHat PDF
MERN Stack Developer Roadmap By ScholarHat PDF
 
World environment day ppt For 5 June 2024
World environment day ppt For 5 June 2024World environment day ppt For 5 June 2024
World environment day ppt For 5 June 2024
 
A Strategic Approach: GenAI in Education
A Strategic Approach: GenAI in EducationA Strategic Approach: GenAI in Education
A Strategic Approach: GenAI in Education
 
Your Skill Boost Masterclass: Strategies for Effective Upskilling
Your Skill Boost Masterclass: Strategies for Effective UpskillingYour Skill Boost Masterclass: Strategies for Effective Upskilling
Your Skill Boost Masterclass: Strategies for Effective Upskilling
 
kitab khulasah nurul yaqin jilid 1 - 2.pptx
kitab khulasah nurul yaqin jilid 1 - 2.pptxkitab khulasah nurul yaqin jilid 1 - 2.pptx
kitab khulasah nurul yaqin jilid 1 - 2.pptx
 
PIMS Job Advertisement 2024.pdf Islamabad
PIMS Job Advertisement 2024.pdf IslamabadPIMS Job Advertisement 2024.pdf Islamabad
PIMS Job Advertisement 2024.pdf Islamabad
 
S1-Introduction-Biopesticides in ICM.pptx
S1-Introduction-Biopesticides in ICM.pptxS1-Introduction-Biopesticides in ICM.pptx
S1-Introduction-Biopesticides in ICM.pptx
 
The basics of sentences session 5pptx.pptx
The basics of sentences session 5pptx.pptxThe basics of sentences session 5pptx.pptx
The basics of sentences session 5pptx.pptx
 
Pollock and Snow "DEIA in the Scholarly Landscape, Session One: Setting Expec...
Pollock and Snow "DEIA in the Scholarly Landscape, Session One: Setting Expec...Pollock and Snow "DEIA in the Scholarly Landscape, Session One: Setting Expec...
Pollock and Snow "DEIA in the Scholarly Landscape, Session One: Setting Expec...
 
Digital Artifact 1 - 10VCD Environments Unit
Digital Artifact 1 - 10VCD Environments UnitDigital Artifact 1 - 10VCD Environments Unit
Digital Artifact 1 - 10VCD Environments Unit
 
"Protectable subject matters, Protection in biotechnology, Protection of othe...
"Protectable subject matters, Protection in biotechnology, Protection of othe..."Protectable subject matters, Protection in biotechnology, Protection of othe...
"Protectable subject matters, Protection in biotechnology, Protection of othe...
 

PickerApp CLass.pdf

  • 1. //**************************** PickerApp CLass****************************************************** package increment.pick; import java.util.Random; public class PickerApp { private int upperLimit; private int number; private int guessCount; /** * Default constructor */ public PickerApp() { this(50); } /** * Parameterized constructor * param upperLimit */ public PickerApp(int upperLimit) { this.upperLimit = upperLimit; Random random = new Random(); number = random.nextInt(upperLimit - 1) + 1; guessCount = 1; } public int getNumber() { return number; } public int getGuessCount() { return guessCount; } public int getUpperLimit() { return upperLimit; } public void incrementGuessCount() { guessCount = guessCount + 1;
  • 2. } } //********************************** PICK CLass**************************************************** package increment.pick; import java.util.Scanner; public class Pick { public static void main(String args[]) { System.out.println("Hello "); System.out.println(); Scanner sc = new Scanner(System.in); PickerApp game = new PickerApp(); System.out.println("I have selected a number between 0 and " + game.getUpperLimit()); System.out.println(); while(true) { System.out.print("Enter your guess: "); //A) a) int guess = 0; try { //C) g) guess = Integer.parseInt(sc.nextLine()); //A) a) } catch(NumberFormatException nfe) { System.out.println("Invalid number"); continue; } //D) i) if((guess <= 0) || (guess >= game.getUpperLimit())) System.out.println("Enter a between 0 and " + game.getUpperLimit() + " both exclusive"); else { if(guess == game.getNumber()) //A) b) If user guesses the correct number break break; else if (guess > (game.getNumber() + 10)) { //B) d) System.out.println("Way too high! "); } else if (guess < game.getNumber()) {
  • 3. System.out.println("Your guess is too low. "); } else if (guess > game.getNumber()) { System.out.println("Your guess is too high. "); } } game.incrementGuessCount(); } //B) e) if(game.getGuessCount() <= 3) System.out.println("Great work! You are a mathematical wizard."); else if((game.getGuessCount() > 3) && (game.getGuessCount() <= 7)) System.out.println("Not too bad! You've got some potential."); else if(game.getGuessCount() > 7) System.out.println("What took so you so long? Maybe you shoould take some lessons"); //Close scanner sc.close(); } } SAMPLE OUTPUT: Hello I have selected a number between 0 and 50 Enter your guess: 0 Enter a between 0 and 50 both exclusive Enter your guess: 50 Enter a between 0 and 50 both exclusive Enter your guess: 2 Great work! You are a mathematical wizard. Solution //**************************** PickerApp CLass****************************************************** package increment.pick;
  • 4. import java.util.Random; public class PickerApp { private int upperLimit; private int number; private int guessCount; /** * Default constructor */ public PickerApp() { this(50); } /** * Parameterized constructor * param upperLimit */ public PickerApp(int upperLimit) { this.upperLimit = upperLimit; Random random = new Random(); number = random.nextInt(upperLimit - 1) + 1; guessCount = 1; } public int getNumber() { return number; } public int getGuessCount() { return guessCount; } public int getUpperLimit() { return upperLimit; } public void incrementGuessCount() { guessCount = guessCount + 1; } } //********************************** PICK CLass****************************************************
  • 5. package increment.pick; import java.util.Scanner; public class Pick { public static void main(String args[]) { System.out.println("Hello "); System.out.println(); Scanner sc = new Scanner(System.in); PickerApp game = new PickerApp(); System.out.println("I have selected a number between 0 and " + game.getUpperLimit()); System.out.println(); while(true) { System.out.print("Enter your guess: "); //A) a) int guess = 0; try { //C) g) guess = Integer.parseInt(sc.nextLine()); //A) a) } catch(NumberFormatException nfe) { System.out.println("Invalid number"); continue; } //D) i) if((guess <= 0) || (guess >= game.getUpperLimit())) System.out.println("Enter a between 0 and " + game.getUpperLimit() + " both exclusive"); else { if(guess == game.getNumber()) //A) b) If user guesses the correct number break break; else if (guess > (game.getNumber() + 10)) { //B) d) System.out.println("Way too high! "); } else if (guess < game.getNumber()) { System.out.println("Your guess is too low. "); } else if (guess > game.getNumber()) { System.out.println("Your guess is too high. "); }
  • 6. } game.incrementGuessCount(); } //B) e) if(game.getGuessCount() <= 3) System.out.println("Great work! You are a mathematical wizard."); else if((game.getGuessCount() > 3) && (game.getGuessCount() <= 7)) System.out.println("Not too bad! You've got some potential."); else if(game.getGuessCount() > 7) System.out.println("What took so you so long? Maybe you shoould take some lessons"); //Close scanner sc.close(); } } SAMPLE OUTPUT: Hello I have selected a number between 0 and 50 Enter your guess: 0 Enter a between 0 and 50 both exclusive Enter your guess: 50 Enter a between 0 and 50 both exclusive Enter your guess: 2 Great work! You are a mathematical wizard.