Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8333175
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T02:55:55+00:00 2026-06-09T02:55:55+00:00

classMain.java public class classMain { public static classCall classCallObject; public static void main(String[] args)

  • 0

classMain.java

public class classMain
{
  public static classCall classCallObject;

  public static void main(String[] args)
  {
    classCallObject = new classCall();
    classCallObject.calling();
  }
}

classCall.java

import java.awt.CardLayout;
import java.awt.FlowLayout;
import javax.swing.JFrame;
import javax.swing.JPanel;

public class classCall extends JFrame
{
  public JFrame frame;
  public JPanel cards;
  public CardLayout cardlayout = new CardLayout();
  public static classEngine engObject = new classEngine();

  public void calling()
  {
    frame = new JFrame();
    frame.setVisible(true);
    frame.setLayout(new FlowLayout());
    frame.setTitle("Cricket Game 2012");
    frame.setSize(1024, 740);
    frame.setResizable(false);
    frame.setDefaultCloseOperation(EXIT_ON_CLOSE);         
    gui guiObject = new gui();
    frame.add(guiObject.totalScore);
  }
}

gui.java

import java.awt.FlowLayout;
import javax.swing.JFrame;
import javax.swing.JLabel;

public class gui extends JFrame
{
  public JLabel totalScore;

  public gui()
  {
    classCall.engObject.gameEngine();
    totalScore = new JLabel(String.format("Total is %d - %d", classCall.engObject.getTotal(), classCall.engObject.getWickets()));
    totalScore.setLayout(new FlowLayout());
  }
}

classEngine.java

import java.util.Random;

public class classEngine
{

  public int[][] Overs = new int[20][6];
  public static int total=0;
  public static int wickets=0;

  public void gameEngine()
  {
    for (int over=1; over<Overs.length;over++)
    {
      for (int ball=1; ball<Overs[over].length; ball++)
      {
              Overs[over][ball] = batsmanNormalNormal();
              total=total + Overs[over][ball];
      }
    }
  }

  public int batsmanNormalNormal()
  {      
    int x=0;
    int randomNumber = 0;
    Random randomObject = new Random();
    randomNumber=randomObject.nextInt(100)+1;

    if (randomNumber<=1 && randomNumber>=10)
      x=4;
    else if (randomNumber<=11 && randomNumber>=13)
    {
      x=0;
      wickets++;
    }      
    else if (randomNumber<=14 && randomNumber>=17)
      x=1;
    else if (randomNumber<=18 && randomNumber>=19)
      x=1;
    else if (randomNumber<=20 && randomNumber>=30)
      x=2;
    else if (randomNumber<=31 && randomNumber>=55)
      x=1;
    else if (randomNumber<=56 && randomNumber>=96)
      x=0;
    else if (randomNumber<=97 && randomNumber>=98)
      x=6;
    else if (randomNumber<=99 && randomNumber>=100)
      x=3;

    return x;

  }

  public int getTotal()
  {
    return total;
  }

  public int getWickets()
  {
    return wickets;
  }
}

I have tried to create a java code which stimulates the game of cricket.
I know many of you may not know this game. Basically, what I want to do is randomly generate numbers (weighted probability – not completely random) and add them to a static int called total.
I want to display the Total using the JLabel.

But for some reason, the total doesnt update. It says 0-0.
It should give other results like 140 or 200 because i have coded it to add randomly generated numbers to the total approx. 120 times.

I think I may be missing something.

I think it is something apparent which my blank brain cannot read atm.
Can somebody plz help me with this?
Thanks

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T02:55:58+00:00Added an answer on June 9, 2026 at 2:55 am

    Make sure to check that greater than and lesser than signs are at the right place.

    In this program the if and else if statements never get executed because the conditions that I have put there are never true!

    Thats why the total score is not updated.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

package GC; import java.util.Scanner; public class main { public static void main(String args[]) {
import java.util.HashMap; import java.util.Map; public class Main { public static void main(String[] args) {
public class Main { public static void main(String[] args){ Class2 class2Object = new Class2();
In this Java code: public class Main { public static void main(String[] args) {
public class Main { public static void main(String args[]) { List list = new
public class Main { public static void main (String args[]) { int nums[]= {2,
Given this code : package db; import java.sql.*; public class Main { public static
I have a really simple Java code: public class Main { public static void
I have a static class (Foo) and a main class (Main) See Main.java: public
Right now I have two .java files. The Main.java: public class Main { static

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.