• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

I feel I'm going about this the wrong way

 
Ranch Hand
Posts: 289
2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi guys ben working on an insurance quote program the last couple of days

the plan was to have 3 methods

getDetails

calculateData

printQuote

i have finished the getDetails method answering all the questions to get data back from the user

and i created the end of the printQuote method to put the whole thing in a loop

so there are still sections to do.

but i just feel the program is really long, maybe im missing something here and could be more efficient, i just dont know.

remember that i had to use different primitives like byte and short for the sake of the unholly instructor.

here is my code, tear me to shreds!!!

 
Saloon Keeper
Posts: 10705
86
Eclipse IDE Firefox Browser MySQL Database VI Editor Java Windows ChatGPT
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Just to pick an example. There are two issues here that I see. One is that you shouldn't be using a byte to store an integral amount; use int. The other is that these are redundant. You can derive "hasPenaltyPoints" from penaltyPoints being zero. If you really needed to know, true or false, if the person has penalty points, you could make a method hasPenaltyPoints().

This  would also simplify the user interface by reducing two questions down to one.

Move all your user interface code into their own methods. Maybe go one step further and make some more generic input methods as appropriate. For example:
or

 
Carey Brown
Saloon Keeper
Posts: 10705
86
Eclipse IDE Firefox Browser MySQL Database VI Editor Java Windows ChatGPT
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Make a method
This makes the input code easier to read and allows you to improve the test to use, perhaps, a regular expression, without involving changes to the user input method.

Instead of "age", get the person's birth data and compute the age on the fly.
 
wayne brandon
Ranch Hand
Posts: 289
2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hey Carey

i fully understand where you are coming from

but we are only allowed to use 3 methods

as for the byte thing, if it is a number from 1 to 127 such as number of drivers (which would prob be 1,2 or 3 at the most) we have been instructed to use a byte, Campbell told me the same thing
ridiculous huh?

i will look at what you said about storing boolean etc

but all of this aside does it look ok

i was thinking that maybe some things like driver age, points etc could be compressed into one loop but i would think it would be messy

thanks for taking the time
 
wayne brandon
Ranch Hand
Posts: 289
2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
"Instead of "age", get the person's birth data and compute the age on the fly." i love this!!!

if i have time i will implement it after im finished

i still have a month to do this, so i prob will, very good idea!!! thanks
 
Carey Brown
Saloon Keeper
Posts: 10705
86
Eclipse IDE Firefox Browser MySQL Database VI Editor Java Windows ChatGPT
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

wayne brandon wrote:...but we are only allowed to use 3 methods

<shakes head sadly>
 
wayne brandon
Ranch Hand
Posts: 289
2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
<drops head in shame>
 
Bartender
Posts: 10780
71
Hibernate Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

wayne brandon wrote:but we are only allowed to use 3 methods


Really? Sounds silly to me ... but such are vagaries of computer courses.

So basically you've written a program that you want to do absolutely everything you've been asked to in ONE class, and THREE methods.

Or did your teacher maybe mean to apply what you already (presumably) know about classes, create some that might be useful, and THEN come up with a solution that uses the three methods you've been asked to write?

I suggest you ask him/her, and get back to us; because what you've written is certainly Java code (and don't throw it away, because some of it might be useful), but it's not a Java - or Object-oriented - PROGRAM in any sense that I understand it.

Programming is not just banging down code in the hope of getting a solution; it's understanding the problem you've been given.

HIH

Winston
 
Carey Brown
Saloon Keeper
Posts: 10705
86
Eclipse IDE Firefox Browser MySQL Database VI Editor Java Windows ChatGPT
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

the plan was to have 3 methods

getDetails

calculateData

printQuote

My interpretation of this is that you need  those three methods but that it doesn't preclude helper methods.
 
wayne brandon
Ranch Hand
Posts: 289
2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
We have done very little oop and have only just started return values after being given this assignment

Look he isn't strict

I initially started making methods for each section
I had a method for getAge penaltyPoints etc etc cause that's how I thought you program
But he said that isn't necessary and had instructed the students that asked that three methods
Was enough. But I'm sure if I used a few more it wouldn't be a problem. I have already used the .isequal method that he said is fine, we never covered that. So he isn't too strict.
What are you suggesting.
 
Marshal
Posts: 79178
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

wayne brandon wrote:. . . but we are only allowed to use 3 methods

as for the byte thing, if it is a number from 1 to 127 such as number of drivers (which would prob be 1,2 or 3 at the most) we have been instructed to use a byte, Campbell told me the same thing . . .

Who is paying for this bootcamp of yours?
 
wayne brandon
Ranch Hand
Posts: 289
2
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
i am ...was 500 dollars for 4 months twice a week

it is silly stuff,but i think i have learnt stuff too.
 
Winston Gutkowski
Bartender
Posts: 10780
71
Hibernate Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

wayne brandon wrote:i am ...was 500 dollars.


Jeez. Well, kudos to you my man. Not many would shell out that kind of dosh.

Doesn't mean we'll be any "softer" on you though. :-)

Winston
 
Campbell Ritchie
Marshal
Posts: 79178
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If you are getting two whole days for four months, $500 isn't a bad price.
 
wayne brandon
Ranch Hand
Posts: 289
2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I thought it was very reasonable too.
this is my last assignment so i can then either go to college or keep going somewhere else.
but i dont know what the next step is,just focussing on trying to do whats ahead of me.
one thing is for sure,i really love this stuff.
i have already spent about 10 hours on this and my classmates havent even started
i get home im working, i try to do something every day.
i dont see it as work,though sometimes it can be frustrating.
i just hope i get better and sometimes when you guys reply stuff, im totally lost.
but i will just keep going, i have a lot of passion.
 
Winston Gutkowski
Bartender
Posts: 10780
71
Hibernate Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

wayne brandon wrote:i have a lot of passion.


Good, because you'll need it. Programming is great, boring, insightful, tedious, exacting, and - just very rarely - inspirational. If you're in it for the money, there are better-paying jobs out there; but if not, and money isn't your only goal, and you like programming, prepare for a LOT of fun work and thinking.

Best of luck.

Winston
 
Sheriff
Posts: 17644
300
Mac Android IntelliJ IDE Eclipse IDE Spring Debian Java Ubuntu Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Carey Brown wrote:

wayne brandon wrote:...but we are only allowed to use 3 methods

<shakes head sadly>


<screams>
That is so bad. Don't let this instructor mold you into exactly the kind of programmer we do NOT need more of in this world: one who just takes "specifications" like that and follows them blindly.

Writing code is design and as such requires you to think and constantly adapt as your ideas get put into executable code. The requirement to use only three methods forces you into writing code that is horrifically long, unreadable, and difficult to work with, including the important tasks of testing and debugging.
 
Junilu Lacar
Sheriff
Posts: 17644
300
Mac Android IntelliJ IDE Eclipse IDE Spring Debian Java Ubuntu Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

wayne brandon wrote:But he said that isn't necessary and had instructed the students that asked that three methods was enough


I'll tell you what's way more than enough: paying $500 to have a teacher who says something like that. WTH. Sorry, but No. Just NO.

He should be encouraging his students to break long methods into smaller ones. He should be encouraging you to find ways to eliminate duplicated logic. All those loops you have for checking for correct input is duplicated logic that makes your program more difficult to work with and more inviting to inconsistency and bugs.
 
Campbell Ritchie
Marshal
Posts: 79178
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Junilu Lacar wrote:. . . All those loops you have for checking for correct input is duplicated logic . . .

Didn't I show you my input class and how you can verify that an input is in a particular range? It is a bt harder for text because even a single word of text has so much potential variability that it becomes hard to validate. One way to do such validation may be a regular expression, but that is probably beyond the scope of what you need at present. And regular expression are usually not easy.
Another way to validate input is get it away from String forat as quickly as possible because validation of a different datatype is probably easier.
 
Marshal
Posts: 8857
637
Mac OS X VI Editor BSD Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
@OP

Could you please post the instructions exactly as you have been given them? (assuming they are in english).

I see you have been asked to create 3 specific methods college is expecting to see, however, I don't see anywhere insisted to have only those.
It is quite common to misinterpret requirements and having done so to go down the wrong route implementing solution only because of incorrect assumptions.

Guys mentioned many things (simple ones), which I really like to read the way they word them, what the software development is about.

Now, if you see that your problem solutions requires you to create 30 methods and that way makes your program easier to understand and implement, this is what really you should be doing then, writing 30 methods instead of 3. Creativity is part of the programming, think problem through and come up with ideas how to solve it in an elegant way. Elegant usually means SIMPLE to understand, and not COMPLICATED, which makes hard to understand.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic