Question

I need help with a java problem, I need the following method               ...

I need help with a java problem, I need the following method
                   Method that reads a file and creates a TreeMap, the key is the "salary" and the value is an object "Profesor"
                   my txt file is like this:
                       Harry smith   345677
                       andy Connor   123456

0 0
Add a comment Improve this question Transcribed image text
Answer #1

import java.io.File;
import java.util.Scanner;
import java.util.TreeMap;

public class MakeTreeMap {
   public static void main(String[] args) throws Exception {
       System.out.println(getTreeMap());
   }

   private static TreeMap<Double,String> getTreeMap() throws Exception{
       TreeMap<Double,String> res= new TreeMap<Double,String>();
       Scanner sc = new Scanner(new File("myFile.txt"));
       while(sc.hasNextLine()) {
           // reading first and last names and making it as full name
           String name=sc.next()+" "+sc.next();
           //reading salary from file
           double salary=sc.nextDouble();
           //adding to tree map salary as key and name as value
           res.put(salary, name);
       }
       return res;
   }
}

Console X - ** Es al 99 - <terminated > Make Tree Map (Java Application) C:\Program Files {123456.0=andy Connor, 345677.0=Har

Note : Please comment below if you have concerns. I am here to help you

If you like my answer please rate and help me it is very Imp for me

Add a comment
Know the answer?
Add Answer to:
I need help with a java problem, I need the following method               ...
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
  • I need help writing the following java Java Method below. I just need a method to...

    I need help writing the following java Java Method below. I just need a method to take a user inputted First or Last Name and return the associated phone number, thank you! import java.util.*; import java.io.*; class PhoneList { public static void main(String[] args) throws Exception { boolean loop = true; File file = new File("PhoneList_Data.txt"); FileWriter fw = new FileWriter(file, true); fw.write("PhoneList Data"); fw.write("\n" + "Last, First: 6041337567, 2181731566");    // do { } (loop)    fw.close(); } //...

  • Hey I need help on Java. I have to create a while loop that reads 5 fields in each row, nextInt, ...

    Hey I need help on Java. I have to create a while loop that reads 5 fields in each row, nextInt, nextInt, next, next, and nextLine. Then I have to instantiate a User object using those 5 fields and insert that object in the usersArr. I just need to see what this would look like if a text file with 5 fields for 5 users existed. Here's my code so far: int [] usersArr = new int[200];           System.out.print("Enter file name:...

  • I need help with this .java implementation: Implement an algorithm that given two sorted arrays of...

    I need help with this .java implementation: Implement an algorithm that given two sorted arrays of size m and n creates a sorted array of size (n + m) in O(n + m) time. The script must take as an input a command line argument specifying the name of a .txt file which will contain the arrays to be sorted. Each line in the .txt file will contain two arrays, with elements in arrays separated by commas and the arrays...

  • I need help parsing a large text file in order to create a map using Java....

    I need help parsing a large text file in order to create a map using Java. I have a text file named weather_report.txt which is filled with hundreds of different indexes. For example: one line is "POMONA SUNNY 49 29 46 NE3 30.46F". There are a few hundred more indexes like that line with different values in the text file and they are not delimited by commas but instead by spaces. Therefore, in this list of indexes we only care...

  • Using java in android studio, I need help in making a text to speech button that...

    Using java in android studio, I need help in making a text to speech button that reads off of my text view thanks for the help

  • Hallo! I have a problem in my code, I need help please in java code. My...

    Hallo! I have a problem in my code, I need help please in java code. My task is : Write a program that can read a text from a file and do frequency analysis on the letters that occur . To store information (frequency) you must use an array. Tip! The place where you collect the frequency of eg the letter A is the equivalent of the ASCII code of "A" ie 65. The array should be 127 elements. For...

  • Hi everyone! I need help on my Java assignment. I need to create a method that...

    Hi everyone! I need help on my Java assignment. I need to create a method that is called sumIt that will sum two values and will return the value.It should also invoke cubeIt from the sum of the two values. I need to change the currecnt program that I have to make it input two values from the console. The method has to be called sumIt and will return to the sum that will produce the cube of the sum...

  • I need help running this code. import java.util.*; import java.io.*; public class wordcount2 {     public...

    I need help running this code. import java.util.*; import java.io.*; public class wordcount2 {     public static void main(String[] args) {         if (args.length !=1) {             System.out.println(                                "Usage: java wordcount2 fullfilename");             System.exit(1);         }                 String filename = args[0];               // Create a tree map to hold words as key and count as value         Map<String, Integer> treeMap = new TreeMap<String, Integer>();                 try {             @SuppressWarnings("resource")             Scanner input = new Scanner(new File(filename));...

  • I need help to calculate the sum of this, i just don't know how...... file_name =...

    I need help to calculate the sum of this, i just don't know how...... file_name = input("What is the value-probability file? ")     with open(file_name , "r") as final:         for numbers in final:             split_function = numbers.split()             num_one = float(split_function[0])             num_two = float(split_function[1])             final = num_one * num_two             final_line = final So when my code runs the output looks like this : What is the value-probability file? hw3_part2_test1.txt -0.567032 -17.630715000000002 3.194056 4.398823 13.990935 I need all these numbers now to add to...

  • Hi ! I need help please, I want to write java code, but that is difficult...

    Hi ! I need help please, I want to write java code, but that is difficult for me. it is about using annotation, reflection and XLM_ file. Please help me! I want explaintion with code and I want to se result please! My assignment is! Using the annotations and reflection API write an XML file exporter for composite objects of any kind. That is, the exporter should rely only on the annotations in the class definitions of the composite objects...

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