Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 10 of 10

Thread: help with "Stacked" list

  1. #1
    Junior Member
    Join Date
    Jan 2018
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default help with "Stacked" list

    I'm trying to make a semi-random list of items for a maze, but since I'm new to java I wouldn't know how.

    the way I'm currently doing it is, roll a d12+11 for n (the number of items in the chest), then roll n d100s for the categories of the items, then d100s for the actual item depending on which category each item landed in (a 100 resuting in 2 rerolls in the same category). it works for small amounts of chests, but im planing on having hundreds of them and it would be to time consuming rolling them manualy.

    I don't need help with the entire code, just the mechanics.

  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    21,225
    Thanks
    52
    Thanked 2,273 Times in 2,244 Posts

    Default Re: help with "Stacked" list

    Can you post the code (wrapped in code tags) that you are working on and ask some specific questions about problems you are having.
    If you don't understand my answer, don't ignore it, ask a question.

  3. #3
    Junior Member
    Join Date
    Jan 2018
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: help with "Stacked" list

    Thats just it, i dont know where i'd start.
    I know i nead a random number code for all 3 parts
    And a loop that runs n times.
    But i dont know how to start wrighting the code.

  4. #4
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    21,225
    Thanks
    52
    Thanked 2,273 Times in 2,244 Posts

    Default Re: help with "Stacked" list

    Before trying to write any code make a list of the steps the program needs to take to solve the problem.
    Then take the first item in the list and try writing the code for it.
    If you have any problems, post the code and ask questions.
    Copy the full text of any error messages and paste them.
    Don't try to do the whole program at once. Do it in small steps, get them to work before moving to the next one.


    What programs have you written before?
    If you don't understand my answer, don't ignore it, ask a question.

  5. #5
    Junior Member
    Join Date
    Jan 2018
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: help with "Stacked" list

    Mostly i'v just changed the background of webpages and making buttons. I took 1 year of "programing" that turned out to be nothing more than a typing class with extra benefits.

  6. #6
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    21,225
    Thanks
    52
    Thanked 2,273 Times in 2,244 Posts

    Default Re: help with "Stacked" list

    If you haven't written any programs, I suggest that you start with some very simple programs to start with to build some experience.
    If you don't understand my answer, don't ignore it, ask a question.

  7. #7
    Junior Member
    Join Date
    Jan 2018
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: help with "Stacked" list

    so iv pieced together a program to act as the shell

    public class chest{
    public static void main(String[] args) {
    int dice1;

    welcome();

    }
    public static void welcome() {
    System.out.println("Chest Gen");{
    }

    int dice1=(int)(Math.random()*12+12);
    int sum= dice1;

    System.out.println("Roll: total = " +sum);

    if (sum==12){
    System.out.println("Sorry with a " + sum + " You LOSE "); }
    else if(sum==13) {
    System.out.println("Woah!!! With a " + sum + " You WIN!!!!!!!"); }
    else if(sum==14) {
    System.out.println("Sorry with a " + sum + " You LOSE "); }
    else if(sum==15) {
    System.out.println("Woah!!! With a " + sum + " You WIN!!!!!!!"); }
    else if(sum==16) {
    System.out.println("Sorry with a " + sum + " You LOSE "); }
    else if(sum==17) {
    System.out.println("Woah!!! With a " + sum + " You WIN!!!!!!!"); }
    else if(sum==18){
    System.out.println("Sorry with a " + sum + " You LOSE "); }
    else if(sum==19) {
    System.out.println("Woah!!! With a " + sum + " You WIN!!!!!!!"); }
    else if(sum==20) {
    System.out.println("Sorry with a " + sum + " You LOSE "); }
    else if(sum==21) {
    System.out.println("Woah!!! With a " + sum + " You WIN!!!!!!!"); }
    else if(sum==22) {
    System.out.println("Sorry with a " + sum + " You LOSE "); }
    else if(sum==23) {
    System.out.println("Woah!!! With a " + sum + " You WIN!!!!!!!"); }
    else if(sum==24) {
    System.out.println("Woah!!! With a " + sum + " You WIN!!!!!!!"); }
    }

    }

    I'm using "System.out.println("Woah!!! With a " + sum + " You WIN!!!!!!!"); }" as a place holder. I want the code to take "sum=dice1" and run a loop that consists of;

    int dice2=(int)(Math.random()*100+);
    int sum= dice2;

    if (sum==0 to 47){
    System.out.println("Food"); }
    else if(sum==48 to 67) {
    System.out.println("Alchemy"); }
    else if(sum==68 to 82) {
    System.out.println("Ore"); }

    and so on, but cant find any examples

    --- Update ---

    IDK where the faces came from
    there suppose to be a (

  8. #8
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    21,225
    Thanks
    52
    Thanked 2,273 Times in 2,244 Posts

    Default Re: help with "Stacked" list

    What happens when you compile and execute the code?
    If there are any error messages you need help with, copy and paste here.

    Please edit your post and wrap your code with code tags:

    [code]
    **YOUR CODE GOES HERE**
    [/code]

    to get highlighting and preserve formatting.


    where the faces came from
    The forum's formatting software
    To disable them Use the Advanced Option when creating a post and select this option under Additional Options:
    Disable smilies in text
    If you don't understand my answer, don't ignore it, ask a question.

  9. #9
    Junior Member
    Join Date
    Jan 2018
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: help with "Stacked" list

    it works fine I just need help with the loop. I need it to take the sum of dice1 and run a loop that many times

  10. #10
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    21,225
    Thanks
    52
    Thanked 2,273 Times in 2,244 Posts

    Default Re: help with "Stacked" list

    I need it to take the sum of dice1 and run a loop that many times
    What have you tried? What happened?
    There are two steps:
    1)take the sum of dice1 >> How do you get the sum of dice1?
    2)run a loop that many time >> use a for loop
    If you don't understand my answer, don't ignore it, ask a question.

Similar Threads

  1. Replies: 4
    Last Post: July 18th, 2014, 02:04 AM
  2. Replies: 1
    Last Post: July 16th, 2014, 04:16 AM
  3. Replies: 2
    Last Post: May 22nd, 2014, 01:17 PM
  4. Replies: 2
    Last Post: June 22nd, 2013, 10:30 AM
  5. How would you add a list of "events" and "tasks" to their respective arrays?
    By LIboy1027 in forum What's Wrong With My Code?
    Replies: 1
    Last Post: June 19th, 2013, 06:32 AM