יום רביעי, 15 בספטמבר 2010

Chapter 2 Test


/**
 * Write a description of class MovieRatingSystem here.
 *
 * @author (Tal Zilkha)
 * @version (1)
 */
public class MovieRatingSystem
{
    private String name;//declaration
    private int duration;//field
    private int overallRating;
    private int totalRatings;
    private int totalTens;
    /**
     * The base values for the instance variables.
     */
    public MovieRatingSystem()//constructor
    {
        totalRatings = 0;
        duration = 0;
        name = "";
        overallRating = 0;
        totalTens = 0;
    }//block statement
    /**
     * Define the length of the movie in minutes.
     */
    public void setTime(int movieLength)
    {
        duration = movieLength;//assignment statement
    }
    /**
     * Define the title of the movie.//comment
     */
    public void setName(String movieTitle)
    {
        name = movieTitle;//mutator//local variable
    }
    /**
     * Rate and find the number of ratings
     */
    public void rateMovie(int rate)//formal parameter
    {
        if (rate>10 || rate<1)//conditional statement
       
        System.out.println ("Sorry, only ratings between 1 and 10 are accepted.");
       
        if (rate == 10)
        {
        totalTens = totalTens + 1;
        totalRatings = totalRatings + 1;//operator
        overallRating = (overallRating + rate)/totalRatings;//expression
        }
        else
        totalRatings = totalRatings + 1;
        overallRating = (overallRating + rate)/totalRatings;
     }
     
    /**
     * Define the title of the movie.
     */
    public void getInfo()//method signature
    {
        System.out.println ("Movie Name:" + name);//accessor
        System.out.println ("Running Time:" + duration);//return statement
   
    }
    public void getRatingInfo()
    {
        System.out.println ("The Average Rating out of " + totalRatings + " ratings for " + name + " is " + overallRating + " and there were " + totalTens + " 10's submitted.");//method body
   
    }
}








Actual Parameter - The acctual value of a formal parameter

Instance Variable - Simply a field.

Scope - The method a local variable is in.

Lifetime - The time during a parameter is being called in a method.

  

אין תגובות:

הוסף רשומת תגובה