Jump to content


Table Top Rpg Program


  • Please log in to reply
6 replies to this topic

#1 The Bad Programmer

The Bad Programmer

    Newbie

  • Members
  • Pip
  • 4 posts

Posted 22 February 2012 - 12:36 AM

HELLO

I hope someone can help me with my problem(s).
You see, this weekend, my friends and I are going to play a table top RPG, Star Wars in particular.
And I, being a kind soul, decided to try to create a program to make the experience better.
So, I have scoured the internet after applying my VERY (ACCIDENTALLY HIT THE END BUTTON) basic knowledge of Java, and came up with quite a bit of code. My goal is to create a database for all of our characters, and our stats, plus our stat modifiers. As you can probably tell, I'm not very good at Java.

So here's the code...

import java.util.Scanner;
import java.io.BufferedInputStream;
import java.util.Locale;

public class SWRPG {

    public static void main(String[] args) {
java.io.BufferedReader stdin = new java.io.BufferedReader(new java.io.InputStreamReader(System.in));
     Scanner reader = new Scanner(System.in);
     int N = Integer.parseInt(args[0]);

        // initialize an arary that holds N objects of type Student
        Student[] students = new Student[N];

        // read in the data
        for (int i = 0; i < N; i++) {
            String Name   = stdin.readString();
            String Str = stdin.readString();
            String Dex = stdin.readString();
            String Con = stdin.readString();
            String Inte = stdin.readString();
            String Wis = stdin.readString();
            String Char = stdin.readString();
            String Car = stdin.readString();
            int section = stdin.readInt();
            students[i] = new Student(Name, Str, Dex, Con, Inte, Wis, Char, Car, section);
        }

            // print results
        for (int i = 0; i < N; i++) {
            System.out.println(students[i]);
        }
    }

}


Another class.


import java.util.Scanner;
public class Student {

    private String Name;     // first name
    Scanner reader = new Scanner(System.in);
    private String Str;
    private String Dex;
    private String Con;
   private String Inte;
   private String Wis;
   private String Char;
    private String Car;
    private int    section;   // section number

    // construct a new student with given fields
    public Student(String Name, String Str, String Dex, String Con, String Inte, String Wis, String Char, String Car,  int section) {

    System.out.println("Enter Strength: ");
Str = reader.readLine();
System.out.println("Enter Dexterity: ");
Dex = reader.readLine();
System.out.println("Enter Constitution: ");
Con = reader.readLine();
System.out.println("Enter Intelligence: ");
Inte = reader.readLine();
System.out.println("Enter Wisdom: ");
Wis = reader.readLine();
System.out.println("Enter Charisma: ");
Char = reader.readLine();
System.out.println("Enter Carrying Capacity: ");
Car = reader.readLine();
System.out.println("Enter section: ");
section = reader.nextInt();




    }

    // return true if the invoking object's section is less than that of b
    public boolean less(Student b) {
        Student a = this;
        return a.section < b.section;
    }

    // return a string representation of the invoking object
    public String toString() {
        return section + " " + Name + " " + Str + "  " + Dex + " " + Con + " " + Inte + " " + Wis + " " + Char + " ";
    }

}



Thanks for any help that I get, I greatly appreciate it, and so do my friends.

Please, if possible, help me troubleshoot before the weekend :)

#2 The Bad Programmer

The Bad Programmer

    Newbie

  • Members
  • Pip
  • 4 posts

Posted 22 February 2012 - 01:52 AM

I just thought of something, but it won't change very many problems.
I want a string, that has the characters name, stats, and stat modifiers.
Not count each stat as a string, just the name and the characters stats all together as 2 strings?
I.E

String Name
int Str, Con, Dex, Wis, etc...

But what I want for output is similar to this...

" (Random Name) Roland, 15 Strength, 17 Constitution, 14 Dexterity, etc..., Strength Modifier of +2, Carrying capacity of ***( the formula for carrying capacity is "Car = (Str ^ 2) * .5;"

Thank you for any input.

#3 nujumkey

nujumkey

    Member

  • Members
  • PipPip
  • 10 posts

Posted 22 February 2012 - 02:38 AM

i agree with your comment about stats, but first you may want to tweak your program first. unfortunatly i am a newbie too.
i've copied your program and am currently scanning it again except now i can adjust it and see if i can find a problem using an error code. :D
hope to get backt o you by tomorrow

#4 The Bad Programmer

The Bad Programmer

    Newbie

  • Members
  • Pip
  • 4 posts

Posted 22 February 2012 - 02:42 AM

View Postnujumkey, on 22 February 2012 - 02:38 AM, said:

i agree with your comment about stats, but first you may want to tweak your program first. unfortunatly i am a newbie too.
i've copied your program and am currently scanning it again except now i can adjust it and see if i can find a problem using an error code. :D
hope to get backt o you by tomorrow



I thank you good sir, with alllllllllll my heart. or ma'am... Anyway, thanks for your time, if you have any questions about purpose just ask.

#5 nujumkey

nujumkey

    Member

  • Members
  • PipPip
  • 10 posts

Posted 22 February 2012 - 02:57 AM

okay i think ive got a few tips.

firstly you might watnt o try both of these import codes;

import java.io.*; //for file/keyboard input
import java.util.*;

the * replacing your old Scanner one, i've always found it helpful for some queer reason.

another thing how exactly did you write your program? it looks like you added one thing after another depending on when you watched different guides, so its a bit jumbled. i think if you start over, making reference to your old program you will find it to be better organized and maybe catch an error or two.

and lastly i have this anoyying error with the secind class. i think my computer tries to apply both classes, despite the void :(. im not sure how to combat it.

#6 nujumkey

nujumkey

    Member

  • Members
  • PipPip
  • 10 posts

Posted 22 February 2012 - 02:58 AM

View PostThe Bad Programmer, on 22 February 2012 - 02:42 AM, said:

I thank you good sir, with alllllllllll my heart. or ma'am... Anyway, thanks for your time, if you have any questions about purpose just ask.

or mam...

i know my names asian but what...

im a guy btw.

#7 The Bad Programmer

The Bad Programmer

    Newbie

  • Members
  • Pip
  • 4 posts

Posted 22 February 2012 - 01:14 PM

View Postnujumkey, on 22 February 2012 - 02:58 AM, said:

or mam...

i know my names asian but what...

im a guy btw.
Just being safe, hahaha, and ok I'll try the tips.