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
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;
}
}
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
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 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...
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));...
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 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! 1. I need some help with sorting string in a text file. My goal is to 1 shift left strings for string.length time. I was able to do that successfully. However, I am also trying to sort, using insertion sort , the resulting shifts. I store all shifts in a vector (or is it better to use an array?!) , and try to sort them that way, but my output is just the shifted strings but not sorted. Can...
Hi I was hoping to get some help with my code for this problem. I don't know how to correctly read a txt file and the difference between using string and cstring. My code is at the bottom please help thanks. 1. Create the following “data.txt” file. Each record consists of customer's name and their balance: Maria Brown 2100.90 Jeffrey Jackson 200.20 Bernard Smith 223.10 Matthew Davenport 1630.20 Kimberly Macias 19100.90 Amber Daniels 2400.40 The records in the file will...
[Java] I need help completing the method below. The instructions are also below. public int wordSearch(String word, String filename) { } - find the first time the word appears in a text file filename and returns the position of the word in the file(if its the first word in the file, method should return 1) - assume no punctuation in file - assume all whitespace is either a new line or single space - do not include the times that...
Need help with java programming. Here is what I need to do: Write a Java program that could help test programs that use text files. Your program will copy an input file to standard output, but whenever it sees a “$integer”, will replace that variable by a corresponding value in a 2ndfile, which will be called the “variable value file”. The requirements for the assignment: 1. The input and variable value file are both text files that will be specified in...
do this in java and as simple as possible as i am new to this. The lab10.xml is here and the zip file is here Thank you Create a program called ReadNames FromXML that reads the file lab10.xml (also in a ZIP file here for download), stores each string of the file into an array list and displays each name. On the documentation page for XMLDecoder you will find that exceptions can arise when this program runs: FileNotFoundException: when the...