Results 1 to 9 of 9
  1. #1
    Fisty's Avatar
    Fisty is offline Member
    Join Date
    Mar 2012
    Posts
    5
    Rep Power
    0

    Default Car cricket program

    New question when writing a program for say car cricket how would i show that
    9 ot of 10 vehicles should be a car?

  2. #2
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    16,571
    Rep Power
    23

    Default Re: javac is not recognized as an internal or external command error

    Please start a new thread for a new topic.
    If you don't understand my response, don't ignore it, ask a question.

  3. #3
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,189
    Rep Power
    19

    Default Re: Car cricket program

    Agreed. Thread split from javac is not recognized as an internal or external command error

    In future, whenever you have a question start your own thread -- they're free. Don't wake the dead, as you did this time, and don't attempt to hijack another poster's thread with your question.

    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  4. #4
    Fisty's Avatar
    Fisty is offline Member
    Join Date
    Mar 2012
    Posts
    5
    Rep Power
    0

    Default Re: Car cricket program

    okay my bad.
    Well can anyone answer my question now?

    If you are writing a program, such as a roll of the die how do you make it so that a number comes up a certain percent of the time compared to another?
    for example a 4 comes up 33% of the time, how would you write it in code?

  5. #5
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    16,571
    Rep Power
    23

    Default Re: Car cricket program

    Do you have the algorithm for that? Given an algorithm we could help you write the code in java.
    If you don't understand my response, don't ignore it, ask a question.

  6. #6
    Fisty's Avatar
    Fisty is offline Member
    Join Date
    Mar 2012
    Posts
    5
    Rep Power
    0

    Default Re: Car cricket program

    /*
    @author = Joshua Fist
    @version 1 (March 2012)
    Assignment 1 for KXT101 (car cricket)
    */

    import java.util.Scanner.*;
    import java.util.Random.;

    public class AssigOne112
    {
    public static void main (String[] args)
    {
    Scanner sc = new Scanner (System.in);
    Random generator = new Random();
    final int black = 0;
    final int blue = 1;
    final int cyan = 2;
    final int dark grey = 3;
    final int grey = 4;
    final int green = 5;
    final int light grey = 6;
    final int magenta = 7;
    final int orange = 8;
    final int pink = 9;
    final int red = 10;
    final int white = 11;
    final int yellow =12;
    String name1, name2;
    boolean first;
    int innings = 0;

    System.out.println("Enter a player's name"); //declaration
    name1 = newString();
    System.out.println("Enter a 2nd player's name"); //declaration
    name2 = new String();
    System.out.println("Will " + name1 + " be batting first?");
    first = new boolean();
    System.out.println("How many innings will be played?");


    }
    }

    This is my program so far:

    I need to create two objects "car" and "van/truck/bus/SUV"
    then I need to make it so the chance an oncoming vehicle is a car is 9 out of 10.

    How would I write this in my program?

  7. #7
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    16,571
    Rep Power
    23

    Default Re: Car cricket program

    the chance an oncoming vehicle is a car is 9 out of 10.
    One simple way would be to use the Random class to generate a number from 1-10 and test if it is <= 9
    If you don't understand my response, don't ignore it, ask a question.

  8. #8
    Fisty's Avatar
    Fisty is offline Member
    Join Date
    Mar 2012
    Posts
    5
    Rep Power
    0

    Default Re: Car cricket program

    how would i use the random class?
    could you use an example?

  9. #9
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,189
    Rep Power
    19

    Default Re: Car cricket program

    You would start by reading the API for java.util.Random.

    Also read through the FAQs section of this site and find how to use the code tags to preserve the formatting of your code.

    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

Similar Threads

  1. Replies: 2
    Last Post: 04-02-2011, 12:57 PM
  2. Replies: 13
    Last Post: 03-22-2011, 06:49 AM
  3. changing my program to array working program
    By Chewart in forum New To Java
    Replies: 39
    Last Post: 11-18-2009, 06:53 PM
  4. Replies: 0
    Last Post: 04-04-2008, 02:40 PM
  5. Replies: 0
    Last Post: 10-04-2007, 09:33 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •