Question: make a pseudocode for the new code program and answer PART B original code import java.util.Scanner; public class Main{ public static void main(String[] args){ Scanner

 make a pseudocode for the new code program and  answer PART B



original code


import java.util.Scanner; public class Main{ public static void main(String[] args){ Scanner scan = new Scanner(System.in); final int ROUND = 10; int user, genInput(), score = 0; for (int r=1; r

public static int getInput(Scanner input){ // TODO: prompt user to enter a number between 1 and 52, // then validate and return it }

public static int genInput(){ //TODO : generate and return a random integer number between 1 and 52 }

public static void printRoundInfo(int r, int user, int comp){ System.out.print("R" + r + ": "); System.out.print("Computer card is " + getRank(comp) + " of " + getSuit(comp)); System.out.println("; User card is " + getRank(user) + " of " + getSuit(user)); }

public static int printRoundResult(int score, int user, int comp){ int winner = findWinner(user, comp); switch (winner){ case 0 : score *=2; System.out.println("It's tie - user score is " + score); break; case 1 : score +=1; System.out.println("User wins - user score is " + score); break; default : System.out.println("Computer wins - user score is " + score); break; } return score; }

public static int findWinner(int user, int comp){ //TODO: find the winner and return -1, 1 or 0 if it is tie, //user wins or computer wins }

// add more methods if needed. }


NEW CODE


import java.util.Scanner; import java.lang.Math; public class Main{ public static void main(String[] args){ Scanner scan = new Scanner(System.in); final int ROUND = 10; int user, comp, score = 0; for (int r=1; r 52){ System.out.println("Invalid card input. Please try again."); System.out.print("Enter your card: "); userCard = input.nextInt(); } return userCard; }


public static int genInput(){ return (int)(Math.random()*52) + 1;

}

public static void printRoundInfo(int r, int user, int comp){ System.out.print("R" + r + ": "); System.out.print("Computer card is " + getRank(comp) + " of " + getSuit(comp)); System.out.println("; User card is " + getRank(user) + " of " + getSuit(user));

}

public static int printRoundResult(int score, int user, int comp){ int winner = findWinner(user, comp); switch (winner){ case 0 : score *=2; System.out.println("It's tie - user score is " + score); break; case 1 : score +=1; System.out.println("User wins - user score is " + score); break; default : System.out.println("Computer wins - user score is " + score); break; } return score;

}

/** * Calculates and returns the Winner of the round * @param user - The card selected by the user * comp - The card selected by the computer * @return 0, if there is a tie, * 1, if user wins, * -1, if computer wins */ public static int findWinner(int user, int comp){

int userCardRank = user % 13; if(userCardRank == 0){ userCardRank = 13; } int compCardRank = comp % 13; if(compCardRank == 0){ compCardRank = 13; } if(compCardRank == userCardRank){ return 0; } if(userCardRank > compCardRank){ return 1; } return -1; }

/** * Calculates and returns the rank of given card * @param card - The card whose Rank is to be found * @return The Rank of the card */ public static String getRank(int card){ int rank = card % 13; if(rank == 0){ return "King"; } if(rank == 1){ return "Ace"; } if(rank > 1 && rank

}

R4: Computer card is 9 of Diamonds; User card is 3 ofDiamonds Computer wins-user score is 4 ... ==> Enter your card: 18

R4: Computer card is 9 of Diamonds; User card is 3 of Diamonds Computer wins-user score is 4 ... ==> Enter your card: 18 R10: Computer card is 4 of Spades; User card is 5 of Diamonds ==> User wins - user score is 19 End of Game! Part B [10 marks]: 1- In the main method to call genInput method use the name of class and dot operator, i.e: replace comp = genInput (); (line8) with comp = WarGame.genInput (); and compile and run the program. What happens? 2- Now remove static modifier in the getInput method's header and compile the program. What happens? Justify the result. Submission Make a folder containing your source code (WarGame.java file: Your answer to Part A) and external documentation, zip the folder and submit the zip file to D2L. Check Lab Guide (section 3) to find out more details about your submission and grading.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock

Main Initialize ROUND 10 user comp score 0 For r 1 to ROUND comp genInput user getInput printRoundIn... View full answer

blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!