Thursday, October 22, 2020

 Write a JAVA program of a player class || JAVA program on cricket


Problem Statements:

1. Define a class player having a player name, player_id, team, player type, Run rate,no-of-centuries,no-of-wickets, and method print_info(). 

2. Define two constructors for creating objects like Batsman, Bowler having fields like innings_played, run rate, wickets taken, score, etc. 

3. Create methods update_stats(), Comp_stats(Player ob1,Player ob2)-to compare 2 player & return higher one(performance is determined on the basis of score made (in-case of batsman), wickets taken (in-case of bowler)). 

4. Add method overloading for update_stats() method and print_info() method. Use objects as parameters to the methods. 

5. Use static for generating player-id, final for the team name, and this for constructor chaining. 

6.Use array of objects to store players, and print the top scorer batsman and highest wicket-taker among all.


CODE :

import java.util.Scanner;
public class Player
{
    String player_name;
    int player_id;
    String player_type;
    double strike_rate;
    double economy_rate;
    int player_score;
    int no_centuries;
    int no_wickets;
    static int count=1;
    static int max_score=0;
    static int max_wickets=0;
    static String max_batsman;
    static String max_bowler;
    Player(){
        player_id=count++;
    }
    Player(String name,String type,double rate,int centuries,int score){
        this.player_name=name;
        this.player_type=type;
        this.player_score=score;
        this.strike_rate=rate;
        this.no_centuries=centuries;
    }
    Player(String name,String type,int wickets, double ec_rate){
        this.player_name=name;
        this.player_type=type;
        this.no_wickets=wickets;
        this.economy_rate=ec_rate;
    }
    static void  comp_stats(Player obj1,Player obj2){
        if(!((obj1.player_type).equalsIgnoreCase(obj2.player_type))){
            System.out.println("Different type of players cannot be compared");
        }
        else if((obj1.player_type).equalsIgnoreCase("Batsman") &&
        (obj2.player_type).equalsIgnoreCase("Batsman")){
            if((obj1.player_score)>obj2.player_score){
                System.out.println(obj1.player_name+" has better performance than "+obj2.player_name);
            }
             else if(obj1.strike_rate==obj2.strike_rate){
                System.out.println(obj1.player_name+" has same performance as that of "+obj2.player_name);
            }
            else{
                System.out.println(obj2.player_name+" has better performance than "+obj1.player_name);
            }
        }
        else{
            if((obj1.no_wickets)>obj2.no_wickets){
                System.out.println(obj1.player_name+" has better performance than "+obj2.player_name);
            }
            else if(obj1.no_wickets==obj2.no_wickets){
                System.out.println(obj1.player_name+" has same performance as that of "+obj2.player_name);
            }
            else{
                System.out.println(obj2.player_name+" has better performance than "+obj1.player_name);
            }
        }
        System.out.println("------------------------------------------------");
    }
    static void update_stats(Player obj,int score,double rate, int centuries){
        obj.player_score=score;
        obj.strike_rate=rate;
        obj.no_centuries=centuries;
        System.out.println("Player info updated");
        System.out.println("------------------------------------------------");
    }
    static void update_stats(Player obj,int wickets,double ec_rate){
        obj.no_wickets=wickets;
        obj.economy_rate=ec_rate;
        System.out.println("Player info updated");
         System.out.println("------------------------------------------------");
    }
    void print_info(int i, int ent){
        System.out.println("Player name: "+player_name);
        System.out.println("Player id: "+player_id);
        System.out.println("Player type: "+player_type);
        if((player_type).equalsIgnoreCase("Bowler")){
            System.out.println("No of wickets taken: "+no_wickets);
            if(no_wickets>=max_wickets){
                max_wickets=no_wickets;
                max_bowler=player_name;
            }
        }
        else{
            System.out.println("Runrate = "+strike_rate);
            System.out.println("No. of centuries hit = "+no_centuries);
            System.out.println("Score = "+player_score);
            if(player_score>=max_score){
                max_score=player_score;
                max_batsman=player_name;
            }
        }
        System.out.println("------------------------------------------------");
        if(i==(ent-1)){
             System.out.println("Top Scoring Batsman "+max_batsman+" with a score of "+max_score);
            System.out.println("Top Scoring Bowler "+max_bowler+" with number of wickets "+max_wickets);
            System.out.println("------------------------------------------------");
        }
    }
    public static void main(String[] args)
    {
        Scanner in = new Scanner(System.in);
        System.out.print("Enter number of entries: ");
        int ent=in.nextInt();
        System.out.println("------------------------------------------------");
        Player arr[]=new Player[ent];
        System.out.print("Enter team name: ");
        final String team_name = in.next();
        System.out.println("------------------------------------------------");
        for(int i=0;i<ent;i++){
            System.out.print("Enter player"+(i+1)+" name: ");
            String name = in.next();
            System.out.print("Enter player type: ");
            String type = in.next();
            if(type.equalsIgnoreCase("Bowler")){
            System.out.print("Enter number of wickets: ");
            int wickets = in.nextInt();
            System.out.print("Enter Economy Rate: ");
            double ec_rate=in.nextDouble();
            arr[i]=new Player(name,type,wickets,ec_rate);
            }
            else{
            System.out.print("Enter run rate: ");
            double rate = in.nextDouble();
            System.out.print("Enter number of centuries: ");
            int centuries = in.nextInt();
            System.out.print("Enter score: ");
            int score=in.nextInt();   
            arr[i]=new Player(name,type,rate,centuries,score);
            }
            System.out.println("------------------------------------------------");
        }
        System.out.println("Information Stored!");
        System.out.println("------------------------------------------------");
        int n=1;
        while(n!=0){
            System.out.println("Press 1 to update any player, 2 to compare any two player,3 to print all player data, 4 to exit");
            n=in.nextInt();
            switch(n){
                case 1:
                   System.out.print("Enter player name whose info you want to update: ");
                   String upname=in.next();
                   int i;
                   for(i=0;i<ent;i++){
                       if((arr[i].player_name).equalsIgnoreCase(upname)){
                           if((arr[i].player_type).equalsIgnoreCase("Batsman")){
                               System.out.print("Enter new score: ");
                               int newscore=in.nextInt();
                               System.out.print("Enter new runrate: ");
                               double newrate=in.nextDouble();
                               System.out.print("Enter new number of centuries: ");
                               int newcenturies=in.nextInt();
                               update_stats(arr[i],newscore,newrate,newcenturies);
                               break;
                            }
                            else{
                                System.out.print("Enter new number of wickets: ");
                               int newwickets=in.nextInt();
                               System.out.print("Enter new Economy rate: ");
                               double new_ec_rate=in.nextDouble();
                               update_stats(arr[i],newwickets,new_ec_rate);
                               break;
                            }
                       }
                   }
                   if(i==ent){
                       System.out.println("Player record not found");
                   }
                   break;
                case 2:
                    System.out.println("Enter two player name whose info you want to compare: ");
                    String player1=in.next();
                    String player2=in.next();
                    int pos1=0;
                    int pos2=0;
                    for(i=0;i<ent;i++){
                           if((arr[i].player_name).equalsIgnoreCase(player1)){
                               pos1=i;
                           }
                           else if((arr[i].player_name).equalsIgnoreCase(player2)){
                               pos2=i;
                           }
                    }
                    comp_stats(arr[pos1],arr[pos2]);
                    break;
                case 3:
                    System.out.println("TEAM NAME:"+team_name);
                    for(i=0;i<ent;i++){
                        arr[i].print_info(i,ent);
                    }
                    break;
                case 4:
                    System.out.println("\nExit!");
                    n=0;
                    break;
                default:
                    System.out.println("Wrong Choice!");
                    System.out.println("------------------------------------------------");
            }
        }
    }
}


OUTPUT :

    




THANK  YOU.

~   D Sir











Tuesday, August 18, 2020

How to fix npm create-react-app stuck at 'found 0 vulnerabilities'

 How to fix npm create-react-app stuck at 'found 0 vulnerabilities'

                                              core.js Postinstall error

I started learning React recently from youtube, channel name: Thapa Technical. So as I was instructed to install Node.js, I downloaded and installed it (64-bit). I ran npx create-react-app app which is responsible for creating a react app with boilerplate required.

PROBLEM FACE : 

Some file was missing in package.jason. Also public , src and other foldwers and files were not present in the directory. i search so many stuffs in youtube and google. Then after a week , i got a solution and do that. After done that solution, my problem was solved.

The problem is : 

SO, The Solution is that in following steps :

1. Uninstall nodejs.x64 bit and download nodejs.x32 bit and install it.

Now Run the following commands as per your directory :
    2. npm rm -g create-react-app
    3. npm install -g create-react-app
    4. npx create-react-app my-app

Doing that solved my problem.

Happy React , Happy Hacking !!

Thank You.

Thursday, August 13, 2020

How to work on Xampp for the first time using CMD

How to work on Xampp for the first time using CMD


1. Go to c:/xampp/MySQL/bin/MySQL
2. now as per given in the below figure to start the server :



Note:  You should first start the Apache and Mysql server in the Xampp application.

3. create Database :


4. If you want to delete any database as : 


5. After establishing database, we have to use the database as follows : 

6. Now we have to select the database as we want : 


7. we have to create the table format to maintain the databases:


8. How to show our tables in database :


Wednesday, August 12, 2020

How to solve Apache error in Xampp control panel

 How to solve Apache error in Xampp control panel






Here, The problem is that we have not able to start the apache server because of some error. we can read the error is the port i.e. 80 and 443 is not able to run because that port is used by other applications ( Vmware workstation - in my pc ). 

So, we have two option to solve this error :

1. We can uninstall the app which is using the same port.
2. We can change the port in Xampp in option configure->service and port settings.


Hopely, the Problem is solved.

Thank You.

 Write a JAVA program of a player class || JAVA program on cricket Problem Statements: 1. Define a class player having a player name, player...