Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Very new to Java

 
David Gillian
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello all.

I am very new to Java and I'm struggling to keep my head above water. I'm currently enrolled at North Texas and taking Java I. I'm looking for some help and guidance in writing Java programs in Netbeans 6.8, Java 1.6.0_17. I am writing basic programs like the coin counter, simple calculator, and fighter jet simulation. I’m not asking anybody to do my homework, but would like to be pointed in the right direction. If anybody can help me out, it would be greatly appreciated.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65225
95
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You'll get lots of help here. But you have to do the work.

What specific problems are you having?
 
Rose Rimsky
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi David, welcome to Java Don't worry everyone faced the same when beginning with Java, or at least me too But in order to help you, we need to know what are your problems, what have you done so far?? You may wish to take a look at this page.


 
David Gillian
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I need to write a Java program in Netbeans 6.8 that reads a string from the keyboard and tests whether it contains a valid date. Display the date and a message that indicates whether it is valid. If it is not valid, also display a message explaining why it is not valid.
The input date will have the format mm/dd/yyyy. A valid month value MM must be from 1 to 12 (January is 1). The day value dd must be from 1 to a value that is appropriate for the given month. September, April, June, and November each have 30 days. February has 28 days except for leap years when it has 29. The remaining months all have 31 days each. A leap year is any year that is divisible by 4 but not divisible by 100 unless it is also divisible by 400.

If anybody can point me in the right direction on this I would be very grateful.
 
David Gillian
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I really don't know where to start on this. I'm not asking anybody to do my homework. I just want some guidance on where to start on this. Thats all. Thanks.
 
Pushkar Choudhary
Rancher
Posts: 425
Android Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Check out the SimpleDateFormat class.
 
ankur rathi
Ranch Hand
Posts: 3830
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
David Gillian wrote:I really don't know where to start on this. I'm not asking anybody to do my homework. I just want some guidance on where to start on this. Thats all. Thanks.


Try this:

Write this method first:

boolean isStringValidDate(String stringDate) {
// code
}

* stringDate is a string of 10 characters (mm/dd/yyyy).

Now when you read input string from console, take first 10 characters of it (0 to 9), pass that to above method... 10 more characters (this time 1 to 10), again method call, 2 to 11 characters and so on...

Hope I was clear.

 
David Gillian
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you so much for you help! It is greatly appreciated! I can tell already that I going learn a lot from all of you.
 
Campbell Ritchie
Sheriff
Pie
Posts: 50239
79
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If possible, avoid IDEs (including NetBeans) at your stage. Use a text editor (not NotePad, try NotePad2, NotePad++ and jEdit instead) and compile to the command line. The learning curve for IDEs is just as steep as for programming, and they have some "helpful" features which can confuse beginners.
 
fred rosenberger
lowercase baba
Bartender
Posts: 12196
35
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I've said this many times here. When you are first learning to write code (and even after you've been doing it 10 years), there are two critical things you need to do.

1) think about what you are going to do. come up with a plan. write down what you need to do, in English (or whatever natural language you choose) step by step. Pretend you are explaining to someone what they need to do. revise the steps down to their most granular level.
Note that the assignment text itself that you posted is just the START of this process. for example, a first draft would be

1) get data
2) test data
3) print result

so, ok, what does this mean? how do you get the data? the assignment gives you a hint (from the keyboard, as opposed to reading a file). so break that down.

How do you get the data?

1a) prompt user for input
1b) read data from keyboard
1c) save data

look at each of these. Do you think you know how to prompt the user for data? If so, great!!! you are on your way. if not, see if you can break it down any more.

once you have this all broken down, you need to read part 2 of my advice to beginners

2) write as LITTLE code as possible before you go through the compile/run/test/debug cycle. My first go at EVERY program I write is never any more than this:


I compile that, run it, make sure it does what I want. Only after that works do I attempt to write another line or two of code. This sounds like it would be painfully slow, but it's not. Each time I go through the cycle, I can make sure the one or two new lines work right. I can re-test everything I've done, to be sure I don't break anything. I can proceed with confidence that things are ok.

Nothing is worse, or harder, than writing 20 or 50 or 100 lines of code before compiling for hte first time. You will get dozens of compiler errors. You will spend hours fixing all those, only to FINALLY run you code, to watch it fail horribly the most basic test.
 
Jim Hoglund
Ranch Hand
Posts: 525
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I heartily endorse fred's advice on taking baby steps in the code.
Make the compiler smoke, helping you straighten out your syntax.
This will free more of your little gray cells to reflect on the problem
to be solved. Welcome to a great bunch of helpful folks. They
can be tough, but are honest and polite too. Good luck!
Jim ... ...
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic