aspose file tools*
The moose likes Beginning Java and the fly likes Very new to Java Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Very new to Java" Watch "Very new to Java" New topic
Author

Very new to Java

David Gillian
Greenhorn

Joined: Feb 25, 2010
Posts: 4
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

Joined: Jan 10, 2002
Posts: 61198
    
  66

You'll get lots of help here. But you have to do the work.

What specific problems are you having?


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Rose Rimsky
Greenhorn

Joined: Feb 10, 2010
Posts: 25
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.



Fairy tales are more than true: not because they tell us that dragons exist, but because they tell us that dragons can be beaten. – G.K. Chesterton
David Gillian
Greenhorn

Joined: Feb 25, 2010
Posts: 4
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

Joined: Feb 25, 2010
Posts: 4
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

Joined: May 21, 2006
Posts: 425

Check out the SimpleDateFormat class.
ankur rathi
Ranch Hand

Joined: Oct 11, 2004
Posts: 3830
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

Joined: Feb 25, 2010
Posts: 4
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

Joined: Oct 13, 2005
Posts: 38765
    
  23
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

Joined: Oct 02, 2003
Posts: 11308
    
  16

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.


There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors
Jim Hoglund
Ranch Hand

Joined: Jan 09, 2008
Posts: 525
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 ... ...

BEE MBA PMP SCJP-6
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Very new to Java