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 578979
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T14:19:04+00:00 2026-05-13T14:19:04+00:00

Sooo I started taking my second computer science class ever! For my first class

  • 0

Sooo I started taking my second computer science class ever! For my first class we used python and for this class we’re using Java. Our first assignment (pretty much just practice) is to convert this craps program from Python to Java and I’m just having a hell of a time.

Could someone please help with what I’ve done and umm give me some advice? Maybe a good site for a beginner…. Someone that kinda knows Python (only from a first CS course perspective).

1) In python

def winCraps():
roll = rollDice()
if roll == 7 or roll == 11:
    return True
elif roll == 2 or roll == 3 or roll == 12:
    return False
else:
    return rollForPoint(roll)

This is my attempt at the conversion of it over to java

public int winCraps{
    roll = rollDice();
    if (roll = 7 && 11){
    return (true);
    }
    else (roll =2 && 3 && 12){
    return(false);
    }
    else{
    return rollforPoint(roll);
}
}

2) Python

def rollDice():
raw_input("Press <Enter> to roll...")
die1 = randrange(1,7)
die2 = randrange(1,7)
sum = die1 + die2
print "You rolled", die1, "+", die2, "=", sum
return sum

This one confused the hell out of me. What would randrange be in Java??

Java

static int rollDice(){
System.out.print("Press <Enter> to roll...");
double die1 = Math.random();
double die2 = Math.random();
die1 = (int) die1*6+1;
 die2 = (int) die2*6+1;
 int sum = (int)die1 + (int)die2;
 System.out.println("You rolled  "+die1+ " + "+die2+ " = "+sum+".");
 return sum;
 }

*please bear in mind that I’m just learning this stuff lol

  • 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-05-13T14:19:04+00:00Added an answer on May 13, 2026 at 2:19 pm

    You need to fix your if statements the “==” operator checks for equality, and you must put the variable you are checking against in each section of the statement.

    public int winCraps{
        roll = rollDice();
        if (roll == 7 || roll == 11) {
            return true;
        }
        else if(roll == 2 || roll == 3 || roll == 12) {
            return false;
        }
        else{
            return rollforPoint(roll);
        }
    }
    

    In you rollDice() method, the way you assign values to each die is incorrect. I recommend reading up on random numbers (since this is homework, I’ll leave that to you).

    Also, remember in java you must always end each statement with a semicolon

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

Sidebar

Related Questions

Update below... Ok, ive got a problem here. Im using this excellent vimeo class
i've got some problems using jQTouch. I have this Link <a href=#site_map class=swap>Map</a> and
sooo if i install first visual studio 2008 i get a error, this is
I have tried so many things but I don't understand this sooo confusing. I
There are topics about this, but not realy pointed at my problem. I'm using
I have setup with guthub with a previous github account on this computer called
Did anyone set up something like this for himself using the existing node.js REPL?
Ok this has been become sooo confusing to me. I just don't know what
I'm sure this is sooo simple but I've come from a c# background where
I've been meaning to find a solution for this for YEARS. I am sooo

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.