From 5a01203177e487c031780a352e9934c49e07b245 Mon Sep 17 00:00:00 2001 From: sgoudham Date: Mon, 19 Oct 2020 23:06:31 +0100 Subject: [PATCH] User can now enter in the number of players --- Personal/Cards/src/CardMain.java | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/Personal/Cards/src/CardMain.java b/Personal/Cards/src/CardMain.java index d93ea0e..b1d6ccc 100644 --- a/Personal/Cards/src/CardMain.java +++ b/Personal/Cards/src/CardMain.java @@ -1,12 +1,26 @@ import java.util.List; +import java.util.Scanner; public class CardMain { public static void main(String[] args) { /* Play Sevens */ Sevens sevens = new Sevens(); sevens.shuffle(); - List allPlayers = sevens.dealCards(4); - sevens.play(allPlayers, 4); + int numOfPlayers = getNumOfPlayers(); + List allPlayers = sevens.dealCards(numOfPlayers); + + sevens.play(allPlayers, numOfPlayers); + + } + + public static int getNumOfPlayers() { + Scanner in = new Scanner(System.in); + System.out.println("Please Enter The Number of Players!"); + while (!in.hasNextInt()) { + in.nextLine(); + System.out.println("Invalid Amount of Players! Try again!"); + } + return in.nextInt(); } }