/**
* Adds movies, and rates them.
*
* @Manas Majhi
* @1.0 (September 15, 2010)
*/
public class Movie // or MovieRating, except I thought "Movie" makes more sense, as you're adding a movie.
{
private String name; // field
private int time; // in minutes.
private int raters; //declaration
private double rating;
private int tens;
/**
* Constructors for class.
*/
public Movie() // constructor
{
name = ""; //initialization
time = 0;
raters = 0;
rating = 0.0;
tens = 0;
}
/**
* Constructors for class.
*/
public Movie(String theName, int theTime)
{
name = theName;
time = theTime;
raters = 0;
rating = 0.0;
tens = 0;
}
/**
* Get the movie name.
*/ // comment
public String getName() //accessor method
{
return name; //return statement
}
/**
*
*/
public void movieDetails()
{
System.out.println(""); //block statement
System.out.println("Movie name:"+" "+name);
System.out.println("Movie duration:"+" "+time);
System.out.println("");
}
/**
* Get the movie duration (in minutes).
*/
public int getLength() //method signature
{
return time; // method body
}
/**
* Change the movie name.
*/
public void changeName(String newName)
{
name //expression
= //assignment operator
newName;
}
/**
* Change the movie lenght.
*/
public void changeLength(int newTime //formal parameter
) //mutator method
{
time = newTime; //assignment statement
}
/**
* Rate the movie.
*/
public void //return type
rate(int newRating)
{
if(newRating<1 || newRating>10) //conditional statement
{
System.out.println("");
System.out.println("Please enter a rating value of 1 through 10");
System.out.println("");
}
else
{
double overallRating; //local variable
overallRating = ((rating*raters)+newRating)/(raters+1);
rating = overallRating;
raters = raters+1;
if(newRating == 10)
{
tens=tens+1;
}
}
}
/**
* Get rating.
*/
public void getRating()
{
System.out.println("");
System.out.println("*************************************************************************");
System.out.println(raters+" "+"person(s) have rated this movie.");
System.out.println("The average rating is" + rating+".");
System.out.println(tens +" "+"person(s) rated this movie a value of 10/10");
System.out.println("*************************************************************************");
System.out.println("");
}
}
* Adds movies, and rates them.
*
* @Manas Majhi
* @1.0 (September 15, 2010)
*/
public class Movie // or MovieRating, except I thought "Movie" makes more sense, as you're adding a movie.
{
private String name; // field
private int time; // in minutes.
private int raters; //declaration
private double rating;
private int tens;
/**
* Constructors for class.
*/
public Movie() // constructor
{
name = ""; //initialization
time = 0;
raters = 0;
rating = 0.0;
tens = 0;
}
/**
* Constructors for class.
*/
public Movie(String theName, int theTime)
{
name = theName;
time = theTime;
raters = 0;
rating = 0.0;
tens = 0;
}
/**
* Get the movie name.
*/ // comment
public String getName() //accessor method
{
return name; //return statement
}
/**
*
*/
public void movieDetails()
{
System.out.println(""); //block statement
System.out.println("Movie name:"+" "+name);
System.out.println("Movie duration:"+" "+time);
System.out.println("");
}
/**
* Get the movie duration (in minutes).
*/
public int getLength() //method signature
{
return time; // method body
}
/**
* Change the movie name.
*/
public void changeName(String newName)
{
name //expression
= //assignment operator
newName;
}
/**
* Change the movie lenght.
*/
public void changeLength(int newTime //formal parameter
) //mutator method
{
time = newTime; //assignment statement
}
/**
* Rate the movie.
*/
public void //return type
rate(int newRating)
{
if(newRating<1 || newRating>10) //conditional statement
{
System.out.println("");
System.out.println("Please enter a rating value of 1 through 10");
System.out.println("");
}
else
{
double overallRating; //local variable
overallRating = ((rating*raters)+newRating)/(raters+1);
rating = overallRating;
raters = raters+1;
if(newRating == 10)
{
tens=tens+1;
}
}
}
/**
* Get rating.
*/
public void getRating()
{
System.out.println("");
System.out.println("*************************************************************************");
System.out.println(raters+" "+"person(s) have rated this movie.");
System.out.println("The average rating is" + rating+".");
System.out.println(tens +" "+"person(s) rated this movie a value of 10/10");
System.out.println("*************************************************************************");
System.out.println("");
}
}
No comments:
Post a Comment