java
Part 1
Create a NetBeans project that asks for a file name. The file should contain an unknown quantity of double numeric values with each number on its own line. There should be no empty lines. Open the file and read the numbers. Print the sum, average, and the count of the numbers. Be sure to label the outputs very clearly. Read the file values as Strings and use Double.parseDouble() to convert them.
Part 2
Create a NetBeans project containing a menu-driven program. The menu items should be "Add Player", "Show All Players", and "Exit".
For "Add Player", ask the user to enter a player name and the player's numeric score. The score should be a positive integer. Store the player record to a CSV file where all the records are kept.
For "Show All Players", print the list of players and their scores.
For "Exit", confirm that the user wishes to exit.
Hint: Read the CSV file into an ArrayList of player objects. When you add a player, add it to the ArrayList and then rewrite the entire list. This is the easiest way to ensure that you do not lose any of the data.
Note: Could you plz go through this code and let me
know if u need any changes in this.Thank You
_________________
Part1)
// Numbers.txt
45.57
65.67
87.76
65.45
34.56
89.90
99.87
76.66
55.54
37.77
88.83
65.54
______________________
// ReadFileNos.java
import java.io.File;
import java.io.FileNotFoundException;
import java.util.Scanner;
public class ReadFileNos {
public static void main(String[] args) {
//Declaring variables
String line,filename;
int cnt = 0;
double num, sum = 0, avg;
/*
* Creating an Scanner class object
which is used to get the inputs
* entered by the user
*/
Scanner sc = new
Scanner(System.in);
System.out.print("Enter Filename
:");
filename=sc.next();
try {
//Open the input
file
Scanner file=new
Scanner(new File(filename));
while
(file.hasNext()) {
line = file.nextLine();
sum += Double.parseDouble(line);
cnt++;
}
sc.close();
avg = sum /
cnt;
System.out.printf("Sum :%.2f\n" , sum);
System.out.printf("Average :%.2f\n" , avg);
System.out.println("The Count of Numbers :" + cnt);
} catch (FileNotFoundException
e) {
System.out.println(e);
}
}
}
______________________
Output;
Enter Filename :Numbers.txt
Sum :813.12
Average :67.76
The Count of Numbers :12
______________________
2)
// playerData.csv
James |
67 |
Thomas |
90 |
Mike |
87 |
Jimmy |
78 |
Clark |
65 |
Jack |
98 |
Billy |
94 |
Bob |
85 |
// Player.java
public class Player {
private String name;
private int score;
public Player(String name, int score) {
this.name = name;
this.score = score;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getScore() {
return score;
}
public void setScore(int score) {
this.score = score;
}
@Override
public String toString() {
return "Player Name=" + name + ",
Score=" + score;
}
}
_______________________
// Test.java
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileWriter;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Scanner;
public class Test {
public static void main(String[] args) {
String name;
int score;
/*
* Creating an Scanner class object
which is used to get the inputs
* entered by the user
*/
Scanner read = new
Scanner(System.in);
ArrayList<Player> arl = new
ArrayList<Player>();
try {
Scanner sc = new
Scanner(new File("playerData.csv"));
while
(sc.hasNext()) {
name = sc.nextLine();
score = Integer.parseInt(sc.nextLine());
Player p = new Player(name, score);
arl.add(p);
}
sc.close();
while (true)
{
System.out.println("1.Add Player");
System.out.println("2.Display All
Players");
System.out.println("3.Exit.");
System.out.print("Enter Choice :");
int choice = read.nextInt();
switch (choice) {
case 1: {
read.nextLine();
System.out.print("Enter
Player Name :");
name = read.nextLine();
while(true)
{
System.out.print("Enter Score
:");
score = read.nextInt();
if(score<0)
{
System.out.println("** Invalid.Must be positive **");
}
else
break;
}
Player p = new Player(name,
score);
arl.add(p);
try {
FileWriter
fw = new FileWriter(new File("playerData.csv"));
for (int i
= 0; i < arl.size(); i++) {
fw.write(arl.get(i).getName() + "\n");
fw.write(arl.get(i).getScore() + "\n");
}
fw.close();
} catch (IOException e)
{
System.out.println(e);
}
continue;
}
case 2: {
System.out.println("Displaying Players data :");
for (int i = 0; i <
arl.size(); i++) {
System.out.println(arl.get(i));
}
continue;
}
case 3: {
break;
}
default: {
System.out.println("**
Invalid Choice **");
continue;
}
}
break;
}
} catch (FileNotFoundException
e) {
System.out.println(e);
}
}
}
_________________________
Output:
1.Add Player
2.Display All Players
3.Exit.
Enter Choice :1
Enter Player Name :Billy
Enter Score :94
1.Add Player
2.Display All Players
3.Exit.
Enter Choice :1
Enter Player Name :Bob
Enter Score :85
1.Add Player
2.Display All Players
3.Exit.
Enter Choice :2
Displaying Players data :
Player Name=James, Score=67
Player Name=Thomas, Score=90
Player Name=Mike, Score=87
Player Name=Jimmy, Score=78
Player Name=Clark, Score=65
Player Name=Jack, Score=98
Player Name=Billy, Score=94
Player Name=Bob, Score=85
1.Add Player
2.Display All Players
3.Exit.
Enter Choice :3
_______________Could you plz rate me well.Thank
You
java Part 1 Create a NetBeans project that asks for a file name. The file should...
#PLEASE WRITE THE CODE IN JAVA! THANK YOU IN ADVANCE! Write a program that manages a list of up to 10 players and their high scores in the computer's memory. Use two arrays to manage the list. One array should store the players' names, and the other array should store the players' high scores. Use the index of the arrays to correlate the names with the scores. Your program should support the following features: a. Add a new player and...
In this project, you will use functions and dictionaries to track basketball players and their respective points, then display statistics of points made. You will need three functions as follows: def freeThrowMade(playerDictionary, playerName) - this function will add 1 point to the player's total score def twoPointMade(playerDictionary, playerName) - this function will add 2 points to the player's total score def threePointMade(playerDictionary, playerName) - this function will add 3 points to the player's total score Each of these functions has...
signature 1. Create a new NetBeans Java project. The name of the project has to be the first part of the name you write on the test sheet. The name of the package has to be testo You can chose a name for the Main class. (2p) 2. Create a new class named Address in the test Two package. This class has the following attributes: city: String-the name of the city zip: int - the ZIP code of the city...
JAVA Write a program that prompts the user to enter a file name, then opens the file in text mode and reads it. The input files are assumed to be in CSV format. The input files contain a list of integers on each line separated by commas. The program should read each line, sort the numbers and print the comma separated list of integers on the console. Each sorted list of integers from the same line should be printed together...
create a new Java application called "WeightedAvgWithExceptions" (without the quotation marks), according to the following guidelines and using try-catch-finally blocks in your methods that read from a file and write to a file, as in the examples in the lesson notes for reading and writing text files. Input File The input file - which you need to create and prompt the user for the name of - should be called 'data.txt', and it should be created according to the instructions...
Java - In NetBeans IDE: • Create a class called Student which stores: - the name of the student - the grade of the student • Write a main method that asks the user for the name of the input file and the name of the output file. Main should open the input file for reading . It should read in the first and last name of each student into the Student’s name field. It should read the grade into...
Create a java program that reads an input file named Friends.txt containing a list 4 names (create this file using Notepad) and builds an ArrayList with them. Use sout<tab> to display a menu asking the user what they want to do: 1. Add a new name 2. Change a name 3. Delete a name 4. Print the list or 5. Quit When the user selects Quit your app creates a new friends.txt output file. Use methods: main( ) shouldn’t do...
This java assignment will give you practice with classes, methods, and arrays. Part 1: Player Class Write a class named Player that stores a player’s name and the player’s high score. A player is described by: player’s name player’s high score In your class, include: instance data variables two constructors getters and setters include appropriate value checks when applicable a toString method Part 2: PlayersList Class Write a class that manages a list...
JAVA please Java problem that has to be in doubly linked list. It is game problem that I have to keep of the players' scores. this should have a Java blueprint class named player It should have two fields, the name and score and include the constructors, toString() method, and getters and setters. Scores must be kept in ascending order (smallest at the front ) in a doubly linked list. It has menu as well: Load original data Print the...
Case Study Baseball Team Manager. CMSC 135 Python Chapter 7 Assignment: Use a file to save the data Update the program so it reads the player data from a file when the program starts andwrites the player data to a file anytime the data is changed What needs to be updated: Specifications Use a CSV file to store the lineup. Store the functions for writing and reading the file of players in a separate module than the rest of the...