Computer Science, asked by ishanganguly195, 6 months ago

Write a program in Java-A dice game is played between 2 players. Each player throws a dice unless his score adds upto 20. The player with the minimum number of throws is declared winner. Define a class Game with the given specifications: DATA MEMBERS- i) String name1, name2;// Name of players, (ii) int p_no1,p_no2; // Player numbers MEMBER METHODS: i)void accept()- To accept the details of the players, (ii) void compute() - To compute the results depending on the number of throws, (iii) void display()- to display the details of the result. Write a main method to create object of a class and call the above methods.

Answers

Answered by anamtaany31
6

Answer:

import java .util.*;

class Sample{

public static void main(String args[ ])

{

Scanner sc = new Scannet (Sysyem.in);

String name1 ,name2;int p_no1,p_no2,res;

S.o.pln("Name of first playet :");

name1=sc. nectLine( );

S.o.pln ("Name of second line:");

name2=sc.nextLine( );

S.o.pln ("Player number:");

p_no1=sc.nextInt( );

S.o.pln("Player number second:");

p_n2=sc.nextInt( );

void accept ( )

{

S.o.pln ("Name of first player="+name1);

S.o.pln ("Name of second player="+name2);

S.o.pln("Player number="+p_no1);

S.o.pl("Player no second="+p_no2);

}

void compute( )

{

if ( res= =name2);

else

res==name1;

}

void display( )

{

S.o.pln("Winner:"+res);

}

public void main( )

{

sc.accept( );

sc.compute( );

sc.display( );

}

}

}

Similar questions