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 8931311
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T09:05:16+00:00 2026-06-15T09:05:16+00:00

I wrote a program to work from the console in Eclipse and the terminal

  • 0

I wrote a program to work from the console in Eclipse and the terminal window in Linux. I am now transforming it into an Android app and I have the basic functionality of the Android UI done up until the point where it needs to use the logic from the Java file of the program I wrote. All of my inputs from the Java file are currently from the keyboard (from Scanners).

My question is: how do I transform this to get it work with the user interaction of the app?

The only input would be from the built in NumberPicker. The Java file starts from the main method: public static void main(String[] args) {)

For example:

Sample Android Code:

public class Source1 extends Activity {

@Override
protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.source1_layout);
        Intent intent = getIntent();
        int pickerValue = intent.getIntExtra("numEntered", 0);
}

Sample Java Code from program (Test.java):

public class Test {

    public static void main(String[] args) {

    System.out.println("Enter number: ");
    Scanner reader = new Scanner(System.in);
    int num = reader.nextInt();
    ...
    }
}

How do I pass pickerValue into the main method of the Test class (starting the logic of the main method)? I want num = pickerValue; in the main method (replacing the Scanner). How is this done?

Also, will the print statements I have, System.out.println(...);, translate directly into the Android UI and print on the screen or do I have to modify those?

  • 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-06-15T09:05:18+00:00Added an answer on June 15, 2026 at 9:05 am

    You should try to separate the UI from the logic. Extract the part where you’re computing something based on inputs from the part where you actually gather the input. That way, the logic methods (or classes) can be reused with several input-gathering methods.

    For example, a Calculator class should not have the following methods:

    /**
     * asks for two numbers A and B, reads them from the keyboard, and displays the result 
     * of A^B on the screen
     */
    public void power() {...}
    
    /**
     * asks for a number A, reads it from the keyboard, and displays the square root
     * of A on the screen
     */
    public void squareRoot() {...}
    

    Instead, it should be separated into two classes:

    public class Calculator {
        /**
         * returns a^b
         */
        public double power(double a, double b) {...}
    
        /**
         * returns the square root of a
         */
        public double squareRoot(double a) {...}
    }
    
    public class ConsoleCalculator {
        private Calculator calculator;
    
        public ConsoleCalculator(Calculator calculator) {
            this.calculator = calculator;
        }
    
        /**
         * asks for two numbers A and B, reads them from the keyboard, uses
         * the calculator to compute A^B, and displays the result on the screen
         */
        public void power() {...}
    
        /**
         * asks for a number A, reads it from the keyboard, uses the calculator to
         * compute the square root of A and displays the result on the screen
         */
        public void squareRoot() {...}
    }
    

    This way, it’s easy to build an AndroidCalculator, because the hard-core math logic is encapsulated in a Calculator class, which doesn’t care about where the inputs come from.

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

Sidebar

Related Questions

I have a Win32 console program that I wrote and it works fine. The
I wrote a program with java and mysql and now i want to have
i wrote program to connect oracle database 11g for my android application to store
I wrote a program for downloading an image from web using AsyncTask in service
I wrote a program called Hello.py that looks like this: import pygame, sys from
Not sure what's going on here. I have an Windows console app written in
I wrote one program that load a text file. it work well. I try
hey i am currently converting my functions from console program to windows service program
I need to write a simple program for work that does the following: read
I want to write a little program which is able to work with Google

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.