• Post Reply Bookmark Topic Watch Topic
  • New Topic

Beginning with arrays_build up to creating a tictactoe game  RSS feed

 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I started this Java course online and have been corresponding with the instructor. It takes days days to get an answer from him regarding any errors in my code. Instead of suggesting fixes, he tells me to just go back and re-look at everything.
The only issue is I have no baseline from which to judge the errors I am getting.

He wanted me to build a tictactoe board and game with logic. I don't even have a grasp of basic Java terminology to begin such a task. He then suggested that I create an array with names and birthdays to warm up.

Here is my code -- I am just reading book and webpages trying to figure out a solution for displaying info and scanning the array and putting data into it... it is horrendous but I need some barney style help with this stuff, books are overwhelming without guidance.

I want to put the names and birthday in an array. I want to display the array. Do I need to step through the array with a 'for' statement? What needs to go into line 18 to display the array in my output window?

Any help is appreciated...

1 package NamesBirthdays;
2
3 public class NamesBirthdays {
4
5 public static void main(String [] args) {
6
7
8 char nbarray [] = new char [8];
9 nbarray [0] = Paul;
10 nbarray [1] = Melody;
11 nbarray [2] = Joe;
12 nbarray [3] = Julianne;
13 nbarray [4] = 01APR01;
14 nbarray [5] = 01MAY01;
15 nbarray [6] = 01JUN01;
16 nbarray [7] = 01JUL01;
17
18 System.out.println()
19
20
21 }
22
23 }

These are some of the errors I get:

/MyClass.java:22: error: ';' expected
nbarray [4] = 01APR01;
^
/MyClass.java:23: error: ';' expected
nbarray [5] = 01MAY01;
^
/MyClass.java:24: error: ';' expected
nbarray [6] = 01JUN01;
^
/MyClass.java:25: error: ';' expected
nbarray [7] = 01JUL01;
 
Bartender
Posts: 1840
10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi! Welcome to the ranch.

Things I have noticed:
your array is an array 'char' or characters - i.e. a single letter, you probably want to have an array of type String instead.
char nbarray[] --> String nbarray[]

Your String constants in your program need double quotes around them. i.e. Paul should be "Paul"

These things are so fundamental, I would recommend you step back from arrays until you understand String variables and System.out.println.
I wonder what sort of course you are following that wouldn't follow fundamentals like that.

Which course are you doing?
What book are you following?
Have you tried the standard Java Tutorial
 
author
Sheriff
Posts: 23295
125
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

The nbarray array variable refers to a character array. And Paul, Melody, Joe, etc. are not valid characters.

Can you elaborate what you are trying to accomplish?

Henry
 
D Williams
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you both for your input. In regards to your questions I was hired to evaluate a failing computer programming course for an online education provider as part of their accreditation.

One of the things I do as an adult education consultant is evaluate the delivery method of course material. The best way to evaluate an online course is to take it and identify where it is successful and lacking.
The institution is really good on delivering programming logic and not so great at delivering course material concerning specific types of code. That is where I am at now, I am evaluating the Java specific portion of the course and the instructors that deliver the course material.

I wasn't hired for Java experience but rather my experience in creating quality online based education. The issue, I am having is, I actually enjoy this topic and while I'm in the course evaluating it, I want to take something from it. Believe me it gets much more complicated than what I am posting here but I hope that answers some questions.

As far as your responses I am using the Java Beginners Book, a 2.5 inch thick book with extra small font, from Oracle and the Oracle website. It has an emphasis on using Netbeans which I have found to be very, very overwhelming considering the course is given entirely online. I also can't believe that a complete novice is handed the task of building a tictactoe game from scratch without ever being exposed to the Java language before.

The comment you made and I am paraphrasing about "not understanding string fundamentals" is an issue. I think this comes as a result of not being in a course with peers who are learning the material from an experienced person in a brick and mortar school. I think the online paradigm for teaching computer programming online is shifting in favor of what is being taught on Code.org and Khan Academy. Is this your experience? Are you both programmers, who have learned programming through interaction with instructors at an institution or did you learn online?

You both have provided me some insight into what I suppose is the syntax of the Java programing language. There is an argument between my colleagues and I over if the school should focuses teaching programming logic and philosophy first or syntax. Both sides have been making good arguments but I am currently leaning towards syntax first paradigm, given my issues here. Your thoughts and opinions?

Finally, so the char datatype is used only for single characters? In on of the books I am reading strings are not listed as one of the 8 primary data types in Java. It talks about strings but doesn't put them into context the way you did here on the board. Does this really strike you as odd? The book I am evaluating has byte, short, int, long, float, double, boolean, char as the main eight... string isn't mentioned?

The book is Java Programming by Troy Dimes.

 
D Williams
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So I have implemented changes and I've looked up online about the System.out.println and I don't understand it at all but this is what I have.

All I am looking to do is create the array and display its content as an exercise.

1 package NamesBirthdays;
2
3 public class NamesBirthdays {
4
5 public static void main(String [] args) {
6
7
8 string nbarray [] = new string [8];
9 nbarray [0] = "Paul";
10 nbarray [1] = "Melody";
11 nbarray [2] = "Joe";
12 nbarray [3] = "Julianne";
13 nbarray [4] = "01APR01";
14 nbarray [5] = "01MAY01";
15 nbarray [6] = "01JUN01";
16 nbarray [7] = "01JUL01";
17
18 System.out.println("What am I doing?")
19
20 }
21
22 }

/MyClass.java:16: error: cannot find symbol
string nbarray [] = new string [8];
^
symbol: class string
location: class MyClass
/MyClass.java:16: error: cannot find symbol
string nbarray [] = new string [8];
^
symbol: class string
location: class MyClass
2 errors

 
Henry Wong
author
Sheriff
Posts: 23295
125
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
D Williams wrote:
MyClass.java:16: error: cannot find symbol
string nbarray [] = new string [8];
^
symbol: class string
location: class MyClass


Java is case sensitive. There is no such a thing as a string class -- perhaps you meant String class?

Henry
 
Stefan Evans
Bartender
Posts: 1840
10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Finally, so the char datatype is used only for single characters? In on of the books I am reading strings are not listed as one of the 8 primary data types in Java. It talks about strings but doesn't put them into context the way you did here on the board. Does this really strike you as odd? The book I am evaluating has byte, short, int, long, float, double, boolean, char as the main eight... string isn't mentioned?


Those eight datatypes you mentioned are primitive data types. I'm not sure I'd call them "primary".
In this case primitive means basically "not an object". These datatypes have a value only - you can't call methods on them.

A String by contrast is an Object, which has behavior as well as a value. i.e. you can call methods on it.
The way the book presents makes sense in terms of separating the primitive datatypes from Objects.
String is a bit of a special case though and I would consider it one of the "Primary" datatypes in java.

To answer other questions.
Yes, I'm a programmer
Yes, I went to university to learn to program

In terms of using Netbeans, you will find a number of people who hold the opinion that using a Development Environment like Netbeans or Eclipse is actually detrimental to learning to program, because it hides a lot of the stuff from you.
I'm of the opinion that the best way to learn is via examples. So a code snippet demonstrating data types and some basic syntax should look something like:




Logic/philosophy vs Syntax first ? Tough call.
What bothered me about your initial coding attempt was it seemed obvious that you hadn't had that basic syntax lesson of "how does text get into a java program". And I would expect some basic variable declaration and manipulation to be covered BEFORE moving onto arrays.
I can see arguments both ways. I think you would need SOME basic syntax to start with. Otherwise it would be a bit like learning to read without knowing your alphabet.

A quick look on Amazon shows Java-Programming-A Beginners-Guide-to Learning is brand new with all 11 reviews giving it 5 stars and no negative feedback. Yeah right.
 
D Williams
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You guys are a wealth of information. I was hesitant at first to come on a board to try and figure this stuff out but in lieu of developing relationship with individuals whose course ware I am evaluating it seemed the best option. It seems like it will definitely pay off. Thank you for your insight. A lot of professionals, who have learned to do anything through traditional education make assumptions about the students they are teaching. Previous knowledge, background, etc... things that professionals assume are just common knowledge are usually glossed over in displaced learning. Having a forum like this is invaluable to the distance learner.

Finally, to my code... I was able to get output out of it, which is exciting for me! I would like to set it up so that the program steps through the array and display each piece. Before I come back and ask any questions on how to do that I am going to do a bit more research, once I hit a brick wall, I'll be back here for tutoring. THANK YOU!

package NamesBirthdays;

public class NamesBirthdays {

public static void main(String [] args) {

String nbarray [] = new String [8];
nbarray [0] = "Paul";
nbarray [1] = "Melody";
nbarray [2] = "Joe";
nbarray [3] = "Julianne";
nbarray [4] = "01APR01";
nbarray [5] = "01MAY01";
nbarray [6] = "01JUN01";
nbarray [7] = "01JUL01";

System.out.println(nbarray [0] + "-" + nbarray [4] + ", " + nbarray [1] + "-" + nbarray [5]);
}

}
 
Bartender
Posts: 689
17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There is certainly a chicken and egg dilemma when it comes to programming philosophy and syntax. When I was first taught Java I remember my tutor showed us the basic shell of a Java program (a class with an empty main method and nothing more). He then said words to the effect of:

By the end of the course you will understand what all of these words mean and why they're there. Until then you will just have to trust me that they need to be there, and we'll get back to them later.


He then started the course with basic local variable declarations and assignments, without us having any idea what a class was or what public, static and void meant. We didn't even know what a method was.

I was taught Java in a university classroom btw, and have since self-taught myself other programming languages on-the-job.
 
Marshal
Posts: 56600
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
D Williams wrote: . . . Finally, so the char datatype is used only for single characters? . . .
Yes and no.

It is actually a number but it is usually displayed as a character. If you look up some Unicode you find that A is shown as 0041. That is a hexadecimal number which translates into decimal as 65. You write 'A' and you get A displayed but the memory contains 65.

And welcome to the Ranch again
 
Java Cowboy
Sheriff
Posts: 16060
88
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please UseCodeTags (<- click for info) when you post source code.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!