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

create a class Movie that reads in the name of a movie and its length in minutes

ID: 3920766 • Letter: C

Question

create a class Movie that reads in the name of a movie and its length in minutes, entered one line after the other at the console. The program must print the name of the film followed by runs for, then its length in hours and minutes. e.g. if the inputs are Finding Nemo and 104, then the program would output Finding Nemo runs for 1 hour and 44 minutes. If the movie is less than one hour, you should not print hours, if it is greater than one hour you should print hours instead of hour. Likewise for minutes; if there are no minutes, do not print them, if there is one, print minute, and if more than one, print minutes.

Thanks

Explanation / Answer

/*As You have not mentioned the Language for the Code ,The code is Written in Java.

*The Java File For Converting Console input to the desired output.

*To compile the File use command -

* javac Movie.java

*

* To Run the program use command -

* java Movie Name of Movie Length_in_Minutes

*

*/

//Movie.java

class Movie

{

//Fields to store Movie name ,hours ,minutes and the Output.

public String movieName="";/*Initialised with the blank value Otherwise it Stores null by default. Creates problem in for loop in constructor.*/

public int hour;

public int minute;

public String output;

//Constructor to accept the values in the form of array of Strings.

Movie(String args[])

{

for(int i=0;i<args.length-1;i++)//for loop used for Movie names including blank spaces

{

this.movieName+=args[i]+" ";

}

int temp=Integer.parseInt(args[args.length-1]);//Assuming that the last value in Console Command is Number.

this.hour=temp/60; //Getting Hours from Minutes

this.minute=temp%60;//Getting Minutes remaining

}

/*

*Function For The Output String .

*Here we Decide the words hour or hours and minute or minutes according to value.

*/

void makeString()

{

output=movieName+"Runs for ";

if(hour<1)

{

if(minute==0)

{

output+=hour+" hour "+minute+" Minute ";

}

else if(minute==1)

{

output+=minute+" Minute.";

}

else

{

output+=minute+" Minutes.";

}

}

else if(hour==1)

{

if(minute==0)

{

output+=hour+" Hour";

}

else if(minute==1)

{

output+=hour+" Hour "+minute+" Minute.";

}

else

{

output+=hour+" Hour "+minute+" Minutes.";

}

}

else

{

if(minute==0)

{

output+=hour+" Hours ";

}

else if(minute==1)

{

output+=hour+" Hours "+minute+" Minute.";

}

else

{

output+=hour+" Hours "+minute+" Minutes.";

}

}

}

//Function to Display The output.

void display()

{

makeString();

System.out.println(output);

}

//Main function for Demonstration.

public static void main(String arg[])

{

Movie mv=new Movie(arg);

mv.display();

}

}