[Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

What do they want from me?

Posted on 2009-04-30
6
Medium Priority
?
861 Views
Last Modified: 2012-05-06
Hello Experts,

I have this homework assignment and I'm unclear about what they want from me... I'm hoping someone will help me out here.  I've satisfied almost all of the requirements in the assignment, but the part starting with calcLateFees is confusing me.  Here is the question, verbatim.

Create a class named Movie that can be used with your video rental business. The Movie class should track the Motion Picture Association of America (MPAA) rating (i.g., Rated G, PG-13,R), ID Number, and movie title with appropriate accessor, and mutator methods.  Also create an equals() method that overrides Object's equals() method, where two movies are equal if their ID number is identical.  Next, create three additional classes named Action, Comedy, and Drama that are derived from Movie. Finally, create an overridden method named calcLateFees that takes as input the number of days a movie is late and returns the late fee for that movie. The default late fee is $2/day. Action movies have a late fee of $3/day, comedies are $2.50/day, and dramas are $2/day. Test your classes from a main method.

This assignment is supposed to be about polymorphism and abstract classes, so where am I supposed to create the calcLateFees method, and what method is it overriding?  The instruction is not clear.  Someone please help!
// Here are my classes-----------------------------------------
public class Movie {
  private String Rating = "NR";
  private int ID = 0;
  private String Title = "No Title Yet";
  
  public void SetTitle(String theTitle) {
    Title = theTitle;
  }
  public String GetTitle() {
    return Title;
  }
  public void SetID(int theID) {
    ID = theID;
  }
  public int GetID() {
    return ID;
  }
  public void SetRating(String theRating) {
    Rating = theRating;
  }
  public String GetRating() {
    return Rating;
  }
  public boolean equals(int ID1, int ID2) {
    if (ID1 == ID2) {
      return true;
    } else {
      return false;
    }
  }
} //-----------------------------------------------------
 
class Action extends Movie {
  /* The instruction didn't
   * say what to do with the
   * dirived classes... */  
} //------------------------------------------------
 
class Comedy extends Movie {
 // ?
} //----------------------------------------------
 
class Drama extends Movie {
// ?
} //---------------------------------------------

Open in new window

0
Comment
Question by:fibdev
  • 3
  • 3
6 Comments
 
LVL 86

Assisted Solution

by:CEHJ
CEHJ earned 160 total points
ID: 24271846
Late fee calculation can go in the parent class
0
 
LVL 12

Expert Comment

by:Gibu George
ID: 24271882
The class movie should be abstract and should have an abstract method calcLateFees,  which takes the parameter no of days, you need to add the implementation in each of the subclasses, ie in Action, Comedy etc.

in action it will be
public int calcLateFees(int noOfDays){
return 3*noOfdays
}

also the equals method takes an object of Movie as its parameter

public boolean equals(Movie movie){
  return this.ID==movie.GetID;
}
0
 
LVL 12

Accepted Solution

by:
Gibu George earned 240 total points
ID: 24271892
return this.ID==movie.GetID();
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 86

Assisted Solution

by:CEHJ
CEHJ earned 160 total points
ID: 24271941
btw, the correct pattern in Java for accessors and mutators is as follows:
public class Movie {
    private String rating;
 
    public String getRating() {
        return this.rating;
    }   
 
    public void setRating(String rating) {
        this.rating = rating;
    }   
}

Open in new window

0
 
LVL 86

Expert Comment

by:CEHJ
ID: 24272395
>>
also the equals method takes an object of Movie as its parameter

public boolean equals(Movie movie){
  return this.ID==movie.GetID;
}
>>

It actually take a parameter of type Object:
public boolean equals(Object o) {
  return this.ID==((Movie)o).ID;
}

Open in new window

0
 
LVL 12

Expert Comment

by:Gibu George
ID: 24272600
Okay, thax. for reminding me
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

After being asked a question last year, I went into one of my moods where I did some research and code just for the fun and learning of it all.  Subsequently, from this journey, I put together this article on "Range Searching Using Visual Basic.NET …
Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
Suggested Courses
Course of the Month20 days, 12 hours left to enroll

865 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question