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

  • Home
  • SEARCH
  • 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 6047799
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T07:23:30+00:00 2026-05-23T07:23:30+00:00

I recently wrote a Java playing card game and have all the game logic

  • 0

I recently wrote a Java playing card game and have all the game logic written within one Class called Game. Where possible I tried to keep all GUI handling outside of this class. I am now trying to convert this game to an Android application.

Within the playAutomaticTurn() method (used by both the Android Activity and the Java desktop application) I then call another method within Game if the computer player wishes to announce that they’ve won. This plays two sound effects dependent on the result using a SoundEffect class that I created (uses the javax.sound.sampled.* libraries).

Rather than completely rewrite the code to move the sound effects back to the calling method (I guess I’d have to return a status from my announceWin() method and in turn return this from playAutomaticTurn()) is there a succinct way to determine whether the main calling application is an Android one?

In this way I could put an if or case statement in place and handle the sound effects differently?

E.g.

if (androidApp) {
    playAndroidSoundEffect
} else {
    playJavaxSoundEffect();
}

Or is the only way to create a constant declaration at the start of the Class and compile it with different values for the Java and Android versions?

E.g. to compile a version for Android (without yet implementing the Android sounds)

private static final boolean SOUND = false;

//...

if (SOUND)
    playJavaxSoundEffect();

Thanks for any assistance and advice you can offer.

  • 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-23T07:23:31+00:00Added an answer on May 23, 2026 at 7:23 am

    Sparkling lots of ifs around your code is bad practice, I recommend creating interface(s) which capture the platform specific behavior, like

    interface SoundService {
       playSound(/* ... */);
    }
    

    This way you can create multiple implementations of your interfaces, including a trivial NoOp implementation for the lazy, and have all the platform specific code in very view places.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I recently wrote a DLL in C# (.Net 2.0) which contains a class that
I recently wrote a class for an assignment in which I had to store
I recently wrote a small tool to generate a class for each tier I
I have a Python script I recently wrote that I call using the command
I recently wrote a java program transforming a SVG document to HTML/ Canvas :
I recently wrote some data access methods (plain old Java) that use immutable objects
I recently wrote a parser in Python using Ply (it's a python reimplementation of
I recently wrote some javascript code that filled a drop down list based on
I recently wrote a piece of code which did SomeClass someObject; mysqlpp::StoreQueryResult result =
I recently wrote mailing list software in Ruby On Rails. I would like to

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.