SlideShare a Scribd company logo
1 of 4
Download to read offline
Hi, Please find mu code:
import java.util.Random;
public class SuperDie {
private int sides;
private Random rand;
public SuperDie(){ // Default constructor
sides = 6;
rand = new Random();
}
// Constructor that lets user define number of sides n.
public SuperDie(int n){
sides = n;
rand = new Random();
}
// Constructor that lets user define number of sides n AND provide their own Random object.
public SuperDie(int n, Random r){
sides = n;
rand = r;
}
public int getNumSides(){
return sides;
}
public void setNumSides(int n){
sides = n;
}
public int roll(){
return rand.nextInt(sides)+1;
}
}
import java.util.*;
class MainDie {
public static void main (String[] args) {
int value, sides;
Random rand = new Random();
SuperDie d1 = new SuperDie();
SuperDie d2 = new SuperDie(20);
SuperDie d3 = new SuperDie(10,rand);
value = d1.roll();
System.out.println ("die1 = " + value);
value = d2.roll();
System.out.println ("die2 = " + value);
value = d3.roll();
System.out.println ("die3 = " + value);
d1.setNumSides(8);
System.out.println ("die1 = " + d1.getNumSides());
}
}
/*
Sample Output:
die1 = 5
die2 = 5
die3 = 2
die1 = 8
*/
Solution
Hi, Please find mu code:
import java.util.Random;
public class SuperDie {
private int sides;
private Random rand;
public SuperDie(){ // Default constructor
sides = 6;
rand = new Random();
}
// Constructor that lets user define number of sides n.
public SuperDie(int n){
sides = n;
rand = new Random();
}
// Constructor that lets user define number of sides n AND provide their own Random object.
public SuperDie(int n, Random r){
sides = n;
rand = r;
}
public int getNumSides(){
return sides;
}
public void setNumSides(int n){
sides = n;
}
public int roll(){
return rand.nextInt(sides)+1;
}
}
import java.util.*;
class MainDie {
public static void main (String[] args) {
int value, sides;
Random rand = new Random();
SuperDie d1 = new SuperDie();
SuperDie d2 = new SuperDie(20);
SuperDie d3 = new SuperDie(10,rand);
value = d1.roll();
System.out.println ("die1 = " + value);
value = d2.roll();
System.out.println ("die2 = " + value);
value = d3.roll();
System.out.println ("die3 = " + value);
d1.setNumSides(8);
System.out.println ("die1 = " + d1.getNumSides());
}
}
/*
Sample Output:
die1 = 5
die2 = 5
die3 = 2
die1 = 8
*/

More Related Content

Similar to Hi, Please find mu codeimport java.util.Random;public class Sup.pdf

Android RenderScript
Android RenderScriptAndroid RenderScript
Android RenderScriptJungsoo Nam
 
Kotlin Bytecode Generation and Runtime Performance
Kotlin Bytecode Generation and Runtime PerformanceKotlin Bytecode Generation and Runtime Performance
Kotlin Bytecode Generation and Runtime Performanceintelliyole
 
Please help me make a UML for Java! Look at the code below and make a.docx
Please help me make a UML for Java! Look at the code below and make a.docxPlease help me make a UML for Java! Look at the code below and make a.docx
Please help me make a UML for Java! Look at the code below and make a.docxJakeT2gGrayp
 
Using Java, please write the program for the following prompt in the.pdf
Using Java, please write the program for the following prompt in the.pdfUsing Java, please write the program for the following prompt in the.pdf
Using Java, please write the program for the following prompt in the.pdfforecastfashions
 
import java.util.Scanner;class BinaryNode{     BinaryNode left.pdf
import java.util.Scanner;class BinaryNode{     BinaryNode left.pdfimport java.util.Scanner;class BinaryNode{     BinaryNode left.pdf
import java.util.Scanner;class BinaryNode{     BinaryNode left.pdfshaktisinhgandhinaga
 
Classes and object
Classes and objectClasses and object
Classes and objectAnkit Dubey
 
PROGRAM 2 – Fraction Class Problem For this programming as.pdf
PROGRAM 2 – Fraction Class Problem For this programming as.pdfPROGRAM 2 – Fraction Class Problem For this programming as.pdf
PROGRAM 2 – Fraction Class Problem For this programming as.pdfezonesolutions
 
Dotnet unit 4
Dotnet unit 4Dotnet unit 4
Dotnet unit 4007laksh
 
Tank Battle - A simple game powered by JMonkey engine
Tank Battle - A simple game powered by JMonkey engineTank Battle - A simple game powered by JMonkey engine
Tank Battle - A simple game powered by JMonkey engineFarzad Nozarian
 
Sceneform SDK на практиці - UA Mobile 2019
Sceneform SDK на практиці - UA Mobile 2019Sceneform SDK на практиці - UA Mobile 2019
Sceneform SDK на практиці - UA Mobile 2019UA Mobile
 
Sceneform SDK на практиці - UA Mobile 2019
Sceneform SDK на практиці - UA Mobile 2019Sceneform SDK на практиці - UA Mobile 2019
Sceneform SDK на практиці - UA Mobile 2019Eugene Kurko
 
Web2Day 2017 - Concilier DomainDriveDesign et API REST
Web2Day 2017 - Concilier DomainDriveDesign et API RESTWeb2Day 2017 - Concilier DomainDriveDesign et API REST
Web2Day 2017 - Concilier DomainDriveDesign et API RESTNicolas Faugout
 
Operator overloading
Operator overloadingOperator overloading
Operator overloadingabhay singh
 
Constructors and Destructors
Constructors and DestructorsConstructors and Destructors
Constructors and DestructorsKeyur Vadodariya
 
The State of JavaScript (2015)
The State of JavaScript (2015)The State of JavaScript (2015)
The State of JavaScript (2015)Domenic Denicola
 
C# 6.0 - April 2014 preview
C# 6.0 - April 2014 previewC# 6.0 - April 2014 preview
C# 6.0 - April 2014 previewPaulo Morgado
 
2016 gunma.web games-and-asm.js
2016 gunma.web games-and-asm.js2016 gunma.web games-and-asm.js
2016 gunma.web games-and-asm.jsNoritada Shimizu
 
Intro to object oriented programming
Intro to object oriented programmingIntro to object oriented programming
Intro to object oriented programmingDavid Giard
 

Similar to Hi, Please find mu codeimport java.util.Random;public class Sup.pdf (20)

Android RenderScript
Android RenderScriptAndroid RenderScript
Android RenderScript
 
Kotlin Bytecode Generation and Runtime Performance
Kotlin Bytecode Generation and Runtime PerformanceKotlin Bytecode Generation and Runtime Performance
Kotlin Bytecode Generation and Runtime Performance
 
Please help me make a UML for Java! Look at the code below and make a.docx
Please help me make a UML for Java! Look at the code below and make a.docxPlease help me make a UML for Java! Look at the code below and make a.docx
Please help me make a UML for Java! Look at the code below and make a.docx
 
Using Java, please write the program for the following prompt in the.pdf
Using Java, please write the program for the following prompt in the.pdfUsing Java, please write the program for the following prompt in the.pdf
Using Java, please write the program for the following prompt in the.pdf
 
import java.util.Scanner;class BinaryNode{     BinaryNode left.pdf
import java.util.Scanner;class BinaryNode{     BinaryNode left.pdfimport java.util.Scanner;class BinaryNode{     BinaryNode left.pdf
import java.util.Scanner;class BinaryNode{     BinaryNode left.pdf
 
662305 10
662305 10662305 10
662305 10
 
Classes and object
Classes and objectClasses and object
Classes and object
 
PROGRAM 2 – Fraction Class Problem For this programming as.pdf
PROGRAM 2 – Fraction Class Problem For this programming as.pdfPROGRAM 2 – Fraction Class Problem For this programming as.pdf
PROGRAM 2 – Fraction Class Problem For this programming as.pdf
 
Dotnet unit 4
Dotnet unit 4Dotnet unit 4
Dotnet unit 4
 
Tank Battle - A simple game powered by JMonkey engine
Tank Battle - A simple game powered by JMonkey engineTank Battle - A simple game powered by JMonkey engine
Tank Battle - A simple game powered by JMonkey engine
 
Sceneform SDK на практиці - UA Mobile 2019
Sceneform SDK на практиці - UA Mobile 2019Sceneform SDK на практиці - UA Mobile 2019
Sceneform SDK на практиці - UA Mobile 2019
 
Sceneform SDK на практиці - UA Mobile 2019
Sceneform SDK на практиці - UA Mobile 2019Sceneform SDK на практиці - UA Mobile 2019
Sceneform SDK на практиці - UA Mobile 2019
 
Web2Day 2017 - Concilier DomainDriveDesign et API REST
Web2Day 2017 - Concilier DomainDriveDesign et API RESTWeb2Day 2017 - Concilier DomainDriveDesign et API REST
Web2Day 2017 - Concilier DomainDriveDesign et API REST
 
Operator overloading
Operator overloadingOperator overloading
Operator overloading
 
Constructors and Destructors
Constructors and DestructorsConstructors and Destructors
Constructors and Destructors
 
The State of JavaScript (2015)
The State of JavaScript (2015)The State of JavaScript (2015)
The State of JavaScript (2015)
 
C# 6.0 - April 2014 preview
C# 6.0 - April 2014 previewC# 6.0 - April 2014 preview
C# 6.0 - April 2014 preview
 
2016 gunma.web games-and-asm.js
2016 gunma.web games-and-asm.js2016 gunma.web games-and-asm.js
2016 gunma.web games-and-asm.js
 
Intro to object oriented programming
Intro to object oriented programmingIntro to object oriented programming
Intro to object oriented programming
 
Design Patterns
Design PatternsDesign Patterns
Design Patterns
 

More from karan8801

1. C.HIV is a virus it can be tansmitted through body fluids liks .pdf
1. C.HIV is a virus it can be tansmitted through body fluids liks .pdf1. C.HIV is a virus it can be tansmitted through body fluids liks .pdf
1. C.HIV is a virus it can be tansmitted through body fluids liks .pdfkaran8801
 
#include iostream #include cstddefusing namespace std;temp.pdf
#include iostream #include cstddefusing namespace std;temp.pdf#include iostream #include cstddefusing namespace std;temp.pdf
#include iostream #include cstddefusing namespace std;temp.pdfkaran8801
 
omparative historical research is a method of social science that e.pdf
 omparative historical research is a method of social science that e.pdf omparative historical research is a method of social science that e.pdf
omparative historical research is a method of social science that e.pdfkaran8801
 
1 .D 2.BSolution 1 .D 2.B.pdf
 1 .D 2.BSolution 1 .D 2.B.pdf 1 .D 2.BSolution 1 .D 2.B.pdf
1 .D 2.BSolution 1 .D 2.B.pdfkaran8801
 
where is it .pdf
                     where is it                                      .pdf                     where is it                                      .pdf
where is it .pdfkaran8801
 
The name of the reaction is aldol condesation (Cl.pdf
                     The name of the reaction is aldol condesation (Cl.pdf                     The name of the reaction is aldol condesation (Cl.pdf
The name of the reaction is aldol condesation (Cl.pdfkaran8801
 
Step1 3 moles of H2O react with Cr metal = 2moles.pdf
                     Step1 3 moles of H2O react with Cr metal = 2moles.pdf                     Step1 3 moles of H2O react with Cr metal = 2moles.pdf
Step1 3 moles of H2O react with Cr metal = 2moles.pdfkaran8801
 
sp2 - sp2 .pdf
                     sp2 - sp2                                       .pdf                     sp2 - sp2                                       .pdf
sp2 - sp2 .pdfkaran8801
 
Part A neutralizes acids - base Part B produces.pdf
                     Part A neutralizes acids - base Part B produces.pdf                     Part A neutralizes acids - base Part B produces.pdf
Part A neutralizes acids - base Part B produces.pdfkaran8801
 
Lewis Acid Base Reaction .pdf
                     Lewis Acid Base Reaction                         .pdf                     Lewis Acid Base Reaction                         .pdf
Lewis Acid Base Reaction .pdfkaran8801
 
KOH ==== K+ (aq) + OH-(aq) [OH-] =9.710^-5 [H.pdf
                     KOH ==== K+ (aq) + OH-(aq)  [OH-] =9.710^-5  [H.pdf                     KOH ==== K+ (aq) + OH-(aq)  [OH-] =9.710^-5  [H.pdf
KOH ==== K+ (aq) + OH-(aq) [OH-] =9.710^-5 [H.pdfkaran8801
 
It is a reaction for secondary amines .Option 2 i.pdf
                     It is a reaction for secondary amines .Option 2 i.pdf                     It is a reaction for secondary amines .Option 2 i.pdf
It is a reaction for secondary amines .Option 2 i.pdfkaran8801
 
fluorene is mobile phase and fluorenone is statio.pdf
                     fluorene is mobile phase and fluorenone is statio.pdf                     fluorene is mobile phase and fluorenone is statio.pdf
fluorene is mobile phase and fluorenone is statio.pdfkaran8801
 
equivalent mass is 27.9 . so Molecular massmole.pdf
                     equivalent mass is 27.9 .  so Molecular massmole.pdf                     equivalent mass is 27.9 .  so Molecular massmole.pdf
equivalent mass is 27.9 . so Molecular massmole.pdfkaran8801
 
There is no solutionSolutionThere is no solution.pdf
There is no solutionSolutionThere is no solution.pdfThere is no solutionSolutionThere is no solution.pdf
There is no solutionSolutionThere is no solution.pdfkaran8801
 
This is a case of allopatric speciation. In this case lice from gori.pdf
This is a case of allopatric speciation. In this case lice from gori.pdfThis is a case of allopatric speciation. In this case lice from gori.pdf
This is a case of allopatric speciation. In this case lice from gori.pdfkaran8801
 
d. 8 The bonding electrons are the electrons taki.pdf
                     d. 8 The bonding electrons are the electrons taki.pdf                     d. 8 The bonding electrons are the electrons taki.pdf
d. 8 The bonding electrons are the electrons taki.pdfkaran8801
 
The genetical changes of single locus are responsible for divergent .pdf
The genetical changes of single locus are responsible for divergent .pdfThe genetical changes of single locus are responsible for divergent .pdf
The genetical changes of single locus are responsible for divergent .pdfkaran8801
 
The corrects answers areThr and Asn are polar amino acids.Isole.pdf
The corrects answers areThr and Asn are polar amino acids.Isole.pdfThe corrects answers areThr and Asn are polar amino acids.Isole.pdf
The corrects answers areThr and Asn are polar amino acids.Isole.pdfkaran8801
 
Since Z4 has an element of order 4,Z4, its a cyclic group of order 4.pdf
Since Z4 has an element of order 4,Z4, its a cyclic group of order 4.pdfSince Z4 has an element of order 4,Z4, its a cyclic group of order 4.pdf
Since Z4 has an element of order 4,Z4, its a cyclic group of order 4.pdfkaran8801
 

More from karan8801 (20)

1. C.HIV is a virus it can be tansmitted through body fluids liks .pdf
1. C.HIV is a virus it can be tansmitted through body fluids liks .pdf1. C.HIV is a virus it can be tansmitted through body fluids liks .pdf
1. C.HIV is a virus it can be tansmitted through body fluids liks .pdf
 
#include iostream #include cstddefusing namespace std;temp.pdf
#include iostream #include cstddefusing namespace std;temp.pdf#include iostream #include cstddefusing namespace std;temp.pdf
#include iostream #include cstddefusing namespace std;temp.pdf
 
omparative historical research is a method of social science that e.pdf
 omparative historical research is a method of social science that e.pdf omparative historical research is a method of social science that e.pdf
omparative historical research is a method of social science that e.pdf
 
1 .D 2.BSolution 1 .D 2.B.pdf
 1 .D 2.BSolution 1 .D 2.B.pdf 1 .D 2.BSolution 1 .D 2.B.pdf
1 .D 2.BSolution 1 .D 2.B.pdf
 
where is it .pdf
                     where is it                                      .pdf                     where is it                                      .pdf
where is it .pdf
 
The name of the reaction is aldol condesation (Cl.pdf
                     The name of the reaction is aldol condesation (Cl.pdf                     The name of the reaction is aldol condesation (Cl.pdf
The name of the reaction is aldol condesation (Cl.pdf
 
Step1 3 moles of H2O react with Cr metal = 2moles.pdf
                     Step1 3 moles of H2O react with Cr metal = 2moles.pdf                     Step1 3 moles of H2O react with Cr metal = 2moles.pdf
Step1 3 moles of H2O react with Cr metal = 2moles.pdf
 
sp2 - sp2 .pdf
                     sp2 - sp2                                       .pdf                     sp2 - sp2                                       .pdf
sp2 - sp2 .pdf
 
Part A neutralizes acids - base Part B produces.pdf
                     Part A neutralizes acids - base Part B produces.pdf                     Part A neutralizes acids - base Part B produces.pdf
Part A neutralizes acids - base Part B produces.pdf
 
Lewis Acid Base Reaction .pdf
                     Lewis Acid Base Reaction                         .pdf                     Lewis Acid Base Reaction                         .pdf
Lewis Acid Base Reaction .pdf
 
KOH ==== K+ (aq) + OH-(aq) [OH-] =9.710^-5 [H.pdf
                     KOH ==== K+ (aq) + OH-(aq)  [OH-] =9.710^-5  [H.pdf                     KOH ==== K+ (aq) + OH-(aq)  [OH-] =9.710^-5  [H.pdf
KOH ==== K+ (aq) + OH-(aq) [OH-] =9.710^-5 [H.pdf
 
It is a reaction for secondary amines .Option 2 i.pdf
                     It is a reaction for secondary amines .Option 2 i.pdf                     It is a reaction for secondary amines .Option 2 i.pdf
It is a reaction for secondary amines .Option 2 i.pdf
 
fluorene is mobile phase and fluorenone is statio.pdf
                     fluorene is mobile phase and fluorenone is statio.pdf                     fluorene is mobile phase and fluorenone is statio.pdf
fluorene is mobile phase and fluorenone is statio.pdf
 
equivalent mass is 27.9 . so Molecular massmole.pdf
                     equivalent mass is 27.9 .  so Molecular massmole.pdf                     equivalent mass is 27.9 .  so Molecular massmole.pdf
equivalent mass is 27.9 . so Molecular massmole.pdf
 
There is no solutionSolutionThere is no solution.pdf
There is no solutionSolutionThere is no solution.pdfThere is no solutionSolutionThere is no solution.pdf
There is no solutionSolutionThere is no solution.pdf
 
This is a case of allopatric speciation. In this case lice from gori.pdf
This is a case of allopatric speciation. In this case lice from gori.pdfThis is a case of allopatric speciation. In this case lice from gori.pdf
This is a case of allopatric speciation. In this case lice from gori.pdf
 
d. 8 The bonding electrons are the electrons taki.pdf
                     d. 8 The bonding electrons are the electrons taki.pdf                     d. 8 The bonding electrons are the electrons taki.pdf
d. 8 The bonding electrons are the electrons taki.pdf
 
The genetical changes of single locus are responsible for divergent .pdf
The genetical changes of single locus are responsible for divergent .pdfThe genetical changes of single locus are responsible for divergent .pdf
The genetical changes of single locus are responsible for divergent .pdf
 
The corrects answers areThr and Asn are polar amino acids.Isole.pdf
The corrects answers areThr and Asn are polar amino acids.Isole.pdfThe corrects answers areThr and Asn are polar amino acids.Isole.pdf
The corrects answers areThr and Asn are polar amino acids.Isole.pdf
 
Since Z4 has an element of order 4,Z4, its a cyclic group of order 4.pdf
Since Z4 has an element of order 4,Z4, its a cyclic group of order 4.pdfSince Z4 has an element of order 4,Z4, its a cyclic group of order 4.pdf
Since Z4 has an element of order 4,Z4, its a cyclic group of order 4.pdf
 

Recently uploaded

An Overview of the Odoo 17 Knowledge App
An Overview of the Odoo 17 Knowledge AppAn Overview of the Odoo 17 Knowledge App
An Overview of the Odoo 17 Knowledge AppCeline George
 
Basic Civil Engineering notes on Transportation Engineering & Modes of Transport
Basic Civil Engineering notes on Transportation Engineering & Modes of TransportBasic Civil Engineering notes on Transportation Engineering & Modes of Transport
Basic Civil Engineering notes on Transportation Engineering & Modes of TransportDenish Jangid
 
How To Create Editable Tree View in Odoo 17
How To Create Editable Tree View in Odoo 17How To Create Editable Tree View in Odoo 17
How To Create Editable Tree View in Odoo 17Celine George
 
The Liver & Gallbladder (Anatomy & Physiology).pptx
The Liver &  Gallbladder (Anatomy & Physiology).pptxThe Liver &  Gallbladder (Anatomy & Physiology).pptx
The Liver & Gallbladder (Anatomy & Physiology).pptxVishal Singh
 
Climbers and Creepers used in landscaping
Climbers and Creepers used in landscapingClimbers and Creepers used in landscaping
Climbers and Creepers used in landscapingDr. M. Kumaresan Hort.
 
Đề tieng anh thpt 2024 danh cho cac ban hoc sinh
Đề tieng anh thpt 2024 danh cho cac ban hoc sinhĐề tieng anh thpt 2024 danh cho cac ban hoc sinh
Đề tieng anh thpt 2024 danh cho cac ban hoc sinhleson0603
 
Major project report on Tata Motors and its marketing strategies
Major project report on Tata Motors and its marketing strategiesMajor project report on Tata Motors and its marketing strategies
Major project report on Tata Motors and its marketing strategiesAmanpreetKaur157993
 
UChicago CMSC 23320 - The Best Commit Messages of 2024
UChicago CMSC 23320 - The Best Commit Messages of 2024UChicago CMSC 23320 - The Best Commit Messages of 2024
UChicago CMSC 23320 - The Best Commit Messages of 2024Borja Sotomayor
 
Graduate Outcomes Presentation Slides - English (v3).pptx
Graduate Outcomes Presentation Slides - English (v3).pptxGraduate Outcomes Presentation Slides - English (v3).pptx
Graduate Outcomes Presentation Slides - English (v3).pptxneillewis46
 
male presentation...pdf.................
male presentation...pdf.................male presentation...pdf.................
male presentation...pdf.................MirzaAbrarBaig5
 
An overview of the various scriptures in Hinduism
An overview of the various scriptures in HinduismAn overview of the various scriptures in Hinduism
An overview of the various scriptures in HinduismDabee Kamal
 
會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文
會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文
會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文中 央社
 
Trauma-Informed Leadership - Five Practical Principles
Trauma-Informed Leadership - Five Practical PrinciplesTrauma-Informed Leadership - Five Practical Principles
Trauma-Informed Leadership - Five Practical PrinciplesPooky Knightsmith
 
Andreas Schleicher presents at the launch of What does child empowerment mean...
Andreas Schleicher presents at the launch of What does child empowerment mean...Andreas Schleicher presents at the launch of What does child empowerment mean...
Andreas Schleicher presents at the launch of What does child empowerment mean...EduSkills OECD
 
TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...
TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...
TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...Nguyen Thanh Tu Collection
 
ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH FORM 50 CÂU TRẮC NGHI...
ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH FORM 50 CÂU TRẮC NGHI...ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH FORM 50 CÂU TRẮC NGHI...
ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH FORM 50 CÂU TRẮC NGHI...Nguyen Thanh Tu Collection
 
The Story of Village Palampur Class 9 Free Study Material PDF
The Story of Village Palampur Class 9 Free Study Material PDFThe Story of Village Palampur Class 9 Free Study Material PDF
The Story of Village Palampur Class 9 Free Study Material PDFVivekanand Anglo Vedic Academy
 
Sternal Fractures & Dislocations - EMGuidewire Radiology Reading Room
Sternal Fractures & Dislocations - EMGuidewire Radiology Reading RoomSternal Fractures & Dislocations - EMGuidewire Radiology Reading Room
Sternal Fractures & Dislocations - EMGuidewire Radiology Reading RoomSean M. Fox
 

Recently uploaded (20)

Mattingly "AI & Prompt Design: Named Entity Recognition"
Mattingly "AI & Prompt Design: Named Entity Recognition"Mattingly "AI & Prompt Design: Named Entity Recognition"
Mattingly "AI & Prompt Design: Named Entity Recognition"
 
An Overview of the Odoo 17 Knowledge App
An Overview of the Odoo 17 Knowledge AppAn Overview of the Odoo 17 Knowledge App
An Overview of the Odoo 17 Knowledge App
 
Basic Civil Engineering notes on Transportation Engineering & Modes of Transport
Basic Civil Engineering notes on Transportation Engineering & Modes of TransportBasic Civil Engineering notes on Transportation Engineering & Modes of Transport
Basic Civil Engineering notes on Transportation Engineering & Modes of Transport
 
How To Create Editable Tree View in Odoo 17
How To Create Editable Tree View in Odoo 17How To Create Editable Tree View in Odoo 17
How To Create Editable Tree View in Odoo 17
 
The Liver & Gallbladder (Anatomy & Physiology).pptx
The Liver &  Gallbladder (Anatomy & Physiology).pptxThe Liver &  Gallbladder (Anatomy & Physiology).pptx
The Liver & Gallbladder (Anatomy & Physiology).pptx
 
Climbers and Creepers used in landscaping
Climbers and Creepers used in landscapingClimbers and Creepers used in landscaping
Climbers and Creepers used in landscaping
 
Đề tieng anh thpt 2024 danh cho cac ban hoc sinh
Đề tieng anh thpt 2024 danh cho cac ban hoc sinhĐề tieng anh thpt 2024 danh cho cac ban hoc sinh
Đề tieng anh thpt 2024 danh cho cac ban hoc sinh
 
Major project report on Tata Motors and its marketing strategies
Major project report on Tata Motors and its marketing strategiesMajor project report on Tata Motors and its marketing strategies
Major project report on Tata Motors and its marketing strategies
 
UChicago CMSC 23320 - The Best Commit Messages of 2024
UChicago CMSC 23320 - The Best Commit Messages of 2024UChicago CMSC 23320 - The Best Commit Messages of 2024
UChicago CMSC 23320 - The Best Commit Messages of 2024
 
Graduate Outcomes Presentation Slides - English (v3).pptx
Graduate Outcomes Presentation Slides - English (v3).pptxGraduate Outcomes Presentation Slides - English (v3).pptx
Graduate Outcomes Presentation Slides - English (v3).pptx
 
male presentation...pdf.................
male presentation...pdf.................male presentation...pdf.................
male presentation...pdf.................
 
An overview of the various scriptures in Hinduism
An overview of the various scriptures in HinduismAn overview of the various scriptures in Hinduism
An overview of the various scriptures in Hinduism
 
會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文
會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文
會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文
 
Mattingly "AI and Prompt Design: LLMs with NER"
Mattingly "AI and Prompt Design: LLMs with NER"Mattingly "AI and Prompt Design: LLMs with NER"
Mattingly "AI and Prompt Design: LLMs with NER"
 
Trauma-Informed Leadership - Five Practical Principles
Trauma-Informed Leadership - Five Practical PrinciplesTrauma-Informed Leadership - Five Practical Principles
Trauma-Informed Leadership - Five Practical Principles
 
Andreas Schleicher presents at the launch of What does child empowerment mean...
Andreas Schleicher presents at the launch of What does child empowerment mean...Andreas Schleicher presents at the launch of What does child empowerment mean...
Andreas Schleicher presents at the launch of What does child empowerment mean...
 
TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...
TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...
TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...
 
ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH FORM 50 CÂU TRẮC NGHI...
ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH FORM 50 CÂU TRẮC NGHI...ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH FORM 50 CÂU TRẮC NGHI...
ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH FORM 50 CÂU TRẮC NGHI...
 
The Story of Village Palampur Class 9 Free Study Material PDF
The Story of Village Palampur Class 9 Free Study Material PDFThe Story of Village Palampur Class 9 Free Study Material PDF
The Story of Village Palampur Class 9 Free Study Material PDF
 
Sternal Fractures & Dislocations - EMGuidewire Radiology Reading Room
Sternal Fractures & Dislocations - EMGuidewire Radiology Reading RoomSternal Fractures & Dislocations - EMGuidewire Radiology Reading Room
Sternal Fractures & Dislocations - EMGuidewire Radiology Reading Room
 

Hi, Please find mu codeimport java.util.Random;public class Sup.pdf

  • 1. Hi, Please find mu code: import java.util.Random; public class SuperDie { private int sides; private Random rand; public SuperDie(){ // Default constructor sides = 6; rand = new Random(); } // Constructor that lets user define number of sides n. public SuperDie(int n){ sides = n; rand = new Random(); } // Constructor that lets user define number of sides n AND provide their own Random object. public SuperDie(int n, Random r){ sides = n; rand = r; } public int getNumSides(){ return sides; } public void setNumSides(int n){ sides = n; } public int roll(){ return rand.nextInt(sides)+1; }
  • 2. } import java.util.*; class MainDie { public static void main (String[] args) { int value, sides; Random rand = new Random(); SuperDie d1 = new SuperDie(); SuperDie d2 = new SuperDie(20); SuperDie d3 = new SuperDie(10,rand); value = d1.roll(); System.out.println ("die1 = " + value); value = d2.roll(); System.out.println ("die2 = " + value); value = d3.roll(); System.out.println ("die3 = " + value); d1.setNumSides(8); System.out.println ("die1 = " + d1.getNumSides()); } } /* Sample Output: die1 = 5 die2 = 5 die3 = 2 die1 = 8 */ Solution Hi, Please find mu code: import java.util.Random;
  • 3. public class SuperDie { private int sides; private Random rand; public SuperDie(){ // Default constructor sides = 6; rand = new Random(); } // Constructor that lets user define number of sides n. public SuperDie(int n){ sides = n; rand = new Random(); } // Constructor that lets user define number of sides n AND provide their own Random object. public SuperDie(int n, Random r){ sides = n; rand = r; } public int getNumSides(){ return sides; } public void setNumSides(int n){ sides = n; } public int roll(){ return rand.nextInt(sides)+1; } } import java.util.*; class MainDie {
  • 4. public static void main (String[] args) { int value, sides; Random rand = new Random(); SuperDie d1 = new SuperDie(); SuperDie d2 = new SuperDie(20); SuperDie d3 = new SuperDie(10,rand); value = d1.roll(); System.out.println ("die1 = " + value); value = d2.roll(); System.out.println ("die2 = " + value); value = d3.roll(); System.out.println ("die3 = " + value); d1.setNumSides(8); System.out.println ("die1 = " + d1.getNumSides()); } } /* Sample Output: die1 = 5 die2 = 5 die3 = 2 die1 = 8 */