Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.java.programmer > #36170

Re: can someone chk is this code ok and if i can make it better please state how

Path csiph.com!news.swapon.de!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail
From Robert Klemme <shortcutter@googlemail.com>
Newsgroups comp.lang.java.programmer
Subject Re: can someone chk is this code ok and if i can make it better please state how
Date Sat, 7 Jan 2017 14:23:13 +0100
Lines 62
Message-ID <edc8e3Fmrq9U1@mid.individual.net> (permalink)
References <e69219b6-6d90-4d99-9e0c-485e867fded4@googlegroups.com>
Mime-Version 1.0
Content-Type text/plain; charset=utf-8; format=flowed
Content-Transfer-Encoding 7bit
X-Trace individual.net uhAR2mjw9G00FYQoW57OIwJUlUvAiH/jk1KojkYzhnSiI2rIA=
Cancel-Lock sha1:AXKq/GUYjXOFoJGSv7OUPSKsCP8=
User-Agent Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.5.1
In-Reply-To <e69219b6-6d90-4d99-9e0c-485e867fded4@googlegroups.com>
Xref csiph.com comp.lang.java.programmer:36170

Show key headers only | View raw


On 06.01.2017 21:38, SuperGiirl wrote:
> public class Gadget
> {
>     private int Weight;
>     private double Price;
>     private String Model;
>     private String Size;
>
>
>     public Gadget(int theWeight, double thePrice, String theModel, String theSize)
>     {
>       Weight = theWeight;
>       Price = thePrice;
>       Model = theModel;
>       Size = theSize;
>     }
>
>
>     public int getTheWeight()
>     {
>
>         return Weight;
>     }
>     public double getThePrice()
>     {
>         return Price;
>     }
>     public String getTheModel()
>     {
>         return Model;
>     }
>     public String getTheSize()
>     {
>         return Size;
>     }

Yet another addition to the other remarks: some of the types look 
suspicious and might be better changed, depending on the intended usage 
of the class.

int for weight might be OK, but if it is in kilograms and needs to 
express grams (i.e. fractional values) a double might be more 
appropriate.  Definitively state the unit in the JavaDoc.

You can get easily into trouble when representing prices as double. 
Apart from the missing currency (again: state in JavaDoc if it is fixed) 
the impedance mismatch between binary representation of double and 
decimal usage of prices might cause trouble when doing calculations.

Using String for a size seems quite wrong.  Either size is represented 
by some abstraction (e.g. S, M, L, XL, XXL) or by some measurement 
(16cm) so for the former you would use an enum and for the latter a 
numeric type or a type combining a measurement and a unit.

Kind regards

	robert


-- 
remember.guy do |as, often| as.you_can - without end
http://blog.rubybestpractices.com/

Back to comp.lang.java.programmer | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

can someone chk is this code ok and if i can make it better please state how SuperGiirl <kainattshafiq90@gmail.com> - 2017-01-06 12:38 -0800
  Re: can someone chk is this code ok and if i can make it better please state how SuperGiirl <kainattshafiq90@gmail.com> - 2017-01-06 12:52 -0800
    Re: can someone chk is this code ok and if i can make it better please state how Andreas Leitgeb <avl@logic.at> - 2017-01-06 21:11 +0000
      Re: can someone chk is this code ok and if i can make it better please state how SuperGiirl <kainattshafiq90@gmail.com> - 2017-01-06 14:02 -0800
  Re: can someone chk is this code ok and if i can make it better please state how Eric Sosman <esosman@comcast-dot-net.invalid> - 2017-01-06 16:15 -0500
    Re: can someone chk is this code ok and if i can make it better please state how Robert Klemme <shortcutter@googlemail.com> - 2017-01-07 14:16 +0100
  Re: can someone chk is this code ok and if i can make it better please state how lewbloch@gmail.com - 2017-01-06 17:23 -0800
  Re: can someone chk is this code ok and if i can make it better please state how Robert Klemme <shortcutter@googlemail.com> - 2017-01-07 14:23 +0100
  Re: can someone chk is this code ok and if i can make it better please state how galt_57@hotmail.com - 2017-01-07 11:39 -0800

csiph-web