Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

I have this code below, but I don\'t understand why it is not working. What am I

ID: 3830636 • Letter: I

Question

I have this code below, but I don't understand why it is not working. What am I doing wrong? I keep recieving the message "Team cannot be resolved to a type". I have no clue what to do in this code.

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

public class Project
{
public static Scanner scan = new Scanner(System.in);
Scanner sc = new Scanner(System.in).useDelimiter(" ");
static LinkedList<Team> list = new LinkedList<Team>();
  
@SuppressWarnings("resource")
public static void main(String[] args) throws Exception {
BufferedReader reader = null; // create variables
ArrayList<String> myFileReader = new ArrayList<String>();
System.out.println("Enter a file of your favorite list of NBA teams (Use the path directory)");
String path = scan.next();
File file = new File(path);
reader = new BufferedReader(new FileReader(file));
String text = null;
while ((text = reader.readLine()) != null) {
myFileReader.add(text);
}
// adds teams to list
for (int i = 0; i < myFileReader.size(); i++) {
Team team = new Team(myFileReader.get(i), 0, "");
list.add(team);
}
System.out.println("Teams in list are: ");
// prints list
for (int i = 0; i < list.size(); i++) {
System.out.println(list.get(i).getName());
}
System.out.println();
System.out.println("If you would like to add/delete a Team, enter yes or no?");
String answer = "";
boolean error = false;
answer = scan.next();
answer = answer.toLowerCase();
do {
try {
if (answer.equals("yes")) {
error = false;
additional();
} else if (answer.equals("no")) {
error = false;
break;
} else {
error = true;
}
} catch (Exception e) {
e.printStackTrace();
error = true;
}
} while (error == true);
boolean rankError = false;
String comment = "";
int[] rank = new int[list.size()];
for (int i = 0; i < list.size(); i++) {
rank[i] = 0;
}
for (int i = 0; i < list.size(); i++) {
Scanner sc = new Scanner(System.in);
System.out.println("Enter rank for " + list.get(i).getName());
do{
try{
int r = sc.nextInt();
if (r > 0 && r <= list.size()) {
addRank(list.get(i).getName(), r, rank);
rankError = false;
} else {
System.out.println("Number to rank is out of bounds! Try again!");
rankError = true;
}
}catch(Exception e){
rankError = true;
e.printStackTrace();
}
}while(rankError == true);
System.out.println("Comments for this Team?");
String s = sc.next();
s += sc.nextLine();
list.get(i).setComment(s);
}
  
Collections.sort(list);
  
int currentRanking = 1;
for(int i = 0; i < list.size(); i++){
list.get(i).setRank(currentRanking);
currentRanking++;
}
  
System.out.println("team " + "Rank " + "Comments");
for (int i = 0; i < list.size(); i++) {
  
System.out.println(list.get(i).getName() + " " + list.get(i).getRank() + " " + list.get(i).getComment());
}
try {
File outfile = new File("C://users/KillaQ/downloads/listoffavorites.txt");
if (!outfile.exists()) {
outfile.createNewFile();
}
FileWriter fw = new FileWriter(outfile.getAbsoluteFile());
BufferedWriter bw = new BufferedWriter(fw);
for (int j = 0; j < list.size(); j++) {
bw.write(list.get(j).getName() + " " + list.get(j).getRank() + " " + list.get(j).getComment());
bw.newLine();
}
bw.close();
} catch (IOException e) {
e.printStackTrace();
}
boolean gameError = true;
while(gameError == true){
System.out.println("Do you want to play again? Enter 'Yes' or 'No'");
String input = scan.next();
if (playagain(input) == 1) {
  
System.out.println("Enter a file of your favorite list of teams (Use the path directory)");
String name = scan.next();
File doc = new File(name);
reader = new BufferedReader(new FileReader(doc));
// adds teams to list
/* for (int i = 0; i < myFileReader.size(); i++) {
Team team = new Team(myFileReader.get(i), 0, "");
list.add(team);
}
**/
System.out.println("teams in list are: ");
// prints list
for (int i = 0; i < list.size(); i++) {
System.out.println(list.get(i).getName() + " " + list.get(i).getRank() + " " + list.get(i).getComment());
}
System.out.println("If you would like to add/delete a team, enter yes or no?");
Scanner keyboard = new Scanner(System.in);
String title = "";
boolean fail = false;
//title = scan.next();
title = keyboard.nextLine();
title = title.toLowerCase();
do {
try {
if (title.equals("yes")) {
fail = false;
additional();
} else if (title.equals("no")) {
fail = false;
break;
} else {
fail = true;
}
} catch (Exception e) {
e.printStackTrace();
fail = true;
}
} while (error == true);
boolean wrong = false;
String say = "";
int[] holder = new int[list.size()];
for (int i = 0; i < list.size(); i++) {
holder[i] = 0;
}
for (int i = 0; i < list.size(); i++) {
Scanner sc = new Scanner(System.in);
System.out.println("Enter rank for " + list.get(i).getName() + " " + list.get(i).getComment());
do{
try{
int a = sc.nextInt();
if (a > 0 && a <= list.size()) {
addRank(list.get(i).getName(), a, holder);
wrong = false;
} else {
System.out.println("Number to rank is out of bounds! Try again!");
wrong = true;
}
}catch(Exception e){
wrong = true;
e.printStackTrace();
}
}while(wrong==true);
System.out.println("Comments for this team?");
String y = sc.next();
y += sc.nextLine();
String temp=list.get(i).getComment();
temp+= (" " + y + " ");
list.get(i).setComment(temp) ;
  
}
} else if (playagain(input) == 0) {
gameError = false;
System.out.print("Goodbye");
break;
}
Collections.sort(list);
  
int cRank = 1;
for(int i = 0; i <list.size(); i++){
list.get(i).setRank(cRank);
cRank++;
}
System.out.println("team " + "Rank " + "Comments");
for(int i = 0; i < list.size(); i++){
System.out.println(list.get(i).getName() + " " + list.get(i).getRank() + " " + list.get(i).getComment());
}
  
try{
File output = new File("C://users/KillaQ/downloads/listoffavorites.txt");
if(!output.exists()){
output.createNewFile();
}
FileWriter f = new FileWriter(output.getAbsoluteFile());
BufferedWriter b = new BufferedWriter(f);
for(int j =0; j < list.size(); j++){
b.write(list.get(j).getName() + " " + list.get(j).getRank() + " " + list.get(j).getComment());
b.newLine();
}
b.close();
}catch(Exception e){
e.printStackTrace();
}
}
  
}
public static void addRank(String team, int r, int[] rank) {
ListIterator<Team> ptr = list.listIterator();
// if its 0, puts rank CORRECT
if (rank[r - 1] == 0) {
rank[r - 1] = 1;
for (int i = 0; i < list.size(); i++) {
if (list.get(i).getName().equals(team)) {
list.get(i).setRank(r);
  
}
}
return;
// if its not 0, check if all following spots are 1, if so go to
// next loop
// if not all spots are 1,put rank as spot and increment all
// following spots
} else {
for (int i = r; i < list.size(); i++) {
if (rank[i] == 1) {
continue;
}
if (rank[i] == 0) {
rank[i] = 1;
for (int j = 0; j < list.size(); j++) {
if (list.get(j).getRank() >= r) {
list.get(j).rank++;
}
if (list.get(j).getName().equals(team)) {
list.get(j).rank = r;
return;
}
}
}
}
// if all following spots are 1, put rank as next open spot above
for (int f = list.size() - 1; f >= 0; f--) {
if (rank[f] == 0) {
rank[f] = 1;
for (int m = 0; m < list.size(); m++) {
if (list.get(m).getName().equals(team)) {
list.get(m).rank = f + 1;
System.out.println("Space is unavailable. team moved to rank " + f);
return;
}
}
}
}
}
}
public static int playagain(String inp) {
if (inp.equals("Yes")) {
return 1;
} else {
return 0;
}
}
public static void additional() {
String reply = "";
boolean addError = false;
System.out.println("Add or delete?");
//reply = scan.next();
do {
try {
   reply = scan.next();
if (reply.equals("add")) {
// do something
addError = false;
System.out.println("What is the name of the team you want to add?");
scan.nextLine();
String name = scan.nextLine();
Team team = new Team(name, 0, "");
list.add(team);
} else if (reply.equals("delete")) {
// delete something
addError = false;
System.out.println("What team do you want to remove?");
String name = scan.next();
int count = list.size();
for (int i = 0; i < count - 1; i++) {
if (list.get(i).getName().equals(name)) {
list.remove(i);
}
}
} else {
System.out.println("Enter add or delete!");
addError = true;
}
} catch (Exception e) {
e.printStackTrace();
addError = true;
}
} while (addError == true);
}
}

Explanation / Answer

Hi Friend, You program is using Team Object.

I have defined Team object.

You can modify according to your need.

Please add this file along with your program. It will compile

class Team implements Comparable<Team>{

  

   private String name;

   int rank;

   private String comment;

   public Team(String name, int rank, String comment) {

       super();

       this.name = name;

       this.rank = rank;

       this.comment = comment;

   }

   public String getName() {

       return name;

   }

   public int getRank() {

       return rank;

   }

   public String getComment() {

       return comment;

   }

   public void setName(String name) {

       this.name = name;

   }

   public void setRank(int rank) {

       this.rank = rank;

   }

   public void setComment(String comment) {

       this.comment = comment;

   }

   @Override

   public int compareTo(Team o) {

       if(rank > o.rank)

           return 1;

       else if(rank < o.rank)

           return -1;

       else

           return 0;

   }

}