Assume you have the following text file:
players.txt
Pikachu,10 Geodude,50 Zubat,75 Marowak,37
Each line contains a player's name and starting health, separated by a comma (,).
Write a method called createPlayers which reads the lines from that file and returns an array of Player objects matching the properties in the input file. Assume you have access to the Inclass we've been using to read text from an input file, and that it has been correctly imported at the top of your program. using java programming language.
Hello, here is the answer to your question:
import java.io.*;
import java.util.*;
class Player
{
String name;
String Health;
Player(String name,String Health)
{
this.name=name;
this.Health=Health;
}
static ArrayList<Player> createPlayers()
throws IOException
{
ArrayList<Player> players = new
ArrayList<Player>();
File f = new File("players.txt");
try (BufferedReader br = new BufferedReader(new
FileReader(f)))
{
String line;
while ((line = br.readLine()) != null)
{
String[] lineSplit =
line.split(",");
players.add(new
Player(lineSplit[0],lineSplit[1]));
}
}
return players;
}
}
class Main
{
public static void main(String[] args) throws IOException
{
ArrayList<Player> answer =
Player.createPlayers();
for(int i=0;i<answer.size();i++)
{
Player player = answer.get(i);
System.out.println("Player name:"+
player.name + ", Player health" + player.Health);
}
}
}
What I have exactly done is created a Player class and created a static method of createPlayer() as asked. The main program has a driver code to test the method.
Hope this helps!
Assume you have the following text file: players.txt Pikachu,10 Geodude,50 Zubat,75 Marowak,37 Each line contains a...
Use basic C++
3. A text file, superstars.txt, contains statistics on cricket players. For each player, the file contains the player's first name, last name, number of matches played, total number of runs scored, number of times the player scored 100 runs in a match, and the number of wickets taken. The last row of data in the file contains the word "END" only. Some rows are shown below 30 11867 164 Chanderpaul Shivnarine 34 11912 130 Lara Brian 73...
In this Assignment assume that you have a text file with numbers separated by newlines. you want to read the numbers in and add them up. since we want to be flexible on the type and size of numbers we can handle, we will use double floating point. Text file contains following numbers 8 3 6.5 9 0 assume that the files are well-formed: it will contain only valid numbers separated by newlines. Using C language
java ASAP Assume that you have tracked daily minutes of you work out for a week. Save the following data into a text file in a notepad. 50 10 36 11 47 30 Write a java program that reads the minutes for a week from the text file that you created. Read the minutes from the input file into the array in one execution of the program.write a java method to find out the maximum and minimum values. Your program...
A hotel keeps records of its sales in a text file (called "hotel.txt"). Each line contains the following information separated by semicolons (":"): The client's name, the service sold (such as Dining, Conference, ...), and the amount of the sale. The figure below shows a few lines of input file. Write a Java program that reads such a file to display some information on the Hotel. You are requested to use lambda expression and streams to display the following information...
****Using C language***** Assume you have an input file with 10 characters. Scan these values into an appropriate array. Convert all the characters into Upper Case, then find their ascii value (like done in the homework) and save to a new array, order these values from highest to lowest. Save to file called “upper.txt” Convert all the characters into Lower Case, then find their ascii value (like done in the homework) and save to a new array, order these values...
Write a Java program to read customer details from an input text file corresponding to problem under PA07/Q1, Movie Ticketing System The input text file i.e. customers.txt has customer details in the following format: A sample data line is provided below. “John Doe”, 1234, “Movie 1”, 12.99, 1.99, 2.15, 13.99 Customer Name Member ID Movie Name Ticket Cost Total Discount Sales Tax Net Movie Ticket Cost Note: if a customer is non-member, then the corresponding memberID field is empty in...
Using C programming For this project, you have been tasked to read a text file with student grades and perform several operations with them. First, you must read the file, loading the student records. Each record (line) contains the student’s identification number and then four of the student’s numerical test grades. Your application should find the average of the four grades and insert them into the same array as the id number and four grades. I suggest using a 5th...
Program Language: PYTHON Consider the following file structure: each line of the file contains a word. The words are in sorted order. For example, a file might look like this apple apple apple apple banana bargain brick brick sample sample simple text text text Write a program that asks the user for a filename with this structure. The program's job is to write the sequence of words to another file, without any duplicates. Name the output file result.txt. Each word is...
Overview These exercises will allow you to have some practice with basic Java file Input/Output. In addition, you will also have an opportunity to have more practice with methods and arrays. Objectives Practice with programming fundamentals Variables - Declaration and Assignment Primitive types Arithmetic Expressions Simple keyboard input and text display output Branching - if-elseif-else syntax Loops - simple while loops, nested while loops Methods - functions and procedures ArrayLists - collections of variables File I/O Works towards the following...
The question asks you to assume that your input file is an English text that may contain any character that appears on keyboard of a computer. The task is to read each character from the input file and after encrypting it by adding an integer value n (0 < n < 128) to the character, to write the encrypted character to output file. We are supposed to use command line arguments and utilize argc, and argv parameters in main function...