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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T20:38:09+00:00 2026-05-25T20:38:09+00:00

So I have to write a program that will take formulas from the user

  • 0

So I have to write a program that will take formulas from the user and calculate them.

    Age, Height, fights, (age+height)*fights <- user defined
    10, 5, 10, 150 <- I calculate this 
    1, 2, 1, 3 <- I calculate this 

But now let say I change the values around and I want the formula column to update dynamically is there anyway to go about doing that ? I am storing by each row into an array list which is array list of array list. Any advice or guidance would be really helpful thank you 🙂

  • 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-25T20:38:09+00:00Added an answer on May 25, 2026 at 8:38 pm

    We can revise this to make a simple engine

    public interface Function<T> {
        T operate(Map<String,T> values);
    }
    
    public class Calculation<T> {
    
         private Map<String,T> values;
    
         private Function<T> function;
    
         public Calculation(Map<String,T> values, Function<T> function) {
             this.values = new HashMap<String,T>(values);
             this.function = function;
         }
    
         public T calculate() {
             return function.operate(Collections.unmodifiableMap(values));
         }
    
         // assume setters and getters are in place to manipulate the backing map and the functor object
    
    }
    

    With this in place, we can define various functions and calculations

    public static void main(String[] args) {
        Function<Integer> original = new Function<Integer>() {
            public Integer operate(Map<String,Integer> values) {
                // these will throw exceptions if they don't exist, which is desired
                // granted it's NullPointerException instead of IllegalStateException, but close enough for this example
                int age = values.get("age").intValue();
                int height = values.get("height").intValue();
                int fights = values.get("fights").intValue();
                return (age+height)*fights;
            }
        };
        Map<String,Integer> map = new Map<String,Integer>();
        map.put("age",10);
        map.put("height",100);
        map.put("fights",25);
        Calculation<Integer> calc = new Calculation<Integer>(map,original);
    
        // later someone can replace either the values in the backing map
        // or replace the function altogether to get a new function
    }
    

    The problem comes when you try to make it not only user defined, but user entered. As in, a user could define the function as being one of a set of functions you have pre-entered. In this case, you’ll need to have a parser that turns something like this:

    value + (other + (something * that)) / wazook
    

    into this:

    EquationBuilder<Integer> eb = new EquationBuilder<Integer>();
    eb.append(map.get("value"));
    eb.append(OPERATOR.PLUS);
    // etc
    return eb.evaluate();
    

    But that may be beyond the scope of your assignment. Or maybe it’s not.

    Hopefully this is a little closer to your requirements than my previous example.

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

Sidebar

Related Questions

I need to write a program that will take a existing local windows user,
for an assignment I have to write a program that will take in an
I have to write a program that read from a file that contains the
I have a class assignment where I have to write a program that will
Problem: I want to write a process that will allow a user to take
I am trying to write a program that will take the users input value
I need to write a program, that will ask a user to enter a
I have to write a program that sniffs network packets (part1-the simple part). And
I wanted to write a program that test if two files are duplicates (have
I have been assigned wit the task to write a program that takes a

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.