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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T04:38:19+00:00 2026-06-04T04:38:19+00:00

public static void main(String[] args) throws FileNotFoundException { double agentID; String type; double price;

  • 0
public static void main(String[] args) throws FileNotFoundException {
    double agentID;
    String type;
    double price;
    Set<String> types = new TreeSet<String>();
    Map<Double, Double> agents = new TreeMap<Double, Double>();
    Scanner console = new Scanner(System.in);     
    String propertyID;
    double totalPrice = 0;

    System.out.print ("Please enter file name: ");
    String inputFileName = console.next();
    File inputFile = new File(inputFileName);
    Scanner in = new Scanner(inputFile);
    while (in.hasNextLine()) {
        propertyID = in.next();
        type = in.next(); 
        price = in.nextDouble();
        agentID = in.nextDouble();
        type = type.toUpperCase();   
        types.add(type);
        if (agents.containsValue(agentID)) {
            agents.put(agentID, agents.get(agentID)+price);
        }
        else {
            totalPrice = price;
            agents.put(agentID, totalPrice);
        }
    }
    in.close();
    System.out.println(types);
    System.out.println(agents);
}

I am trying to update map value of totalPrice if the value in agentID is already contained in the agents map. When I run the program it will output the initial value assigned to the key agentID but it will not output the totalPrice + price. I have looked over the questions here and looked over the API Docs, but I am not making any progress. Any help would be appreciated.

  • 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-04T04:38:20+00:00Added an answer on June 4, 2026 at 4:38 am

    It seems that you are trying to map the agentId with the price. So I think what you need to use is

    if (agents.containsKey(agentID)) { ... }
    

    See the official containsKey javadoc for more information.

    Please try to simplify the code in your questions (remove the file reading and other unneeded info) to make it easier to determine where the problem could be.

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

Sidebar

Related Questions

public static void main(String[] args) throws Exception { RSAKeyPairGenerator rsaKeyPairGen = new RSAKeyPairGenerator(); AsymmetricCipherKeyPair
public static void main(String[] args) throws IOException { String st3[]=new String[]{сто, двести, триста, sdf,
public static void main(String[] args) throws IOException, URISyntaxException,TransformerException { TransformerFactory factory = TransformerFactory.newInstance(); String
as the title. public static void main(String[] args) throws InterruptedException { Thread thread =
import java.io.*; import java.util.*; public class Readfilm { public static void main(String[] args) throws
public class Main { public static void main(String[] args){ Class2 class2Object = new Class2();
public class Loopname{ public static void main (String [] args){ String files []= new
import java.util.*; import java.io.*; public class LootGenerator{ public static void main (String[] args) throws
My code is as such: public static void main(String args[]) throws IOException { String
public class Test { public static void main(String[] args) throws Exception { String s1

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.