• Post Reply Bookmark Topic Watch Topic
  • New Topic

How to.....  RSS feed

 
srinivas katlu
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I am a beginner in Java, I am able to identify classes after that not able to go further......can any one give hints about the following use cases please! steps involved in coding(Identifying constructors, methods and object creation).

help me please!!!

1.Create a document with 4 pages and one table of contents page( this is part of 4 pages that is one of the pages, it should contain the 4 pages booklet's table of contents).

2.ATM Machine
Deposit 1000 Rupees
Withdraw 8000
deposit 1000
deposit again 8000
get a statement showing the balance.

all the transactions should be shown in an arraylist.

3.Buying movie tickets from a machine..


I am able to go upto class creation....not able to implement methods....I am lost....

Thanks in advance!
 
Deepak Bala
Bartender
Posts: 6663
5
Firefox Browser Linux MyEclipse IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sounds like homework.

What classes did you create so far ? What approach did you take to solve the problem ?
 
Anayonkar Shivalkar
Bartender
Posts: 1558
5
Eclipse IDE Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello srinivas katlu,

Welcome to CodeRanch!

As Deepka Bala has asked, firstly you'll have to decide the actors (i.e. classes), then assign functionality for each class. Also, if necessary, you can create another class and decide their relationship (e.g. IS-A, HAS-A etc.).

After you are done with this part, then you should start writing code.

I hope this helps.
 
srinivas katlu
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
[size=18]

1.Create a document with 4 pages and one table of contents page( this is part of 4 pages that is one of the pages, it should contain the 4 pages booklet's table of contents).

In this use case I have identified classes as follows...


Document.java

properties ->number of pages,author
methods--> getpagenumber()

Pages.java

properties-->pagenumber
methods--> getAllContent()

TableOfContents.java


methodsgetTableOfContent()

First I created package name

class

after this not able to go further.....




 
fred rosenberger
lowercase baba
Bartender
Posts: 12565
49
Chrome Java Linux
  • Likes 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
EVERY time I start a java project, the first thing I do is step away from my computer. I write down (ok...I may use a text editor, but I am definitely NOT thinking about java at this point) what needs to happen. What kinds of things do I need? what do they need to know? How/can they be changed? Do they need to talk to each other?

Then I start writing down details of some of the things they need to do - still no java...so I may need to get a an amount to deposit, an account to deposit it to, and a PIN. I need to retrieve the current balance, add the deposit to it, and then print the total.

I do this for most of the methods I can think of. Only when I've spent a significant amount of time on this (possibly days, if the project is large enough) do I start writing code. I then write exactly this much code:



I compile and run that. Only when I am sure i have no errors do I think about writing any more. My next iteration might be:



I then compile, run, and test that. Note that there was code in my original version that i have thrown away. By the time I am done, I will probably have written and thrown away 2-3 times as much code as I keep that I have used for testing.

The idea is that you only code teeny, tiny bits at a time. You test as you go, and you compile and test OFTEN. You only want to add little bits so that you know where problems are each compile/test cycle.
 
srinivas katlu
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Fred....
 
srinivas katlu
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for replying Deepak, this is not my home work....since I started learning Java to get familiarize with classes, objects and constructors....I just googled and found them. without solutions..

 
srinivas katlu
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for replying Shivalkar...I don't know what are IS-A and HAS-A something like linking or concept of encapsulation?
 
Anayonkar Shivalkar
Bartender
Posts: 1558
5
Eclipse IDE Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
srinivas katlu wrote:Thanks for replying Shivalkar...I don't know what are IS-A and HAS-A something like linking or concept of encapsulation?

Well, IS-A and HAS-A are quite basic class-relationships. Some books might mention HAS-A relationship as 'composition'. Important thing is - you should be aware of those concepts.

E.g. Every Manager IS-A Employee. So, if your application has two classes - Employee and Manager, then Manager should get all the properties/behavior of Employee. In short, Manager should extend Employee class.
On the other hand, every Car HAS-A Engine. So, for two classes, Car and Engine - the Car class should contain an instance of Engine.

If you are not aware of those concepts, then I would highly recommend to go through those. Those concepts come in very handy when number of classes start to increase.

I hope this helps.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!