05. april 2008 - 18:10Der er
8 kommentarer og 1 løsning
Extends - constructor error
Hej eksperter. Jeg er ny til java, og har en opgave hvor jeg skal extends en class, men jeg får en error "Cannot find symbol, symbol constructor Movie(), class Movie". jeg læste noget om at det er fordi jeg skulle lave en constructor uden arguments, og så en Super(), men kan ikke få det til at virke. Nogle der kan forklare mig det mere præcist hvad man skal gøre?
Her er min kode:
--MOVIE CLASS START-- public class Movie { protected String pRating; protected int pId; protected double pPrize; protected String pTitle; protected double fees = 2; protected int feeDays;
public Movie (String rating, int id, double prize, String title) { pRating = rating; pId = id; pPrize = prize; pTitle = title; } } --MOVIE CLASS END--
--ACTION CLASS START-- public class Action extends Movie {
Er der ikke andre måder at gøre det på? Det er til en skoleopgave, og jeg skal argumenter i movie klassen. Men samtidig skal jeg jo ikke have film direkte i mine sub-klasser.
Kan også være jeg skal gøre det på en anden måde? Her er min opgavebeskrivelse, jeg tror kun det er de 3 første punkter der er relevante til det her. PS. Vil bare lige vide om det er den rigtige måde jeg gør den på eller om der er en bedre måde med det her constructor / super noget.
For all fields/attributes you should choose whatever data type you find the best. Consider of course whether it should be used for calculations or not.
1. 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 (e.g., Rated G, PG-13, R), an ID Number, a prize, and movie title with appropriate accessor and mutator method (get and set methods).
2. Create an equals() method that overrides the Objects equals() method. Two movies are equal if their ID Number is identical.
3. Create three additional classes named Action, Comedy and Drama that are derived from the Move.
4. 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 if more than 3 days late. Comedy movies have a late fee of $2.5/day if more than 2 days late, and dramas are $2/day.
5. Create a test class and test your classes from a main method.
6. Create a Rental class. This class should store a movie that is rented, an integer representing the ID of the customer that rented the movie, an integer indicating how many days late the movie is. And add a method that calculates the late fees for the rental.
7. In the test class’s main method create an array of type Rental filled with sample data of all types of movies. Then create a method named lateFeeOwed that iterates through the array and returns the total amount of late fees that are outstanding.
8. All classes should have added the toString method so that it return a string of the necessary information.
9. In the test class’s main method create an array of type Movies filled with sample data of all types of movies. Then create a method named movieList that iterates through the array and print the movies information
10. Create a class MovieList. It has to store the movies in an array of data type Movie. Write an add method to store a movie and write a get method to retrieve a movie. Use this class in the test class to print a list of all the movies.
Ja ved godt det med price, men da min lærer har brugt prize i opgavebeskrivelsen, bruger jeg også det. Jeg bruger i øjeblikket NetBeans IDE 5.5.1, ved ikke om den er god?
Mange tak for din al din hjælp arne_v, bare smid et svar :)
Jeg har NetBeans 6.0 installeret (omend jeg normalt bruger Eclipse).
I den kan kan du højre klikke på klassen, vælge "insert code", vælge constructor og så indsætter den constructorer med samme signatur som super class. Den kalder dog ikke super ligesom når jeg genererer constructor i Eclipse. Lidt mystisk.
Tilladte BB-code-tags: [b]fed[/b] [i]kursiv[/i] [u]understreget[/u] Web- og emailadresser omdannes automatisk til links. Der sættes "nofollow" på alle links.