Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 4 of 4

Thread: How can I make this code concise?

  1. #1
    Junior Member
    Join Date
    Sep 2013
    Location
    Tokyo
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Red face How can I make this code concise?

    Hello,

    I am a beginner of Java.
    I made this code but I think this code may be shorter.

    Could you help me?
    ----
    abstract class Shain{
    public abstract int getKyuuyo();
    }

    class Maneijya extends Shain{
    private int koteikyu =1000000;
    public int getKyuuyo(){
    return koteikyu;
    }
    }

    class Purogurama extends Shain{
    private int kihonkyu1=350000;
    private int jikankyu1=2000;
    private int zangyouJikan1=10;
    private int ptotal1=kihonkyu1+jikankyu1*zangyouJikan1;

    private int kihonkyu2=250000;
    private int jikankyu2=1500;
    private int zangyouJikan2=20;
    private int ptotal2=kihonkyu2+jikankyu2*zangyouJikan2;

    public int getKyuuyo(){
    return ptotal1+ptotal2;
    }
    }

    class Arubaito extends Shain{
    private int jikankyu1=1200;
    private int zangyouJikan1=120;
    private int atotal1=jikankyu1*zangyouJikan1;

    private int jikankyu2=1000;
    private int zangyouJikan2=150;
    private int atotal2=jikankyu2*zangyouJikan2;

    public int getKyuuyo(){
    return atotal1+atotal2;
    }
    }

    class KyuyoCal{
    public static void main(String args[]){
    Maneijya m=new Maneijya();
    Purogurama p=new Purogurama();
    Arubaito a=new Arubaito();

    System.out.println("給与の合計は、"+(m.getKyuuyo()+p.getK yuuyo()+a.getKyuuyo())+"です。");
    }
    }


  2. #2
    Member Kewish's Avatar
    Join Date
    Apr 2013
    Location
    Australia
    Posts
    116
    Thanks
    10
    Thanked 17 Times in 14 Posts

    Default Re: How can I make this code concise?

    Thanks to google translate I got "total salary" is. That is about all I got unfortunately. The names for your variables don't really help me out to see what you're doing. So I can't help.

    For example;
    private int koteikyu =1000000;
    I have no idea what this is.

    You should also surround your code with the 'code' or 'highlight' tags from the link I gave you earlier.

  3. #3
    Grand Poobah
    Join Date
    Mar 2011
    Posts
    1,545
    My Mood
    Grumpy
    Thanks
    0
    Thanked 167 Times in 158 Posts

    Default Re: How can I make this code concise?

    Depends upon what you mean by shorter. You can put all code on one line, thus shorter but very much wider and harder to read.

    Why do you care? Does the code compile, run and perform correctly? If so that is you care about right now. As you gain experience you will learn how some things can be improved upon but just concentrate on getting your code to work regardless of how many lines it takes.
    Improving the world one idiot at a time!

  4. #4
    Junior Member
    Join Date
    Sep 2013
    Location
    Tokyo
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: How can I make this code concise?

    Thank you for you two replies!

    This code is "Calculate total salary".
    I have to hand in this code to my tutor. I just wanted it to be better.
    But oh,yeah! Who cares! I agree with Junky!

    I will hand in this today.
    Thank you for your twos kind words.

Similar Threads

  1. Can I make this code better?
    By hrenfrow in forum What's Wrong With My Code?
    Replies: 2
    Last Post: January 23rd, 2013, 10:33 AM
  2. can someone please make this code
    By poldz123 in forum Java Theory & Questions
    Replies: 1
    Last Post: September 19th, 2012, 05:50 PM
  3. I NEED HELP, HOW TO MAKE THIS CODE!!!
    By tahsim in forum Member Introductions
    Replies: 1
    Last Post: March 20th, 2012, 09:05 AM
  4. How to make this code even simpler
    By blakmaze in forum What's Wrong With My Code?
    Replies: 1
    Last Post: October 30th, 2011, 03:00 PM
  5. need help to make my code flexible.
    By sagar474 in forum What's Wrong With My Code?
    Replies: 1
    Last Post: September 29th, 2011, 12:11 PM