Question

Lets get ready for the basketball tournament! Assume the class Bracket has the following interface: class...

Lets get ready for the basketball tournament! Assume the class Bracket has the following interface:

class Bracket
{
 public:
 Bracket(string location);
 string getdata() const;
 private:
 string location;
};

The function getdata should return the value of the attribute. Write the member functions for this class. ALSO - rewrite the interface so that the getdata function is virtual.

Create a class Team which is derived from the base class Bracket. Include a constructor that accepts the location (Bracket) and the team name which is a string attribute for the class. Also include a function getdata which returns the team name.

  1. Create a class Player which is derived from the base class Team. Include a constructor that accepts the location (Bracket), team name (Team) and the player name which is a string attribute for the class. Also include a function getdata which returns the player name.
  2. a. Write a main program that creates a vector v of Bracket* (pointer) objects by reading the data in from a file. The file (named tournament.txt) has the following format. Each line in the file has four string values (all without spaces)
    string1 string2 string3 string4
    
    • String1 indicates the type of the record - Bracket, Team, Player.
    • String2 is the Bracket name.
    • String3 is the Team name (if the record type is Bracket, the value is na).
    • String4 is the Player name (if the record type is Bracket or Team, the value is na).

    b. Process the vector v by applying the getdata function to each value object pointed to by elements of the vectori and outputing the result - one value per line.

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

import java.util.*;
import java.io.*;

import java.lang.String;


class Bracket
{
public:
Bracket(){
location = null;
}
String getdata(){
return location;
} const;
private:
String location;
}
class Team extends Bracket

{ private:
String teamName;
public:
  
Team(){
location = null;
teamName = null;
}
String getdata(String teamName){
return teamName;
  
}
//methods and fields
}
class Player extends Team{
private:
String playerName;
public:
Player(String location, String teamName, String playerName){
location = null;
teamName = null;
playerName = null;
}
String getdata(String playerName){
return playerName;
  
}
}
public class Main
{
  

   public static void main(String[] args) throws FileNotFoundException, IOException {
   Scanner inFile = null;
try {
inFile = new Scanner(new File("tournament.txt"));
} catch (FileNotFoundException e) {

e.printStackTrace();
}

   Vector<Bracket> sampleVec = new Vector<Bracket>();
   int size = 0;
   sampleVec.add("Bracket");
   size++;
   sampleVec.add("Team");
   size++;
   sampleVec.add("Player");
   size++;
   while (inFile.hasNextLine()) {
String nextLine = inFile.nextLine();
String[] BracketANDTeamANDPlayer = nextLine.split(" ");
sampleVec.add(BracketANDTeamANDPlayer[size++]);
  
}
   if(sampleVec[0].equals(sampleVec[3])){
   sampleVec.add(new Bracket());
   System.out.println(sampleVec.getdata());
   }
   else if(sampleVec[1].equals(sampleVec[3]){
   sampleVec.add(new Team());
   System.out.println(sampleVec.getdata());
   }
   else{
   sampleVec.add(new Player());
   System.out.println(sampleVec.getdata());
   }
   FileReader freader = new FileReader(filename);

BufferedReader inputFile = new BufferedReader(freader);

int flag = 1;

do {

temp = new CollegeStudent();

temp.readFromFile(inputFile);

if (temp.getName().compareTo("") != 0) {

temp.storeToVector();

} else


} while( flag != 0);

} // end main

   }
}

Add a comment
Know the answer?
Add Answer to:
Lets get ready for the basketball tournament! Assume the class Bracket has the following interface: class...
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
  • PYTHON 3.6 Overview In this assignment we implement a class called TripleString. It consists of a...

    PYTHON 3.6 Overview In this assignment we implement a class called TripleString. It consists of a few instance attribute and a few instance methods to support those attributes. In the next assignment, the TripleString class will help us create a more involved application. Before we do that though, we have to thoroughly test our TripleString implementation. Specifications The class TripleString will contain symbolic constants, instance attributes, and instance methods. ▶ Class symbolic constants This class has 3 symbolic constants, which...

  • Code Lab Help (C++)

    Write the interface (.h file) of a class Player containing:A data member name of type string .A data member score of type int .A member function called setName that accepts a parameter and assigns it to name . The function returns no value.A member function called setScore that accepts a parameter and assigns it to score . The function returns no value.A member function called getName that accepts no parameters and returns the value of name .A member function called...

  • Write a full class definition for a class named Player , and containing the following members: A data member name of t...

    Write a full class definition for a class named Player , and containing the following members: A data member name of type string . A data member score of type int . A member function called setName that accepts a parameter and assigns it to name . The function returns no value. A member function called setScore that accepts a parameter and assigns it to score . The function returns no value. A member function called getName that accepts no...

  • IN PYTHON Assignment Overview This assignment will give you experience on the use of classes. Understand...

    IN PYTHON Assignment Overview This assignment will give you experience on the use of classes. Understand the Application The assignment is to first create a class calledTripleString.TripleStringwill consist of threeinstance attribute strings as its basic data. It will also contain a few instance methods to support that data. Once defined, we will use it to instantiate TripleString objects that can be used in our main program. TripleString will contain three member strings as its main data: string1, string2, and string3....

  • C++ Assignment: Create a class called FitnessMember that has only one variable, called name. The FitnessMember...

    C++ Assignment: Create a class called FitnessMember that has only one variable, called name. The FitnessMember class should have a constructor with no parameters, a constructor with a parameter, a mutator function and an accessor function. Also, include a function to display the name. Define a class called Athlete which is derived from FitnessMember. An Athlete record has the Athlete's name (defined in the FitnessMember class), ID number of type String and integer number of training days. Define a class...

  • The class declaration (interface) and the function definitions (implementation) must be in separate files - the...

    The class declaration (interface) and the function definitions (implementation) must be in separate files - the interface or "header" file has a .hpp extension and the implementation has a .cpp extension. As usual, all data members should be private. Write a class called BankAccount that has: a string data member called customerName, a string data member called customerID, and a double data member called customerBalance a constructor that takes two strings and a double (name, ID, balance) and uses them...

  • Use c++ to code: Problem 1 Implement a class Clock whose get hours and get_minutes member functions return the current...

    Use c++ to code: Problem 1 Implement a class Clock whose get hours and get_minutes member functions return the current time at your location. To get the current time, use the following code, which requires that you include the <ctime>header time_t current_time time (e); ta local time - localtime(current, tine)i int hours -local_time->tm hour int minutes-local time->tm_min; Also provide a get_time member function that returns a string with the hours and minutes by calling the get_hours and get_minutes functions. Provide...

  • Implement the following class in interface and implementation files. A separate file (the main project file)...

    Implement the following class in interface and implementation files. A separate file (the main project file) shall have the main function that exercises this class. Create a class named Student that has three member variables: name - string that stores the name of the student numClasses - integer that tracks how many courses the student is currently enrolled in, this number must be between 1 and 100 ClassList - an array of strings of size 100 used to store the...

  • Write a class called Player that has four data members: a string for the player's name,...

    Write a class called Player that has four data members: a string for the player's name, and an int for each of these stats: points, rebounds and assists. The class should have a default constructor that initializes the name to the empty string ("") and initializes each of the stats to -1. It should also have a constructor that takes four parameters and uses them to initialize the data members. It should have get methods for each data member. It...

  • Write three object-oriented classes to simulate your own kind of team in which a senior member...

    Write three object-oriented classes to simulate your own kind of team in which a senior member type can give orders to a junior member type object, but both senior and junior members are team members. So, there is a general team member type, but also two specific types that inherit from that general type: one senior and one junior. Write a Python object-oriented class definition that is a generic member of your team. For this writeup we call it X....

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