I would like to ask assistance how I can retrieve all the scores every game. And how to add the points by not incrementing game 1 and game 2 and so on.. THank you...

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package simpleblackjackproj;

import java.util.Scanner;

/**
 *
 * @author ICA
 */
public class SimpleBlackJackProj {
    private static String choice;
    private static int pointsPlayer;
    private static int pointsComputer;

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {

        int i = 0, j=1;
        Scanner scan = new Scanner(System.in);
        blackjack blackjack = new blackjack();

      
        System.out.println("WELCOME TO THE BLACKJACK GAME!!!");

do{
    System.out.print("Do you want to start a deal? Y/N: ");
    choice = scan.nextLine();

        if(choice.equalsIgnoreCase("Y"))
        {
            System.out.println("\n~~~~~~~~~~~~~~~~~~ GAME  "+j+ " ~~~~~~~~~~~~~~~~~~ " );
            j++;

            //your cards
            System.out.println("----------------------------------------");
            System.out.println("~~Your Cards~~");

            for (i = 1; i <= 3; i++){
            System.out.println("Card "+i+ ": " );
            blackjack.playerPoints(blackjack.randomCard());
            pointsPlayer += blackjack.points;
            }

            //pc's cards
            System.out.println("----------------------------------------");
            System.out.println("~~Computer's Cards~~");

            for (i = 1; i <= 3; i++){
            System.out.println("Card "+i+ ": " );
            blackjack.playerPoints(blackjack.randomCard());
            pointsComputer += blackjack.points;
            }
        }
    
        System.out.printf("\nYou have " + pointsPlayer + " points.");
        System.out.printf("\nComputer have " + pointsComputer+ " points.\n");
        

        if(pointsPlayer>=21 && pointsPlayer<pointsComputer){
            System.out.printf("\nYou won!!!\n");
        }
        else if(pointsPlayer<=21 && pointsPlayer > pointsComputer){
            System.out.printf("\nYou won!!!\n");
        }
        else if(pointsPlayer<=21 && pointsComputer>21){
            System.out.printf("\nYou won!!!\n");
        }
        else if(pointsPlayer == pointsComputer){
            System.out.printf("\nDRAW!!!\n");
        }
        else{
            System.out.printf("\nYou lose!!!\n");
        }


}while(choice.equalsIgnoreCase("Y"));

        if(choice.equalsIgnoreCase("N")){
            int k=0;
            for(k=0; k<=0;k++){
            System.out.println("\n====Your Game History====");
            System.out.println("\nGame "+j+ ". Your Score is "+pointsPlayer);
            }
        }
    
    }
}




/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package simpleblackjackproj;
import java.util.Random;

/**
 *
 * @author ICA
 */
class blackjack { 
    
    String rCard;
    int points;
    
    String[ ] cards = {"Ace","King","Queen","Jack","10","9","8","7","6", "5", "4", "3", "2"};

    //random card method
    String randomCard() {  
        Random r = new Random();
        rCard = cards[r.nextInt(13)];
        System.out.println(rCard);
        return rCard;
    }
    
    int playerPoints(String card)
    {
		if(card.equals("Ace")) {
                    return points = 11;
                    
                }
		else if(card.equals("King")) {
			return points = 10;	
		}
		else if(card.equals("Queen")) {
			return points = 10;
		}
		else if(card.equals("Jack")) {
			return points = 10;
		}
		else if(card.equals("10")) {
			return points = 10;	
		}
		else if(card.equals("9")) {
			return points = 9;
		}
		else if(card.equals("8")) {
			return points = 8;
		}
		else if(card.equals("7")) {
			return points = 7;
		}
		else if(card.equals("6")) {
			return points = 6;
		}
		else if(card.equals("5")) {
			return points = 5;
		}
		else if(card.equals("4")) {
			return points = 4;	
		}
		else if(card.equals("3")) {
			return points = 3;
		}
		else {
			return points = 2;
		}
    }
}

Record it in external file, associate player name with score and update score for "the" player

iam sorry am not sure how to do it

am not sure how to record in an external file.. am still practicing java... i have already associated a player name.. i have pointsComputer and pointsPlayer, points are associated in them... am dunno why the points keeps on incrementing whenever i start a new game and display the points before proceeding to a next game.

If you want to keep your score somewhere permanently then you have to store it somewhere or it will be lost once you close your application. Your two options are either to work with files or with database. Simple file example can be used from Oracle Java tutorial - Reading, Writing, and Creating Files

tnx much.. thats something new :)
BTW do you mean that the scores are lost after i select a next game?

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.