• Post Reply Bookmark Topic Watch Topic
  • New Topic

Not understanding how to utilize objects  RSS feed

 
lassy bug
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm trying to create contact information as object and another object as parcel then calculate the shipping fee. Problem is I don't have a good understanding in implementing object type to my code. Attached are what I've done and I know that my constructor in my parcel class and contact class are probably wrong too but I don't know what to do with it. Any insights? I just started Java 2 weeks ago and I just opened up an account here in this forum. Please let me know if I cross any rules.

 
Tony Docherty
Bartender
Posts: 3271
82
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch.

Your code is hard to read because you haven't followed the Java naming conventions, class names start with an uppercase letter, variable and method names start with a lower case letter and when you concatenate two or more words the first letter or the joined word is upper case, so setishipping() should be setShipping() - why is there a spurious 'i' in all your method names. The variable 'City' should be 'city' etc.

Does your code even compile? - please either fix the compilation errors first or if you can't show us what they are.

With regard to your constructors:
In your Contact constructor you are overwriting whatever values of xco and yco are passed in - do you really want to do this?
In your Parcel constructor ding a System.exit() just because a value is out of bounds is a little harsh and would make your program virtually unusable. you should also look at your assignment of sender and receiver I don't think you want to be assigning them to local variables.
 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!