[QUOTE=stultuske;1699651]and ... how is this post adding anything?[/QUOTE]

my post was late by 2 minutes, hope you understand =.=

At line 23, your s2 variable is [B]null[/B].

[QUOTE=yoshio5908;1693656]Hello everyone at Daniweb! This is my first post here, sorry if i do something wrong.

Ok, so just a quick background on me and where I'm at in java. This year I'm taking my first Comp Sci class as CSUN (Cal State University Northridge). I am a complete beginner when it comes to programming, you have been warned haha.

Anyway, I have to write a program that prints 10 random numbers between 1-100, then prints how many are even and how many are odd.

This is what I have so far.

[CODE]import java.util.Scanner;
public class problem3{
public static void main(String[] args){

for(int i=1;i<=10;i++){
    int randomNumber = (int)(99 * Math.random())+1;

    while(randomNumber % 2 == 0){
        int k = 0 
        System.out.println("you have " + z + " odd numbers");

    while(randomNumber % 2 != 0){
        int z = 0 ;
        System.out.println("you have " + k + " even numbers");



You can search the net about decision making in programming. That could give you some hint.

So, what is your problem?

Since you cannot use split and StringTokenizer, one way is to check one by one of each character from the string if there are any delimiter, put the words inside an array, and then reverse them.

[QUOTE=cecsFTL;1690683]Does anyone know how do i make the program pick a number between 100-999 instead of 0-999?[/QUOTE]

100 + random.nextInt(900)

You can also use JLabel as the button and then add MouseListener to it.

[QUOTE=masijade;1688249]You shouldn't have to "guess". What I am getting at is he should be posting a full "problem" description, not just describing what is supposed to happen and then a blurb of code that may, or may not, have been written by the OP, and then expect everyone to "finish" the code for them without even any hint as to what is still missing, or wrong.[/QUOTE]

I guess you were right after all(sorry for guessing again lol). I agree finishing the program for him does not make him learn anything.

@TigerTeck: You should start learning the basic of programming. My advice is when you learn one thing, start practise with it. Do not proceed if you still didn't get the previous lesson. Honestly, I learned a lot from Youtube since my lecturer sucks. You should check it out there too if you have some time.

I guess your question is how to make it work?

Well, here is a few problem with your code:


[QUOTE=dsoto;1687863]Thank you so much! My student class runs great now. I'm having some trouble with my university class though. I get this error:
Exception in thread "main" java.lang.NullPointerException
at University.collectDataForReport(University.java:8)
at Tuition.main(Tuition.java:24)[/QUOTE]

You didn't initialize the Student[] array.

[QUOTE=subone;1687560]We cannot use the [B]length [/B]because we didn't take it yet. Is there another way?:)[/QUOTE]

What do you mean by "we didn't take it yet"?

We check the length only after the user input the number.

My suggestion:

  1. Add ActionListener to textField.
  2. When actionPerformed(), move the cursor to textArea using textArea.grabFocus().
  3. If you want to place the cursor at the end of the text of textArea, use select() method.

Just use if else statement.


Sorry, my bad. I thought you want an input that is less than 5(1 digit).

Here is my suggestion:

  1. Take the input as string.
  2. Check the length of it.
  3. If it is less than 5, convert it into integer, and then proceed with whatever you wanna do with it, else just print "Error".

sike.mausa, you really should ask your teacher what this program will do. You said your teacher gave it to you? That's weird. Did he/she ever mention about correcting the error or something?

I made it to run but I don't know if the output really meet what you expected.

Here is what I did:

[code]import java.util.;
import java.io.

public class CourseStats {

static String[] studentNames;
static int[][] quizzes;
static int[][] homeworks;
static int[] exam;
static final int NUM_QUIZZES = 9;
static final int NUM_HOMEWORKS = 12;
static final int QUIZZES = 1;
static final int HOMEWORKS = 2;

public static void main(String[] args) throws IOException {



public static void printAverages() {
    for (int i = 1; i <= NUM_QUIZZES; i++) {
        System.out.print("Quiz #" + i + " average: ");

    for (int i = 1; i <= NUM_HOMEWORKS; i++) {
        System.out.print("HW #" + i + " average: ");
public static void printDetails() {

    for (int i = 1; i <= 12; i++)
        System.out.print("\tHW" + i);

public static double getAverage(int type, int whichOne) {
    double test = 0.0;
    if (type == QUIZZES) {

    } else if (type == HOMEWORKS) {

    return test;
public static void initializeArrays() {
    studentNames = new String[100];
    quizzes = new int[100][NUM_QUIZZES];
    homeworks = new int[100][NUM_HOMEWORKS];
    exam = new int[100];
public static void readFile(String filename) throws IOException {


At line 18, I just pass a string just for testing.

At line 27 and 32, I don't know what you really want to print, so I just put the final variable. In your source code, you put something like System.out.println(QUIZZES, i) which is ...


import java.util.Scanner;

public class Student {

private String firstName;
private String lastName;
private String address;
private String phoneNumber;
private int credits;
private double tuition;
private double healthCare;
private double lateFee;
private double mealPlan;
private String mealOption;
private double totalTuition;
private double incidentalFee;
private boolean state;
private boolean lateFeeBoolean;
private boolean campusFood;
private boolean healthCareBoolean;

public Student() {
    this("", "", "", "", 0, 0.0, 0.0, 0.0, 0.0, "", 0.0, 0.0, false, false, false, false);
public Student(String studentFirstName, String studentLastName, String studentAddress, String studentPhoneNumber, int studentCredits, double studentTuition, double studentHealthCare, double studentLateFee, double studentMealPlan, String studentMealOption, double studentTotalTuition, double studentIncidentalFee, boolean studentState, boolean studentLateFeeBoolean, boolean studentCampusFood, boolean studentHealthCareBoolean) {

void setFirstName(String studentFirstName) {
    firstName = studentFirstName;
void setLastName(String studentLastName) {
    lastName = studentLastName;
void setAddress(String studentAddress) {
    address = studentAddress;
void setPhoneNumber(String studentPhoneNumber) {
    phoneNumber = studentPhoneNumber;
void setCredits(int studentCredits) {
    credits = studentCredits;
void setTuition(double studentTuition) {
    tuition = studentTuition;
void setHealthCare(double studentHealthCare) {
    healthCare = studentHealthCare;
void setLateFee(double studentLateFee) {
    lateFee = studentLateFee;
void setMealPlan(double studentMealPlan) {
    mealPlan = studentMealPlan;
void setMealOption(String studentMealOption) {
    mealOption = studentMealOption;
void setTotalTuition(double studentTotalTuition) {
    totalTuition = studentTotalTuition;
void setIncidentalFee(double studentIncidentalFee) {
    incidentalFee = studentIncidentalFee;
void setState(boolean studentState) {
    state = studentState;
void setLateFeeBoolean(boolean studentLateFeeBoolean) {
    lateFeeBoolean = studentLateFeeBoolean;
void setCampusFood(boolean studentCampusFood) {
    campusFood = studentCampusFood;
void setHealthCareBoolean(boolean studentHealthCareBoolean) { ...

I don't know if it affects much but at line 41 in your Student class should be assigned to HealthCare variable.

I'll try to look for more error.

I've been knowing about this site long time ago, yet I didn't even registered, just become a silent reader.

Now I decided to register just for fun, and hopefully I could learn a lots of things here and able to contribute something to the community.

As the compiler stated, you must return a data of type double for your getAverage() method at line 46. If you do not want to return any value, just change to

public static [B]void[/B] getAverage()

but that does not meet the purpose of creating accessor method if it does not return a value.