Jump to content


Check out our Community Blogs

Register and join over 40,000 other developers!


Recent Status Updates

View All Updates

Photo
- - - - -

Analysing a problem case


  • Please log in to reply
5 replies to this topic

#1 Coldhearth

Coldhearth

    CC Resident

  • Just Joined
  • PipPipPipPip
  • 88 posts

Posted 08 November 2009 - 12:19 PM

Hi,

I'm a beginning programmer and I'm learning Java now.
I was wondering if any of you could help me out with the analystic part of programming.

I have here an exercise:

Drivers are concerned with the mileage their automobiles get. One driver has kept track of
several tankfuls of gasoline by recording the miles driven and gallons used for each tankful.
Develop a Java application that will input the miles driven and gallons used (both as integers)
for each tankful. The program should calculate and display the miles per gallon obtained for
each tankful and print the combined miles per gallon obtained for all tankfuls up to this point.
All averaging calculations should produce floating-point results. Use class Scanner
and sentinel-
controlled repetition to obtain the data from the user.


From this we have to make a small working application (exercise in chapter 4 of our book)

My question is how do you best analyse such a problem (text) to change it into classes, instance variables, methods etc...

Tips would be great :)
  • 0

#2 WingedPanther73

WingedPanther73

    A spammer's worst nightmare

  • Moderator
  • 17757 posts
  • Location:Upstate, South Carolina
  • Programming Language:C, C++, PL/SQL, Delphi/Object Pascal, Pascal, Transact-SQL, Others
  • Learning:Java, C#, PHP, JavaScript, Lisp, Fortran, Haskell, Others

Posted 09 November 2009 - 08:41 AM

Usually what I do is try to solve the problem by hand with pencil and paper. I make note of all the information I had to record as I solve it: those are my instance variables. The processing I do are my methods.

There isn't a single "method" to this, you just get a feel for it with practice.
  • 0

Programming is a branch of mathematics.
My CodeCall Blog | My Personal Blog

My MineCraft server site: http://banishedwings.enjin.com/


#3 Coldhearth

Coldhearth

    CC Resident

  • Just Joined
  • PipPipPipPip
  • 88 posts

Posted 09 November 2009 - 08:51 AM

I have heard something about analysing the text of a problem case by filtering nouns and verbs and so to find classes, instance variables and methods....
Some trick to filter unnecessary information to create the program...?
  • 0

#4 WingedPanther73

WingedPanther73

    A spammer's worst nightmare

  • Moderator
  • 17757 posts
  • Location:Upstate, South Carolina
  • Programming Language:C, C++, PL/SQL, Delphi/Object Pascal, Pascal, Transact-SQL, Others
  • Learning:Java, C#, PHP, JavaScript, Lisp, Fortran, Haskell, Others

Posted 09 November 2009 - 10:27 AM

You have to spend a little time determining which nouns/verbs are actually relevant to the problem. Ultimately, you have to understand the problem. For more advanced problems, there can also be unstated nouns/verbs that are actually necessary for the solution.
  • 0

Programming is a branch of mathematics.
My CodeCall Blog | My Personal Blog

My MineCraft server site: http://banishedwings.enjin.com/


#5 wim DC

wim DC

    Roar

  • Expert Member
  • PipPipPipPipPipPipPipPip
  • 2681 posts
  • Programming Language:Java, JavaScript, PL/SQL
  • Learning:Python

Posted 09 November 2009 - 11:31 PM

For the first 2 lines:

Drivers are concerned with the mileage their automobiles get. One driver has kept track of
several tankfuls of gasoline by recording the miles driven and gallons used for each tankful.

the noun verb thing you mentioned doesn't just give you the classes and variables etc.
basicly all verbs COULD be a method and nounds MAY be a class or variable.

Drivers concerned with mileage of their automobiles.
out of this sentence i would get:
Driver: class
mileage: attribute / variable
automobile: class with the mileage attribute / variable in it.

A small test to find out if it's a class or not is: If you can think about a number or 1 word with the candidate class, it is not a class.
Like Driver i can give his name, address, sort of car he drives, what licence he has,... pretty much 100% a class.

Automobile: This one depends. If for the program all you need is the name of the type of car. So only 1 thing, it would be a variable/attribute. However we also have the mileage variable which obviously should fit in automobile. That makes it having more than 1 word / number, -->class
Mileage : just a number --> attribute /variable

isConcernedWith() possible method. I don't know if you think about it this way.. but for me it makes pretty much sence that this is not a viable method..... It basicly means that inside the class Driver you will have an attribute that gives the Automobile

One driver has kept track of
several tankfuls of gasoline by recording the miles driven and gallons used for each tankful.

Driver : exists allready.
tankful: text says it itself: the miles driven AND gallons used for each tankful. 2 things --> class
gallons : number --> variable /attribute
miles : number --> variable /attribute

keepsTrackOfByRecording. Possible method (i would just name it recordTankful() or so :P)

You could possible get more things out of:

The program should calculate and display the miles per gallon obtained for
each tankful and print the combined miles per gallon obtained for all tankfuls up to this point.

like a calculate method and display method...

I personally don't really like analysing for such little things that are done faster by just starting to program. But i gues it won't hurt + it might help for the future if you actually have to anaylise
  • 0

#6 Coldhearth

Coldhearth

    CC Resident

  • Just Joined
  • PipPipPipPip
  • 88 posts

Posted 10 November 2009 - 12:20 AM

Thank you very much oxano :) that's a really helpful post ^^
I'll try to use this for other problem cases :)
I'm a starting programmer so I have some issues turning problem cases into programs... :)
  • 0




Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download