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 9 of 9

Thread: How to solve this problem in Programming

  1. #1
    Junior Member yugioh's Avatar
    Join Date
    Jul 2020
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Unhappy How to solve this problem in Programming

    I'm a beginner, please note, I have the following problem and I didn't find a solution on how to solve it, I'm trying to create this, what is the most appropriate way to solve this?

    A bank has a portfolio of thousands of trades and they need to be categorized.
    A trade is a commercial negotiation between a bank and a client.
    Each trade has a value that indicates the transaction amount in dollars and a text indicating if the client´s sector is "Public" or "Private". They implement the following interface:

    interface ITrade
    {
    double Value { get; }
    string ClientSector { get; }
    }

    Currently, there are three categories:
    LOWRISK: Trades with value less than 1,000,000 and client from Public Sector
    MEDIUMRISK: Trades with value greater than 1,000,000 and client from Public Sector
    HIGHRISK: Trades with value greater than 1,000,000 and client from Private Sector

    Imagine you receive a list of trades and you need to return a list of categories as below:
    input: List<ITrade> portfolio
    output: List<string> tradeCategories

    Example:
    Input:
    Trade1 {Value = 2000000; ClientSector = "Private"}
    Trade2 {Value = 400000; ClientSector = "Public"}
    Trade3 {Value = 500000; ClientSector = "Public"}
    Trade4 {Value = 3000000; ClientSector = "Public"}
    portfolio = {Trade1, Trade2, Trade3, Trade4}

    Output:
    tradeCategories = {"HIGHRISK", "LOWRISK", "LOWRISK", "MEDIUMRISK"}

    Keep in mind that category rules may be added/removed/modified in the future and be highly complex.
    Please write your answer in pseudo-code showing clearly what classes, interfaces, methods and design patterns you would create/use to solve this problem. Also, object oriented programming is appreciated.

  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: How to solve this problem in Programming

    What have you tried? Do you have any specific java programming questions about your assignment?

    Be sure to wrap all posted code in code tags.
    http://www.java-forums.org/misc.php?do=bbcode#code
    If you don't understand my answer, don't ignore it, ask a question.

  3. #3
    Junior Member yugioh's Avatar
    Join Date
    Jul 2020
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: How to solve this problem in Programming

    the problem:

    Each trade has a value that indicates the transaction amount in dollars and a text indicating if the client´s sector is "Public" or "Private". They implement the following interface:

    interface ITrade
    {
    double Value { get; }
    string ClientSector { get; }
    }

    Currently, there are three categories:
    LOWRISK: Trades with value less than 1,000,000 and client from Public Sector
    MEDIUMRISK: Trades with value greater than 1,000,000 and client from Public Sector
    HIGHRISK: Trades with value greater than 1,000,000 and client from Private Sector

    Imagine you receive a list of trades and you need to return a list of categories as below:
    input: List<ITrade> portfolio
    output: List<string> tradeCategories

    Example:
    Input:
    Trade1 {Value = 2000000; ClientSector = "Private"}
    Trade2 {Value = 400000; ClientSector = "Public"}
    Trade3 {Value = 500000; ClientSector = "Public"}
    Trade4 {Value = 3000000; ClientSector = "Public"}
    portfolio = {Trade1, Trade2, Trade3, Trade4}

    Output:
    tradeCategories = {"HIGHRISK", "LOWRISK", "LOWRISK", "MEDIUMRISK"}

    Keep in mind that category rules may be added/removed/modified in the future and be highly complex.
    Please write your answer in pseudo-code showing clearly what classes, interfaces, methods and design patterns you would create/use to solve this problem. Also, object oriented programming is appreciated.

    what I tried: I read this whole tutorial that explains what pseudo code is and uses java as an example: https://www.geeksforgeeks.org/how-to...a-pseudo-code/, but I don't know how to do it.

    some code: if (Trade.index(I).tradeValue < 1000000 and Trade.index(I).client ==< publicSector) Print (low risk)

  4. #4
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: How to solve this problem in Programming

    Also posted at: https://www.dreamincode.net/forums/t...these-changes/

    Please read this: http://www.javaprogrammingforums.com...s-posting.html

    See my last post.

    I don't know how to do it.
    Can you ask your instructor for help with that?
    If you don't understand my answer, don't ignore it, ask a question.

  5. #5
    Junior Member yugioh's Avatar
    Join Date
    Jul 2020
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: How to solve this problem in Programming

    my instructor is on a 30-day vacation, I really need help

  6. #6
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: How to solve this problem in Programming

    What have you tried?

    Be sure to wrap all posted code in code tags.

    --- Update ---

    Also posted here: https://coderanch.com/t/732272/java/...amming#3406346
    If you don't understand my answer, don't ignore it, ask a question.

  7. #7
    Member
    Join Date
    Jan 2024
    Posts
    75
    Thanks
    0
    Thanked 4 Times in 4 Posts

    Default Re: How to solve this problem in Programming

    Sure, here's a solution in pseudo-code using object-oriented programming principles:

    ```plaintext
    // Define an interface for trade
    interface ITrade {
    double Value { get; }
    string ClientSector { get; }
    }

    // Define an enum for trade categories
    enum TradeCategory {
    LOWRISK,
    MEDIUMRISK,
    HIGHRISK
    }

    // Define a factory interface for creating trade categorizers
    interface ITradeCategorizerFactory {
    ITradeCategorizer CreateCategorizer();
    }

    // Define an interface for trade categorizers
    interface ITradeCategorizer {
    TradeCategory Categorize(ITrade trade);
    }

    // Define concrete implementations of trade categorizers for each category
    class LowRiskCategorizer : ITradeCategorizer {
    public TradeCategory Categorize(ITrade trade) {
    if (trade.Value < 1000000 && trade.ClientSector == "Public") {
    return TradeCategory.LOWRISK;
    }
    return null; // Or throw an exception for invalid trades
    }
    }

    class MediumRiskCategorizer : ITradeCategorizer {
    public TradeCategory Categorize(ITrade trade) {
    if (trade.Value >= 1000000 && trade.ClientSector == "Public") {
    return TradeCategory.MEDIUMRISK;
    }
    return null; // Or throw an exception for invalid trades
    }
    }

    class HighRiskCategorizer : ITradeCategorizer {
    public TradeCategory Categorize(ITrade trade) {
    if (trade.Value >= 1000000 && trade.ClientSector == "Private") {
    return TradeCategory.HIGHRISK;
    }
    return null; // Or throw an exception for invalid trades
    }
    }

    // Define a trade categorizer factory
    class TradeCategorizerFactory : ITradeCategorizerFactory {
    public ITradeCategorizer CreateCategorizer() {
    // Depending on requirements, this factory can be extended to return different categorizers
    return new LowRiskCategorizer();
    }
    }

    // Define a trade processor class to categorize trades
    class TradeProcessor {
    private ITradeCategorizerFactory _categorizerFactory;

    public TradeProcessor(ITradeCategorizerFactory categorizerFactory) {
    _categorizerFactory = categorizerFactory;
    }

    public List<string> CategorizeTrades(List


    ```plaintext
    ITrade> trades) {
    var categorizer = _categorizerFactory.CreateCategorizer();
    var tradeCategories = new List<string>();

    foreach (var trade in trades) {
    var category = categorizer.Categorize(trade);
    if (category != null) {
    tradeCategories.Add(category.ToString());
    }
    }

    return tradeCategories;
    }
    }

    // Usage:

    // Create a trade categorizer factory
    var categorizerFactory = new TradeCategorizerFactory();

    // Create a trade processor
    var tradeProcessor = new TradeProcessor(categorizerFactory);

    // Example trades
    var portfolio = new List

    ```plaintext
    ITrade> {
    new Trade { Value = 2000000, ClientSector = "Private" },
    new Trade { Value = 400000, ClientSector = "Public" },
    new Trade { Value = 500000, ClientSector = "Public" },
    new Trade { Value = 3000000, ClientSector = "Public" }
    };

    // Categorize trades
    var tradeCategories = tradeProcessor.CategorizeTrades(portfolio);

    // Output trade categories
    print(tradeCategories); // {"HIGHRISK", "LOWRISK", "LOWRISK", "MEDIUMRISK"}
    ```

    This solution provides a flexible and extensible approach using object-oriented principles. It allows for easy addition, removal, or modification of category rules in the future.

    For guidance with programming assignments, you can always seek assistance from various resources available online. There are platforms like programminghomeworkhelp.com where you can find support and guidance to enhance your coding skills and tackle challenging problems.

  8. #8
    Member
    Join Date
    Jan 2024
    Posts
    75
    Thanks
    0
    Thanked 4 Times in 4 Posts

    Default Re: How to solve this problem in Programming

    To solve this problem, we can use object-oriented programming principles and design patterns to create a flexible and scalable solution. Here's a pseudo-code solution:

    ```pseudo
    // Define the Trade interface
    interface ITrade
    {
    double Value { get; }
    string ClientSector { get; }
    }

    // Define the TradeCategory enum to represent different categories
    enum TradeCategory
    {
    LOWRISK,
    MEDIUMRISK,
    HIGHRISK
    }

    // Define the TradeCategorizer class responsible for categorizing trades
    class TradeCategorizer
    {
    // Method to categorize trades
    List<TradeCategory> CategorizeTrades(List<ITrade> portfolio)
    {
    List<TradeCategory> tradeCategories = new List<TradeCategory>();

    foreach (var trade in portfolio)
    {
    TradeCategory category = GetTradeCategory(trade);
    tradeCategories.Add(category);
    }

    return tradeCategories;
    }

    // Method to determine the category of a single trade
    TradeCategory GetTradeCategory(ITrade trade)
    {
    if (trade.Value < 1000000 && trade.ClientSector == "Public")
    {
    return TradeCategory.LOWRISK;
    }
    else if (trade.Value >= 1000000 && trade.ClientSector == "Public")
    {
    return TradeCategory.MEDIUMRISK;
    }
    else if (trade.Value >= 1000000 && trade.ClientSector == "Private")
    {
    return TradeCategory.HIGHRISK;
    }
    else
    {
    // Handle other cases if needed
    }
    }
    }

    // Usage
    void Main()
    {
    List<ITrade> portfolio = new List<ITrade>()
    {
    new Trade { Value = 2000000, ClientSector = "Private" },
    new Trade { Value = 400000, ClientSector = "Public" },
    new Trade { Value = 500000, ClientSector = "Public" },
    new Trade { Value = 3000000, ClientSector = "Public" }
    };

    TradeCategorizer categorizer = new TradeCategorizer();
    List<TradeCategory> tradeCategories = categorizer.CategorizeTrades(portfolio);

    // Output the trade categories
    foreach (var category in tradeCategories)
    {
    Console.WriteLine(category);
    }
    }
    ```

    This solution encapsulates the categorization logic within the `TradeCategorizer` class, providing a clear separation of concerns. It also allows for easy modification or extension of category rules in the future.

    Additionally, this solution offers a structured approach that can be easily adapted to accommodate future modifications or extensions of category rules. If you ever need further help with programming assignment, there are various resources available online to provide guidance and support, such as programminghomeworkhelp.com.

  9. #9
    Member Helium c2's Avatar
    Join Date
    Nov 2023
    Location
    Kekaha, Kaua'i
    Posts
    117
    Thanks
    1
    Thanked 3 Times in 3 Posts

    Default Re: How to solve this problem in Programming

    I know some Algebra and Trigonometry and Calculus. And you wanted to use Java programming to solve this problem? Slowly I'm coming along with Java programmers and what they do. I cannot see the programming implementation yet. As I'm more towards the iPhone use, cash registers, and the Basic Input/Output classes in Java. As for the solution? I don't know how this will work yet. Objected Oriented Programming.

    --- Update ---

    This is an engineering problem. At some server some where. The interface are from the 1.4 sdk kit. Java programming. Coming up with a programming solution I see several steps already. Separately, and in working form with the server and kit. Really nice conceptual problem. You wanted to figure out the whole programming problem though and solution. I can see how this is hard. Especially if you're doing business on the iPhone and this connects to a website. Java Programming.

Similar Threads

  1. Can someone solve this Java programming Project
    By TheNwoLegend in forum What's Wrong With My Code?
    Replies: 1
    Last Post: April 29th, 2019, 02:10 PM
  2. please solve the problem
    By liz in forum Threads
    Replies: 1
    Last Post: February 6th, 2014, 05:27 AM
  3. Replies: 3
    Last Post: September 23rd, 2013, 10:51 AM
  4. how do i solve this programming problem in dr java?
    By jennavg in forum What's Wrong With My Code?
    Replies: 4
    Last Post: April 8th, 2013, 12:22 PM
  5. [SOLVED] Easy error to solve in a minute. Help please, I don't want to fail Java Programming again.
    By ihatejava in forum What's Wrong With My Code?
    Replies: 6
    Last Post: November 15th, 2012, 04:30 PM

Tags for this Thread