Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Solve the following programming problems using object-oriented programming in Ja

ID: 3801144 • Letter: S

Question

Solve the following programming problems using object-oriented programming in Java. Provide the problem statement, code and screenshot of the test run.

Write a program that “throws two (2) dice” by using the Random class. The values generated should go from 1 to 6. In a 6 x 6 multidimensional array, increment the value of each data cell depending on the dice values to determine the frequency of each dice throw. Make 3,000,000 dice throws. Finally, print the content of each data cell.

Create a class named Circle with:Data fields:

Radius

Default and custom constructors

Methods

Set radius

Get radius

Get circumference

Get area

Create three different instances of the circle with different values and store them in an ArrayList<Circle>. Test each method of the Circle class through the ArrayList.

Explanation / Answer

//======================= DiceThrow.java ==========================//

import java.util.Random;

public class DiceThrow {
   static int data[][];
   public static void main(String[] args) {
       data = new int[6][6];
       Dice dice1 = new Dice();
       Dice dice2 = new Dice();
       for(long i=0; i<3000000; i++){
           int dice1Face = dice1.throwDice();
           int dice2Face = dice2.throwDice();
           data[dice1Face-1][dice2Face-1]++;
       }
       System.out.println("======================== Frequency =========================");
       System.out.println("============================================================");
       for(int i=0; i<6; i++){
           for(int j=0; j<6; j++){
               System.out.print(" "+data[i][j]);
           }
           System.out.println(" ");
       }
       System.out.println("============================================================");
   }

}

class Dice{
   Random rand;
   public Dice(){
       rand = new Random();
   }
   public int throwDice(){
       int face = Math.abs(rand.nextInt())%6;
       return face+1;
   }
}


//====================== End of DiceThrow.java ==========================

//======================= CircleTest.java ===========================//

class Circle {
   private double radius;
   final private double PI = 22.0d/7.0d;
   public Circle() {
      
   }
   public Circle(double r) {
       radius = r;
   }
   public double getArea() {
       return PI*radius*radius;
   }
  
   public double perimeter() {
       return 2.0*PI*radius;
   }
   public double getRadius() {
       return radius;
   }
   public void setRadius(double radius) {
       this.radius = radius;
   }
   public double getPI() {
       return PI;
   }
   public String toString(){
       return " Radius :"+radius+" , Area : "+getArea()+" ";
   }
}

import java.util.ArrayList;
import java.util.List;

public class CircleTest {

   public static void main(String[] args) {
       List<Circle> circlelist = new ArrayList<>();
      
       circlelist.add(new Circle(5));
       circlelist.add(new Circle(10));
       circlelist.add(new Circle(15));
      
       for(int i=0; i<circlelist.size(); i++){
           System.out.println("Circle "+i+" : "+circlelist.get(i));
       }
   }

}

//====================== End of CircleTest.java ========================//

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote