Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6744873
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T12:08:09+00:00 2026-05-26T12:08:09+00:00

I did a lot of Java programming and then dropped it and did a

  • 0

I did a lot of Java programming and then dropped it and did a bunch of ruby. Now I am back in Java and I am wondering whether my programming style is strange.

My code below feels very verbose to me, and the question is it reasonably idiomatic Java?
Any suggestions/improvements that you would recommend?


    final static int FORCE_RIGHT = 0;
    final static int FORCE_DOWN = 1;
    final static int FORCE_LEFT = 2;
    final static int FORCE_UP = 3;
    final static int IMP_RIGHT = 4;
    final static int IMP_DOWN = 5;
    final static int IMP_LEFT = 6;
    final static int IMP_UP = 7;


    public void applyForce(int dir) {
        counter++;
        Vector2 vect = new Vector2();
        switch (dir) {
            case FORCE_RIGHT: vect = new Vector2(3.0f, 0.0f); break;
            case IMP_RIGHT: vect = new Vector2(1.0f, 0.0f); break;
            case FORCE_LEFT: vect = new Vector2(-3.0f, 0.0f); break;
            case IMP_LEFT: vect = new Vector2(-1.0f, 0.0f); break;
            case FORCE_UP: vect = new Vector2(0.0f, -3.0f); break;
            case IMP_UP: vect = new Vector2(0.0f, -1.0f); break;
            case FORCE_DOWN: vect = new Vector2(0.0f, 3.0f); break;
            case IMP_DOWN: vect = new Vector2(0.0f, 1.0f); break;
        }
        Vector2 place = body.getWorldCenter();
        if (dir == FORCE_RIGHT || dir == FORCE_LEFT || dir == FORCE_DOWN || dir == FORCE_UP) 
            { 
            body.applyForce(vect, place);
            }
        else 
            { 
            body.applyLinearImpulse(vect, place);
            }
        Log.v("CAR", "Applied force: " + dir + "("+counter+")");
    }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T12:08:10+00:00Added an answer on May 26, 2026 at 12:08 pm

    Here are my improvement suggestions:

    • enums are smarter, since you can also apply behaviour, for example in your log you’d not only see a number
    • instead of the switch statement you could apply a more generic algorithm, but it’s not necessarily better, since it then is more difficult to understand and change, even if it comes with less lines of code
    • no need to do new Vector2() if you call the constructor again afterwards
    • use consistent code formatting (e.g. place to put {, space charachters, …)
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am really new to GUI programming in Java, I did a lot of
I did a lot of PHP programming in the last years and one thing
I see a lot of legacy .Net 1.1-style code at work like in example
A few years ago I did a lot of work with CGI.pm. I'm evaluating
After searching a lot i did not get any answers and finally i had
Lot of googling did not help me! Are there any good dictionary web based
There were a lot of promises and hopes, but did MS actually get around
I have been noticing __construct a lot with classes. I did a little reading
Did you ever had a bug in your code, you could not resolve? I
Dear Ladys and Gentleman, I did my homework, I've googled a lot and I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.