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

First, write a class called Dice that simulates a single dice. The Dice class sh

ID: 3543118 • Letter: F

Question

First, write a class called Dice that simulates a single dice. The Dice class should have the

following fields and methods (with these names and caps):

Field/Method Description


Value - The Value field holds the value of the dice


SetValue - The setValue method stores a value in the Value field


GetValue - The getValue method returns the value of the dice


Roll - The Roll method that generates a random number in the range of 1 through 6 for the value of the die


OutputDice - The OutputDice method output the value of the dice as text (e.g. ONE, TWO, THREE, FOUR, FIVE, and SIX)


DrawDice - The DrawDice method draw the dice/an image of the dice (on more than one line using ASCII characters and/or symbols) in the console window (not a dialog box); This method is optional (for 5 extra credit points)


Once you have designed the class, design a program (DiceDemo) that creates two objects/instances of the Dice class to simulate a pair of dice. The program should simulate the rolling of the 2 dice and display their values (using the OutputDice method, and, if you did the extra credit, also using the DrawDice method).

Explanation / Answer


import java.util.ArrayList;

import java.util.Scanner;


public class LargestNumber


{

public static void main(String args[])

{

int ending=0;

ArrayList<Integer> list=new ArrayList<Integer>();/* declare arrylist to store the value*/

int value=1;

while(value>0)

{

System.out.println("Please Enter the number");/* promt the user to give the number*/

Scanner in=new Scanner(System.in);

value=in.nextInt();/* store the entered value */

ending =value;

if(value>0){/* check if the value is greater than zero than only it will store*/

list.add(value);

}

}

int max=0;

for(int i=0;i<list.size();i++)

{

if(list.get(i).intValue()>max)

max=list.get(i).intValue();

}

System.out.println("----------------------------------------");

System.out.println("largest number is=");/* print the largest number*/

System.out.println(max);

}

}