public void starGame() {
		
		boolean gamestatus = true;
		casesSetup();
		Welcome();
		showCases();
		setladies();
		
		int choice = player.nUser();
		myAmount = briefcase[choice].getAmount();
		briefcase[choice] = null;
		cases--;
	
		while (gamestatus == true) {

			offer = player.offer(turn, briefcase);

			showCases();
			if (cases == 25 || cases == 19 || cases == 14 || cases == 10
					|| cases == 7) {
				for (a = b; a > 0; a--) {
				     int r =  player.Remove(a);
				     briefcase[r] = null;
					System.out.println("\tYou've eliminated "+lady[cases].getName()+" "+lady[cases].getMessage());
					cases--;
				}
				b--;
				turn++;
				System.out.print("\n\tThe Bankers Offer is:  ");
				System.out.printf("$%.2f\n",offer);
				gamestatus = player.gamestatus();
			}else if(cases == 0){
				int r =  player.Remove(1);
			     briefcase[r] = null;
				gamestatus = false;
			} 
			else {
				int r = player.Remove(1);
				briefcase[r] = null;
				System.out.println("\n\tYou've eliminated "+lady[cases].getName()+" "+lady[cases].getMessage());
				cases--;
				System.out.print("\tThe Bankers Offer is: ");
				System.out.printf("$%.2f\n",offer);
				gamestatus = player.gamestatus();
			}
		}
	}

the whole code, specially , the one with the "

if (cases == 25 || cases == 19 || cases == 14 || cases == 10
					|| cases == 7) "

Recommended Answers

All 12 Replies

while(boolean)// its enough no need to check like if condition.

I had a quick look at that code and nothing appears to inefficient. There's certainly nothing wrong with the multiple || in the if.
I would just tidy up the formatting, and a few comments to explain what each part of the code is supposed to achieve, then get on with the next project.

how about the implementation of recursion on the player.remove??

I see no source code for that method, so I can't comment!

I see no source code for that method, so I can't comment!

import java.util.Scanner;

public class Player {

	double offer = 0;

	Scanner input = new Scanner( System.in );

	Banker banker = new Banker();

	public boolean gamestatus() {
		System.out.println("\tis it a deal? or no deal?");
		int temp = input.nextInt();
		if (temp == 1) {
			return false;
		} else {
			return true;
		}
	}

	public double offer(int turn, Briefcase[] cases) {
		offer = 0;
		banker.setOffer(turn, cases);
		offer = banker.getOffer();
		return offer;
	}

	public int nUser(){
		System.out.print("\n\tPlease Select Your Case!: ");
		int nUser = input.nextInt();
		return nUser;
	}
	
	public int Remove(int i){
		
			System.out.println();
			System.out.print("\tPlease remove " + i + " cases: ");
			int nChoice = input.nextInt();
			return nChoice;
	}
   

}

I see no recursion there - it just takes a number from the input and returns it.

I see no recursion there - it just takes a number from the input and returns it.

What if the user inputs a location but it is already nulled? it means that he cannot pick a number twict but the thing is what if? he does? how would I troubleshoot that?

Check if it null, if it is issue an error message and get him to re-try. You'll need a simple while loop...

call the nextInt inside a loop
catch the InputMismatchException that gets thrown, and issue an error message
exit the loop if no exception thrown

call the nextInt inside a loop
catch the InputMismatchException that gets thrown, and issue an error message
exit the loop if no exception thrown

can you check this code for me? how will I do this?

public int Remove(int i, Briefcase c[], String[] m) {

		int nChoice = 0;
		System.out.print("\tPlease remove " + i + " cases: ");
		nChoice = input.nextInt();
		if (c[nChoice] == null) {
			
			System.out.println();
			System.out
					.println("\tYou already entered that digit choose again\n");
			Remove(i, c, m);
			
		} else {
			System.out.println("\tI'm " + m[nChoice]
					+ " You just removed case # " + nChoice);
			System.out.println("\t|" + nChoice + "| contains $"
					+ c[nChoice].getAmount() + "\n");
		}
		return nChoice;
	}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.