Question
I have five different class: Menu.java , Competition.java , Dogs.java , Courses.java , and AppDriver.java. I have posted all classes separatly. I have a bunch
I have five different class:" Menu.java" ," Competition.java" , "Dogs.java" ," Courses.java" , and "AppDriver.java". I have posted all classes separatly. I have a bunch of errors and couldn't figure out what is going on, I need some expert to fix my homework. Thank you in advance.
//Menu.java
import java.io.File; import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.PrintWriter; import java.text.SimpleDateFormat; import java.util.ArrayList; import java.util.Date; import java.util.Scanner; import javax.swing.JOptionPane;
public class Menu {
Competition comp; // Menu-------------------------------------------------- public void runMenu() { comp = new Competition(); String input = JOptionPane.showInputDialog("1. Print report " + "2. Add a Dog " + "3. Exit " + "Enter a choice: "); while (!input.equals("3")) { switch(input) { case "1": printReport(); break; case "2": addDog(); break; case "3": System.out.println("Good bye!"); System.exit(0); default: System.out.println("Invalid choice"); break; } input = JOptionPane.showInputDialog("1. Print report " + "2. Add a Dog " + "3. Exit " + "Enter a choice: "); } } public void printReport() { System.out.println("Choose the course:"); System.out.println("Enter G for Gamblers, J for Jumpers, or T for Titling"); String choice = scanner.nextLine(); if (choice.equalsIgnoreCase("G")) { for (Courses c : courses) { if (c.getName().equalsIgnoreCase("Gamblers")) { printReport('G', c.getMaxTime()); } } } else if (choice.equalsIgnoreCase("J")) { for (Courses c : courses) { if (c.getName().equalsIgnoreCase("Jumpers")) { printReport('J', c.getMaxTime()); } } } else if (choice.equalsIgnoreCase("T")) { for (Courses c : courses) { if (c.getName().equalsIgnoreCase("Titling")) { printReport('T', c.getMaxTime()); } } } else { System.out.println("Invalid choice"); } } public void addDog() { System.out .println("Enter ID: (1 digit followed by a letter, followed by 3 digits)"); String id = scanner.nextLine(); if (id.length() != 5) { System.out.println("Invalid ID"); return; } else { /** * Checking if id is in proper format */ if (!(Character.isDigit(id.charAt(0)) && Character.isLetter(id.charAt(1)) && Character.isDigit(id.charAt(2)) && Character.isDigit(id.charAt(3)) && Character.isDigit(id.charAt(4)))) { System.out.println("Invalid ID"); return; } } System.out.println("Enter dog name: "); String name = scanner.nextLine(); try { System.out.println("Enter running time"); double runTime = Double.parseDouble(scanner.nextLine()); if (runTime <= 0) { System.out.println("Invalid run time"); return; } System.out.println("Enter penalty: "); double penalty = Double.parseDouble(scanner.nextLine()); if (penalty < 0) { System.out.println("Invalid penalty"); return; } System.out.println("Enter course code: "); String code = scanner.nextLine(); if (code.equalsIgnoreCase("G") || code.equalsIgnoreCase("J") || code.equalsIgnoreCase("T")) { Dogs d = new Dogs(id, name, runTime, penalty, code.charAt(0)); dogs.add(d); /** * Defining a printwriter object to append data to the file */ PrintWriter writer = new PrintWriter(new FileOutputStream(dogsFile,true)); writer.append(" " + id + " " + name + " " + runTime + " " + penalty + " " + code); writer.close(); System.out.println("Dog added"); } } catch (NumberFormatException e) { System.out.println("Invalid input"); } catch (Exception e) { System.out.println("Some error occured"); return; } }
}
//Competition.java
import java.io.File; import java.io.FileNotFoundException; import java.io.PrintWriter; import java.util.ArrayList; import java.util.Arrays; import java.util.Date; import java.util.Scanner;
import javax.swing.JOptionPane;
public class Competition { private ArrayList
//Dogs.java
public class Dogs {
private String id;
private String name;
private double runningTime;
private double penalty;
private char courseCode;
/***
* Parameterized constructor to initialize all data fields
*/
public Dogs(String id, String name, double runningTime, double penalty,
char courseCode) {
this.id = id;
this.name = name;
this.runningTime = runningTime;
this.penalty = penalty;
this.courseCode = courseCode;
}
/**
* getters and setters
*/
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public double getRunningTime() {
return runningTime;
}
public void setRunningTime(double runningTime) {
this.runningTime = runningTime;
}
public double getPenalty() {
return penalty;
}
public void setPenalty(double penalty) {
this.penalty = penalty;
}
public char getCourseCode() {
return courseCode;
}
public void setCourseCode(char courseCode) {
this.courseCode = courseCode;
}
}
//Courses.java
public class Courses {
private String name;
private double maximumTime;
/***
* Parameterized constructor to initialize all data fields
*/
public Courses(String name, double maximumTime) {
this.name = name;
this.maximumTime = maximumTime;
}
/**
* getters and setters
*/
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public double getMaxTime() {
return maximumTime;
}
public void setMaximumTime(double maximumTime) {
this.maximumTime = maximumTime;
}
}
//AppDrive.java
import java.io.FileNotFoundException;
public class AppDriver {
public static void main(String[] args) {
try {
Menu m=new Menu();
m.loadData();
m.showMenu();
} catch (FileNotFoundException e) {
System.out.println("File not found");
}
}
}
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started