Question
NEED HELP CORRECTING ERROR IN JAVA Hello, I need help correcting this error in JAVA I am not sure if I have something formatted wrong
NEED HELP CORRECTING ERROR IN JAVA
Hello,
I need help correcting this error in JAVA
I am not sure if I have something formatted wrong or what. I thought the error was due to quotation marks being single or double, but that didn't fix it either.
ERROR BELOW:
Tests Event method addAmounts()
Compilation failed
Compilation failed
java:6: error: incompatible types: char cannot be converted to String event.addAmount('T', 10); ^
java:7: error: incompatible types: char cannot be converted to String event.addAmount('D', 20); ^
java:8: error: incompatible types: char cannot be converted to String event.addAmount('E', 30); ^
Note: Some messages have been simplified; recompile with -Xdiags:verbose to get full output 3 errors
Tests Event method calcEventProfit()
Compilation failed
Compilation failed
java:6: error: incompatible types: char cannot be converted to String event.addAmount('T', 100);
java:7: error: incompatible types: char cannot be converted to String event.addAmount('D', 200); ^
java:8: error: incompatible types: char cannot be converted to String event.addAmount('E', 160); ^
Note: Some messages have been simplified; recompile with -Xdiags:verbose to get full output 3 errors
EventManager.java
/**
* Program description
* @
*/
import java.util.Scanner;
import java.io.File;
import java.io.FileNotFoundException;
import java.text.DecimalFormat;
public class EventManager {
public static void main(String[] args) {
Scanner keyboard = new Scanner(System.in);
System.out.println("Enter filename:");
String filename=keyboard.nextLine();
Scanner eventFile;
try {
eventFile = new Scanner(new File(filename));
Event event=new Event();
while(eventFile.hasNextLine()){
String line=eventFile.nextLine();
String[] values=line.split("\\s");
String amountType=values[0];
double amount=Double.parseDouble(values[1]);
DecimalFormat format=new DecimalFormat("0.00");
event.addAmount(amountType,amount);
System.out.println("Line read: "+values[0]+" "+format.format(amount));
}
System.out.println("Done reading file "+filename);
event.displayTotals();
double eventProfit=event.calcEventProfit();
DecimalFormat format=new DecimalFormat("0.00");
if(eventProfit>=0){
System.out.println(" Event generated a profit of $ "+format.format(eventProfit));
}else{
System.out.println(" Event generated a loss of $ "+format.format(eventProfit));
}
keyboard.close();
eventFile.close();
} catch (FileNotFoundException e) {
System.err.println("Could not open input file "+filename+" Program exiting.");
}
}
}
Event.java
import java.text.DecimalFormat;
/**
*
*
*
* Class description
*
*
*
* @author
*
*
*
*/
public class Event {
private double ticketSales; // total profit from event ticket sales
private double donations; // total profit from event donations
private double expenses; // total expenses to put on the event
DecimalFormat format = new DecimalFormat("0.00");
public Event() {
ticketSales = 0;
donations = 0;
expenses = 0;
}
public double getTicketSales() {
return ticketSales;
}
public double getDonations() {
return donations;
}
public double getExpenses() {
return expenses;
}
// Add your code here (and do not delete any of the above code)
public void addAmount(String amountType, double amount) {
if(amountType.equals("T")){
ticketSales+=amount;
}else if(amountType.equals("D")){
donations+=amount;
}else if(amountType.equals("E")){
expenses+=amount;
}else{
System.out.println("Invalid Amount type");
}
}
public void displayTotals() {
System.out.println();
System.out.printf("Total ticket sales: %10s ", format.format(ticketSales));
System.out.printf("Total donations: %13s ", format.format(donations));
System.out.printf("Total expenses: %14s ", format.format(expenses));
}
public double calcEventProfit() {
return (ticketSales + donations - expenses);
}
}
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