At the end of the code, there is a sc.nextDouble();
that has been causing the error, it is of the correct data type, I do not know what I need to do fix this error. If you copy the code the error is at line 117. I have been inputting the correct format, but keep getting the error.
I have put two **
signs around the line that has been causing the error
//importing java utility tools
import java.util.Scanner;
public class Movie {
//creating private variables for theMovie object parameters
private double price;
private String schedule;
private String movieName;
//creating a movie constructors that takes in 3 parameters to create a
//movie object
Movie(String movieName, String schedule, double price){
this.movieName = movieName;
this.schedule = schedule;
this.price = price;
}
//creating a Default movie Constructor
Movie(){
movieName = "Frozen II";
price = 17.99;
schedule = "2:00-5:00pm";
}
//Creating a movie constructors that takes in parameters of a new Movie
Movie(Movie newMovie){
this.movieName = newMovie.movieName;
this.schedule = newMovie.schedule;
this.price = newMovie.price;
}
//Creating getters and setters to return and set the parameters of the Movie object
public String getMovieName(){
return movieName;
}
public void setMovieName(String movieName){
this.movieName = movieName;
}
public String getSchedule(){
return schedule;
}
public void setSchedule(String schedule){
this.schedule = schedule;
}
public double getPrice(){
return price;
}
public void setPrice(double price){
this.price = price;
}
//Creating the addPrice() method that adds the value passed
//and adds it the price of the movie.
public void addPrice(double p){
this.price += p;
}
//Creating the toString() method that returns the name, schedule and price
//of the movie
public String toString(){
return "Name: "+movieName+"\n"+
"Schedule "+schedule + "\n" +
"price $"+ price;
}
//Creating a boolean method that checks if Movie is equal to the m movie object
public boolean equals(Movie m) {
if (this.movieName.equals(m.movieName) && this.schedule.equals(m.schedule)
&& this.price == m.price) {
return true;
}
return false;
}
//creating the main method
public static void main(String[] args)throws Exception{
Scanner sc = new Scanner(System.in);
//welcome message
System.out.println("|------------------------------------|");
System.out.println("| Welcome to the Movie Program! |");
System.out.println("|------------------------------------|");
//Driver
Movie movie1 = new Movie();
//Prompting the user to enter the information of movie 2
System.out.println("Please enter the name, schedule and price of Movie 2:");
String name = sc.nextLine();
String schedule = sc.nextLine();
double price = sc.nextDouble();
//setting the parameters of movie to with the user given name, schedule and price
Movie movie2 = new Movie(name, schedule, price);
//setting movie 3 with the same details as movie 2 by using Movie 2 as the parameter refrence
Movie movie3 = new Movie(movie2);
System.out.println("Movie 1 is "+"\n"+movie1.toString());
System.out.println("Movie 2 is "+"\n"+movie2.toString());
System.out.println("Movie 3 is "+"\n"+movie3.toString());
//creating a boolean variable that checks the equality of movie 2 and movie 3
boolean equality = movie2.equals(movie3);
if (equality){
System.out.println("The movie \n"+movie2.toString()+"\n is equal to the Movie \n" +
movie3.toString());
}
//prompting the user to enter the information of Movie 1 and overriding the default Movie Constructor
System.out.println("Please enter the information of Movie 1");
name = sc.nextLine();
schedule = sc.nextLine();
**price = sc.nextDouble();**
//setting the name, schedule and price of movie 1
movie1.setMovieName(name);
movie1.setSchedule(schedule);
movie1.setPrice(price);
//adding the price of movie 3 to movie 2
movie2.addPrice((2/3)*movie3.price);
//printing out the new movie list information
System.out.println("Movie 1 info is \n"+movie1.toString());
System.out.println("Movie 2 info is \n"+movie1.toString());
System.out.println("Movie 3 info is \n"+movie1.toString());
//creating a double variable that contains the prices of movie 1, 2 and 3 added together
double totalPrice = movie1.price + movie2.price + movie3.price;
//printing out the total price of the movies
System.out.println("The total price of Movie 1, Movie 2 and Movie 3 is "+totalPrice);
//farewell message
System.out.println("|------------------------------------|");
System.out.println("| Thank you for using |");
System.out.println("| our Movie program! |");
System.out.println("|------------------------------------|");
}
}