SlideShare a Scribd company logo
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

PDF
1. C.HIV is a virus it can be tansmitted through body fluids liks .pdf
PDF
#include iostream #include cstddefusing namespace std;temp.pdf
PDF
omparative historical research is a method of social science that e.pdf
PDF
1 .D 2.BSolution 1 .D 2.B.pdf
PDF
where is it .pdf
PDF
The name of the reaction is aldol condesation (Cl.pdf
PDF
Step1 3 moles of H2O react with Cr metal = 2moles.pdf
PDF
sp2 - sp2 .pdf
1. C.HIV is a virus it can be tansmitted through body fluids liks .pdf
#include iostream #include cstddefusing namespace std;temp.pdf
omparative historical research is a method of social science that e.pdf
1 .D 2.BSolution 1 .D 2.B.pdf
where is it .pdf
The name of the reaction is aldol condesation (Cl.pdf
Step1 3 moles of H2O react with Cr metal = 2moles.pdf
sp2 - sp2 .pdf

More from karan8801 (20)

PDF
Part A neutralizes acids - base Part B produces.pdf
PDF
Lewis Acid Base Reaction .pdf
PDF
KOH ==== K+ (aq) + OH-(aq) [OH-] =9.710^-5 [H.pdf
PDF
It is a reaction for secondary amines .Option 2 i.pdf
PDF
fluorene is mobile phase and fluorenone is statio.pdf
PDF
equivalent mass is 27.9 . so Molecular massmole.pdf
PDF
There is no solutionSolutionThere is no solution.pdf
PDF
This is a case of allopatric speciation. In this case lice from gori.pdf
PDF
d. 8 The bonding electrons are the electrons taki.pdf
PDF
The genetical changes of single locus are responsible for divergent .pdf
PDF
The corrects answers areThr and Asn are polar amino acids.Isole.pdf
PDF
Since Z4 has an element of order 4,Z4, its a cyclic group of order 4.pdf
PDF
selected palntsxerophyte verus mesophyte========================.pdf
PDF
Ruth & AssociatesIncome StatementFor the Year Ended December 31,.pdf
PDF
P(all same) = 6(16)^5 = 16^4 = 11296P(all Different) = 16 1.pdf
PDF
Part A blood solutes, swell Part B blood osmotic pressure, blood.pdf
PDF
no of units producedno of units of component A requiredprice per.pdf
PDF
benzene is less reactive than toluene towardselec.pdf
PDF
Net NonOperating Obligations = Non Operating Liabilities - Non Opera.pdf
PDF
Malware aimed at mobile devices becauseSolutionMalware aimed .pdf
Part A neutralizes acids - base Part B produces.pdf
Lewis Acid Base Reaction .pdf
KOH ==== K+ (aq) + OH-(aq) [OH-] =9.710^-5 [H.pdf
It is a reaction for secondary amines .Option 2 i.pdf
fluorene is mobile phase and fluorenone is statio.pdf
equivalent mass is 27.9 . so Molecular massmole.pdf
There is no solutionSolutionThere is no solution.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
The genetical changes of single locus are responsible for divergent .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
selected palntsxerophyte verus mesophyte========================.pdf
Ruth & AssociatesIncome StatementFor the Year Ended December 31,.pdf
P(all same) = 6(16)^5 = 16^4 = 11296P(all Different) = 16 1.pdf
Part A blood solutes, swell Part B blood osmotic pressure, blood.pdf
no of units producedno of units of component A requiredprice per.pdf
benzene is less reactive than toluene towardselec.pdf
Net NonOperating Obligations = Non Operating Liabilities - Non Opera.pdf
Malware aimed at mobile devices becauseSolutionMalware aimed .pdf

Recently uploaded (20)

PPTX
Cell Types and Its function , kingdom of life
PPTX
202450812 BayCHI UCSC-SV 20250812 v17.pptx
PPTX
Onco Emergencies - Spinal cord compression Superior vena cava syndrome Febr...
PDF
advance database management system book.pdf
PDF
medical_surgical_nursing_10th_edition_ignatavicius_TEST_BANK_pdf.pdf
PDF
RMMM.pdf make it easy to upload and study
PDF
LNK 2025 (2).pdf MWEHEHEHEHEHEHEHEHEHEHE
PDF
GENETICS IN BIOLOGY IN SECONDARY LEVEL FORM 3
PDF
Classroom Observation Tools for Teachers
PPTX
Chinmaya Tiranga Azadi Quiz (Class 7-8 )
PDF
IGGE1 Understanding the Self1234567891011
PDF
ChatGPT for Dummies - Pam Baker Ccesa007.pdf
PDF
1_English_Language_Set_2.pdf probationary
PDF
Empowerment Technology for Senior High School Guide
PDF
Paper A Mock Exam 9_ Attempt review.pdf.
PDF
Weekly quiz Compilation Jan -July 25.pdf
PDF
SOIL: Factor, Horizon, Process, Classification, Degradation, Conservation
PPTX
A powerpoint presentation on the Revised K-10 Science Shaping Paper
PDF
RTP_AR_KS1_Tutor's Guide_English [FOR REPRODUCTION].pdf
PDF
A systematic review of self-coping strategies used by university students to ...
Cell Types and Its function , kingdom of life
202450812 BayCHI UCSC-SV 20250812 v17.pptx
Onco Emergencies - Spinal cord compression Superior vena cava syndrome Febr...
advance database management system book.pdf
medical_surgical_nursing_10th_edition_ignatavicius_TEST_BANK_pdf.pdf
RMMM.pdf make it easy to upload and study
LNK 2025 (2).pdf MWEHEHEHEHEHEHEHEHEHEHE
GENETICS IN BIOLOGY IN SECONDARY LEVEL FORM 3
Classroom Observation Tools for Teachers
Chinmaya Tiranga Azadi Quiz (Class 7-8 )
IGGE1 Understanding the Self1234567891011
ChatGPT for Dummies - Pam Baker Ccesa007.pdf
1_English_Language_Set_2.pdf probationary
Empowerment Technology for Senior High School Guide
Paper A Mock Exam 9_ Attempt review.pdf.
Weekly quiz Compilation Jan -July 25.pdf
SOIL: Factor, Horizon, Process, Classification, Degradation, Conservation
A powerpoint presentation on the Revised K-10 Science Shaping Paper
RTP_AR_KS1_Tutor's Guide_English [FOR REPRODUCTION].pdf
A systematic review of self-coping strategies used by university students to ...

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 */