Question
Any little bit of information will be helpful. Thank you.
Problem Statement You are to develop a program to read MotoGP rider information from an input file. You will need a MotoGpRid
Sample Input File and Corresponding Output File sample input text file Rossi Valentino 46 Italy Yamaha 198 3 0 1 4 Marquez Ma
Problem Statement You are to develop a program to read MotoGP rider information from an input file. You will need a MotoGpRider class whose instances will be used to store the statistics for a MotoGP motorcycle racer. The Rider class will have attributes for last name, first name, racing number, nation, motorcycle make, world championship points, world championship position, and an array that stores the number of top finishes (number of 1" place finishes, number of 2 place finishes, and number of 3d place finishes). You must read the MotoGP rider information from an input file. Each line of the input file will contain single rider's name and information, in the order the information is listed above. All information on the line will be separated by spaces. a Operations for the MotoGpRider class: Provide a default constructor o default string values are "unknown" o default integer values are 0 Read a rider from a single line of the file (The input file should be passed to the read method. You will need to pass it by reference.) Get methods for any data the test driver might need to print later A method to calculate the total number of top 3 finishes A method to return the rider's full name (first name followed by last name) A method to print the rider information to an output file (output file should be passed to the print method) To store multiple MotoGP riders, you are to implement a RiderList data structure/data type that stores riders using an internal array in the class. Read each rider from the input file and then add to the list. Your RiderList structure should hold a maximum of 10 riders. You must track the number of riders actually stored in the list, since the data file could contain fewer or greater than 10 riders. You will need to make sure the list is not full before adding a new rider. You may assume there are no errors in the data. I will not leave data out or put non-numeric data in numeric fields. You must implement the following operations on your List along with any other utility functions you might need. You may also need to add operations to your rider to encapsulate i/o operations to the class. Operations for the RiderList class: Default Constructor - initialize the number of riders to 0 Add a rider to the List-add items in the order they were found in the file. No sorting is necessary in this version of the program. Iterate through the List so that you can get each item out for printing You must implement reset(), hasNext() and getNext() on your list for this to work. Clear out the list to make it empty Test if a list is Full Get the size of the list
Sample Input File and Corresponding Output File sample input text file Rossi Valentino 46 Italy Yamaha 198 3 0 1 4 Marquez Marc 93 Spain Honda 321 1 9 4 1 Dovizioso Andrea 4 Italy Ducati 245 2 4 32 Vinales Maverick 12 Spain Yamaha 1934 113 Note-there should be NO blank lines after the last line of data in an input file. sample output text file 2018 World Championship Statistics RIDER NAME NUMBER POINTS POSITION Valentino Rossi: 46 198 Marc Marquez : Andrea Dovizioso: Maverick Vinales: 93 321 245 12 193 4 RIDERS Valentino Rossi Number Motorcycle : 46 : Yamaha : Italy Top 3 Finishes: 5 Nation Marc Marquez Number 93 Honda : Spain Motorcycle Nation Top 3 Finishes: 14 Andrea Dovizioso Number Motorcycle Nation : 4 : Ducati : Italy Top 3 Finishes: 9 Maverick Vinales : 12 Number a Motorcycle Nation : Spain Top 3 Finishes: 5
0 0
Add a comment Improve this question Transcribed image text
Answer #1

MotoGpRider.java

import java.util.*;

public class MotoGpRider{
String lastname;
String firstname;
int racingnumber;
String nation;
String motorcycle;
int w_champ_points;
int w_champ_position;
int[] finishes = new int[3];

public MotoGpRider(){

this.lastname = null;
this.firstname=null;
this.racingnumber = 0;
this.nation = null;
this.motorcycle = null;
this.w_champ_points = 0;
this.w_champ_position = 0;


}

public MotoGpRider(String lastname,String firstname,int racingnumber,String nation,String motorcycle,int w_champ_points,int w_champ_position,int[] finishes){

this.lastname = lastname;
this.firstname=firstname;
this.racingnumber = racingnumber;
this.nation = nation;
this.motorcycle = motorcycle;
this.w_champ_points = w_champ_points;
this.w_champ_position =w_champ_position;
this.finishes = finishes;

}

public String getLastname(){

return lastname;
}

public String getFirstname(){
return firstname;
}

public int getRacingnumber(){
return racingnumber;
}

public String getNation(){
return nation;
}

public String getMotorcycle(){
return motorcycle;
}

public int getW_champ_points(){
return w_champ_points;
}

public int getW_champ_position(){
return w_champ_position;
}

public int[] getFinishes(){

return finshes;
}

public String getName(){
return firstname+lastname;
}

public int total_num_of_finishes(){
int count=0;
for(int i=0; i<finishes.length; i++){
count = count + finishes[i];
}

return count;
}

}

RiderList.java

import java.util.*;
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;

pulic class RiderList{


public ArrayList<MotoGpRider> addRider(String inputfile){

int count=0;
String lastname;
String firstname;
int racingnumber;
String nation;
String motorcycle;
int w_champ_points;
int w_champ_position;
int[] finishes = new int[3];

ArrayList<MotoGpRider> riderss = new ArrayList<MotoGpRider>();
MotoGpRider rider ;

try (BufferedReader br = new BufferedReader(new FileReader(FILENAME))) {

String str;
String[] arr = new String[10];

while ((str = br.readLine()) != null) {

if(count<=10){

arr = str.split(" ");

lastname = arr[0];
firstname = arr[1];
racingnumber = Integer.parseInt(arr[2]);
nation = arr[3];
motorcycle = arr[4];
w_champ_points = Integer.parseInt(arr[5]);
w_champ_position = Integer.parseInt(arr[6]);
finishes[0] = Integer.parseInt(arr[7]);
finishes[1] = Integer.parseInt(arr[8]);
finishes[2] = Integer.parseInt(arr[9]);

rider = new MotoGpRider(lastname,firstname,racingnumber,nation,motorcycle,w_champ_points,w_champ_position,finishes);
  
riderss.add(rider);
}
else
break;
}

return riderss;

} catch (IOException e) {
e.printStackTrace();
}

}

public void printRider(String outputfilepath,ArrayList<MotoGpRider> riderss){
   File fout = new File(outputfilepath);
   FileOutputStream fos = new FileOutputStream(fout);

   BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(fos));

  
       bw.write("2018 World Championship Statistics");
       bw.newLine();

bw.write("RIDER NAME \t \t NUMBER \t \t POINTS \t \t POSITION ");
   bw.newLine();

bw.write("----------------------------------------------------------------------------------------------------");
bw.newLine();

for(int i=0; i<riderss.size(); i++){

bw.write(riderss[i].getName() + "\t \t" + riderss[i].getRacingnumber() + "\t \t" + riderss[i].getW_champ_points() + "\t \t" + riderss[i].getW_champ_position() );
bw.newLine();
}
bw.newLine();
  
bw.write("RIDERS");
bw.newLine();

for(int i=0; i<riderss.size();i++){
  
bw.write("---------------------------------");
bw.newLine();
bw.write(riderss[i].getName());
bw.newLine();
bw.write("---------------------------------");
bw.newLine();
bw.write("Number \t :" + riderss[i].getRacingnumber());
bw.newLine();
bw.write("MotorCycle \t :" + riderss[i].getMotorcycle());
bw.newLine();
bw.write("Nation \t :" + riderss[i].getNation());
bw.newLine();
bw.write("TOP 3 Finishes \t :" + riderss[i].total_num_of_finishes());
bw.newLine();
bw.newLine();

}

   bw.close();
}

public static void main(String[] args){
int numberof_riders = 0;
ArrayList<MotoGpRider> riders = new ArrayList<MotoGpRider>();

String inputfile = ""; // Write your input text file path here.

riders = addRider(inputfile); // Reading data from text file and storing them into array.

String outputfilepath = ""; // Write your output text file path here.

printRider(outputfilepath,riders); // Printing the required data into output file whose path is mentioned in above line.


}


}

If you left with any doubt. Feel free to ask.

Add a comment
Know the answer?
Add Answer to:
Any little bit of information will be helpful. Thank you. Problem Statement You are to develop a program to read Mo...
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
  • // READ BEFORE YOU START: // You are given a partially completed program that creates a...

    // READ BEFORE YOU START: // You are given a partially completed program that creates a list of students for a school. // Each student has the corresponding information: name, gender, class, standard, and roll_number. // To begin, you should trace through the given code and understand how it works. // Please read the instructions above each required function and follow the directions carefully. // If you modify any of the given code, the return types, or the parameters, you...

  • Problem statement For this program, you are to implement a simple machine-learning algorithm that uses a...

    Problem statement For this program, you are to implement a simple machine-learning algorithm that uses a rule-based classifier to predict whether or not a particular patient has diabetes. In order to do so, you will need to first train your program, using a provided data set, to recognize a disease. Once a program is capable of doing it, you will run it on new data sets and predict the existence or absence of a disease. While solving this problem, you...

  • Write in JAVA Get Familiar with the Problem Carefully read the program description and look at...

    Write in JAVA Get Familiar with the Problem Carefully read the program description and look at the data file to gain an understanding of what is to be done. Make sure you are clear on what is to be calculated and how. That is, study the file and program description and ponder! Think! The Storm Class Type Now concentrate on the Storm class that we define to hold the summary information for one storm. First, look at the definition of...

  • WRITE JAVA PROGRAM Problem Statement You are required to write a stock price simulator, which simulates...

    WRITE JAVA PROGRAM Problem Statement You are required to write a stock price simulator, which simulates a price change of a stock. When the program runs, it should do the following:  Create a Stock class which must include fields: name, symbol, currentPrice, nextPrice, priceChange, and priceChangePercentage.  The Stock class must have two constructor: a no-argument constructor and a constructor with four parameters that correspond to the four fields. o For the no-argument constructor, set the default value for...

  • Topics: list, file input/output (Python) You will write a program that allows the user to read...

    Topics: list, file input/output (Python) You will write a program that allows the user to read grade data from a text file, view computed statistical values based on the data, and to save the computed statistics to a text file. You will use a list to store the data read in, and for computing the statistics. You must use functions. The data: The user has the option to load a data file. The data consists of integer values representing student...

  • ANY HELP PLEASE. PLEASE READ THE WHOLE INSTRUCTION THANK YOU Write a program GS.java that will...

    ANY HELP PLEASE. PLEASE READ THE WHOLE INSTRUCTION THANK YOU Write a program GS.java that will be responsible for reading in the names and grades for a group of students, then reporting some statistics about those grades. The statistics to be gathered are the number of scores entered, the highest score and the name(s) of the student(s) who earned that score, the lowest score and the name(s) of the student(s) who earned that score, and the average score for the...

  • Problem: You will write a program to compute some statistics based on monthly average temperatures for...

    Problem: You will write a program to compute some statistics based on monthly average temperatures for a given month in each of the years 1901 to 2016. The data for the average August temperatures in the US has been downloaded from the Climate Change Knowledge Portal, and placed in a file named “tempAugData.txt”, available on the class website. The file contains a sequence of 116 values. The temperatures are in order, so that the first one is for 1901, the...

  • Problem: You will write a program a C++ to compute some statistics based on monthly average...

    Problem: You will write a program a C++ to compute some statistics based on monthly average temperatures for a given month in each of the years 1901 to 2016. The data for the average August temperatures in the US has been downloaded from the Climate Change Knowledge Portal, and placed in a file named “tempAugData.txt”, available on the class website. The file contains a sequence of 116 values. The temperatures are in order, so that the first one is for...

  • Use C++ For this week’s lab you will write a program to read a data file...

    Use C++ For this week’s lab you will write a program to read a data file containing numerical values, one per line. The program should compute average of the numbers and also find the smallest and the largest value in the file. You may assume that the data file will have EXACTLY 100 integer values in it. Process all the values out of the data file. Show the average, smallest, largest, and the name of the data file in the...

  • C++ ONLY This is your first ever program using object oriented methodology. In this assignment you...

    C++ ONLY This is your first ever program using object oriented methodology. In this assignment you will need to instantiate (create) object(s) and invoke their member functions to perform different tasks. The program is to keep track of customer orders and to create reports as needed. At minimum you will need several objects to be instantiated throughout the program such as: An OrderProcessor object Order objects (stored in an array) Let’s get to class design now. Class Design class Order:...

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