Question

Use java programming for the following questions to have the solutions ready within today Jan 3...

Use java programming for the following questions to have the solutions ready within today Jan 3 2020 at or before 7:00PM GMT+8 time zone:

Question 13

Some service fees (% of asset amount) of two investment companies are shown in the following tables:

Company A:

Service Fee Type

Fee

Management Fee

1.5

Subscription Fee

5.0

Redemption Fee

1.0

Company B:

Service Fee Type

Fee

Platform Fee

0.2

Management Fee

1.0

Subscription Fee

2.0

l1QyQM7s7M7t7ewl8ntvmjWbGqxkgR5oBcqQZIEetvddae2b23jPz9D3wTfe+DZt3uXfrvQzQossALbo

The above information is to be stored in two maps (Map<String, Double>) referenced by companyA and companyB for Company A and Company B respectively. The service fee type is assumed to be unique in each map and it is the key of it.

  1. Assume that there are many entries in the map referenced by companyA. Using an enhanced for loop and an array, write a program segment to store the number of service fee types in each fee category using an element of the array. The fee categories are "fee <= 0.5", "0.5 < fee <= 1.0", and "fee > 1.0".
  2. Assume there are many entries in the maps and one company can have some service fee types not available in the other company. Write a program segment with an enhanced for loop to print out the name of each service fee available in both of the companies (A and B) and its lowest fee. For example, the string "Subscription Fee, 2.0" is printed when we are considering "Subscription Fee".
0 0
Add a comment Improve this question Transcribed image text
Answer #1

// TEXT CODE

import java.util.HashMap;
import java.util.Map;

public class CompanyService {

    public static void main(String[] args){

        // Solving part A)

        // creating companyA map reference
        Map<String, Double> companyA = new HashMap<>();

        // creating companyB map reference
        Map<String, Double> companyB = new HashMap<>();

        // adding companyA service information
        companyA.put("Management Fee", 1.5);
        companyA.put("Subscription Fee", 5.0);
        companyA.put("Redemption Fee", 1.0);

        // adding companyB service information
        companyB.put("Platform Fee", 0.2);
        companyB.put("Management Fee", 1.0);
        companyB.put("Subscription Fee", 2.0);



        // solving part B)

        // creating an array to store the number of service fee types in each three fee categories
        int[] serviceTypesCount = new int[3];

        // using enhanced for loop to get the number of service fee types
        for(Map.Entry<String, Double> entry: companyA.entrySet()){

            // if category is "fee <= 0.5" store count at index 0
            if(entry.getValue() <= 0.5)
                serviceTypesCount[0]++;

            // if category is "0.5 < fee <= 1.0" store count at index 1
            if(0.5 < entry.getValue() && entry.getValue() <= 1.0 )
                serviceTypesCount[1]++;

            // if category is "fee > 1.0" store count at index 2
            if(entry.getValue() > 1.0)
                serviceTypesCount[2]++;

        }

        // printing number of service fee types of each category
        System.out.println(".......Number of service fee types in each fee category for companyA........");
        System.out.println("Category \"fee <= 0.5\" count is: " + serviceTypesCount[0]);
        System.out.println("Category \"0.5 < fee <= 1.0\" count is: " + serviceTypesCount[1]);
        System.out.println("Category \"fee > 1.0\" count is: " + serviceTypesCount[2]);



        // Solving part C)
        System.out.println("\nPrinting the name of each service fee available in both of the companies (A and B) and its lowest fee.");
        for (Map.Entry<String, Double> companyAEntry: companyA.entrySet()){

            String key1 = companyAEntry.getKey();

            // check if key1 is present in companyB or not
            if(companyB.containsKey(key1)){
                // get the lowest fee
                double minFee = 0.0;
                if(companyA.get(key1) < companyB.get(key1)){
                   minFee = companyA.get(key1);
                }else minFee = companyB.get(key1);

                //  print out the name of each service fee available in both of the companies (A and B) and its lowest fee
                System.out.println(key1 + " " + minFee);
            }
        }
    }
}

// SCREENSHOT OF CODE

import java.util.HashMap; import java.util.Map; public class Company Service { public static void main(String[] args) { // soserviceTypesCount[2]++; // printing number of service fee types of each category System.out.println(.......Number of service

// OUTPUT

.......Number of service fee types in each fee category for companyA.... Category fee <= 0.5 count is: 0 Category 0.5 < fe

Add a comment
Know the answer?
Add Answer to:
Use java programming for the following questions to have the solutions ready within today Jan 3...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Some service fees (% of asset amount) of two investment companies are shown in the following...

    Some service fees (% of asset amount) of two investment companies are shown in the following tables: Company A: Service Fee Type Fee Management Fee 1.5 Subscription Fee 5.0 Redemption Fee 1.0 Company B: Service Fee Type Fee Platform Fee 0.2 Management Fee 1.0 Subscription Fee 2.0 The above information is to be stored in two maps (Map<String, Double>) referenced by companyA and companyB for Company A and Company B respectively. The service fee type is assumed to be unique...

  • Use java programming for the following questions to have the solutions ready within today Jan 3...

    Use java programming for the following questions to have the solutions ready within today Jan 3 2020 at or before 8:00PM GMT+8 time zone: Question 10 Declare a local String variable id and initialize it with your 8-digit student ID in string form. What is the output of the following program segment? String str = id + " "; // two spaces System.out.println(str.indexOf("5") + " + " + str.substring(0,2) + "\n" + str.trim().substring(5)+ "#"); The class List below is in...

  • Use java programming for the following questions to have the solutions ready within today Jan 3...

    Use java programming for the following questions to have the solutions ready within today Jan 3 2020 at or before 8:00PM GMT+8 time zone: Question 5 A method secret() of a class F is shown below: public int secret(String[] stringArray, int n) { int num = 0; for (int i=0; i<stringArray.length; i++) if (stringArray[i].indexOf("a", n) >= 0) num++; return num; } A program segment using the method is: F f = new F(); String[] array01 = {"an", "easy", "exam", "on",...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT