Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I am new at programming, could you check my code and verify if or if not, it looks good and what changes it might need

I am new at programming, could you check my code and verify if or if not, it looks good and what changes it might need to pass UML guidelines. I have notes from class followed by two codes, PairOfDice and Driver.

Notes: from class:

Every source code file should contain a comment header block with information about the contents and author

Each method should have a small comment header block that describes its role

Each header block should have a distinct delimiter on the top and bottom so that the reader can visually scan from one block to the next easily

Put comments on the same line with the code only if the comment applies to the one line of code and fits conveniently on that line, otherwise, put it on a separate line above the line of code it is describing

Avoid use of the /* */ style of comment

Code 1:

//--------------------------------------------------------------------------------------------------

//Driver Class testing dice

//--------------------------------------------------------------------------------------------------

public class Driver

{

public static void main(String args[])

{

//------------------------------------------------------------------------------------------

//Object pair of dice

//------------------------------------------------------------------------------------------

PairOfDice dice = new PairOfDice();

//------------------------------------------------------------------------------------------

//Dice rolling

//------------------------------------------------------------------------------------------

dice.roll();

//------------------------------------------------------------------------------------------

//Print values of two dice

//------------------------------------------------------------------------------------------

System.out.println("Die1 Outcome:" + dice.getDie1());

System.out.println("Die2 Outcome:" + dice.getDie2());

//------------------------------------------------------------------------------------------

//Print sum of two dice

//------------------------------------------------------------------------------------------

System.out.println("Die1 + Die2 Outcome: " + (dice.getDie1() + dice.getDie2()));

//------------------------------------------------------------------------------------------

// set two manual dice

//------------------------------------------------------------------------------------------

dice.setDie1(3);

dice.setDie2(6);

//------------------------------------------------------------------------------------------

//display outcome of manual die1 and die2

//------------------------------------------------------------------------------------------

System.out.println("Die1 Outcome:" + dice.getDie1());

System.out.println("Die2 Outcome:" + dice.getDie2());

//------------------------------------------------------------------------------------------

// display the manual values of two dice and their sum

//------------------------------------------------------------------------------------------

System.out.println("Die1 + Die2 Outcome:" + (dice.getDie1() + dice.getDie2()));

}

}

Code 2:

// Java class that hold pair of dice

//******************************************************************

class PairOfDice

{

//-----------------------------------------------------------

//Public instance variables

//-----------------------------------------------------------

private Die die1;

private Die die2;

//-----------------------------------------------------------

//Constructor

//-----------------------------------------------------------

public PairOfDice()

{

die1 = new Die();

die2 = new Die();

}

//-----------------------------------------------------------

//Setter method that gets face value

//-----------------------------------------------------------

public void setDie1(int val)

{

die1.setFaceValue(val);

}

public void setDie2(int val)

{

die2.setFaceValue(val);

}

//-----------------------------------------------------------

//Getter method that returns value of two dice

//-----------------------------------------------------------

public int getDie1()

{

return die1.getFaceValue();

}

public int getDie2()

{

return die2.getFaceValue();

}

//-----------------------------------------------------------

// Roll two dice method

//-----------------------------------------------------------

public int roll()

{

die1.roll();

die2.roll();

return die2.getFaceValue() + die1.getFaceValue();

}

//------------------------------------------------------------

//Stringto String

//------------------------------------------------------------

public String toString()

{

String result = (die1.toString() + " " + die2.toString());

return result;

}

}

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

New Trends In Databases And Information Systems Adbis 2019 Short Papers Workshops Bbigap Qauca Sembdm Simpda M2p Madeisd And Doctoral Consortium Bled Slovenia September 8 11 2019 Proceedings

Authors: Tatjana Welzer ,Johann Eder ,Vili Podgorelec ,Robert Wrembel ,Mirjana Ivanovic ,Johann Gamper ,Mikolaj Morzy ,Theodoros Tzouramanis ,Jerome Darmont

1st Edition

3030302776, 978-3030302771

More Books

Students also viewed these Databases questions

Question

How can customer service act as a competitive weapon?

Answered: 1 week ago

Question

6. Are my sources reliable?

Answered: 1 week ago

Question

5. Are my sources compelling?

Answered: 1 week ago