CodeGym
Promotion
CodeGym University
Learning
Course
Tasks
Surveys & Quizzes
Games
Help
Schedule
Community
Users
Forum
Chat
Articles
Success stories
Activity
Reviews
Subscriptions
Light theme
Start learning now
  • All questions
BlueJavaBanana
Level 37
  • 14.09.2020
  • 209views
  • 2comments

Will not let me validate even though requirements seem to be met??!!

Question about the task Refactoring (part 4)
Java Multithreading,  Level 5,  Lesson 16
Resolved

4.1. Replace inheritance with delegation.
4.1.1. The University class must not inherit Student.
4.1.2. The University class must have a students list. Don't forget to initialize it.
4.1.3. Add a setter and getter for students.
4.1.4. A university has a name and an age. Add the required fields, along with setters and getters for them.
4.2. Extract a superclass.
4.2.1. Create a UniversityPerson class in the human package.
4.2.2. Move the university field to it.
4.2.3. Move the setter and getter for the university field.
4.2.4. Make the required classes inherit UniversityPerson.
4.3. Replace a simple field with an object. Change the university field's type to University.

Requirements:
  • The University class must not inherit Student.
  • In the University class, you need to create a name field, along with a corresponding setter and getter.
  • In the University class, you need to create an age field, along with a corresponding setter and getter.
  • In the University class, you must create a private List<Student> students field.
  • In the University class, you must create a setter and getter for the students field.
  • You need to create a public UniversityPerson class in the human package and make it inherit the Human class.
  • You need to move the university field from the Teacher and Student classes to the UniversityPerson class.
  • You need to move the university field's setter and getter from the Teacher and Student classes to the UniversityPerson class.
  • You must make the Teacher and Student classes inherit the UniversityPerson class.
  • You need to change the university field's type to University.
package com.codegym.task.task29.task2909.car; import java.util.Date; public class Car { static public final int TRUCK = 0; static public final int SEDAN = 1; static public final int CABRIOLET = 2; double fuel; public double summerFuelConsumption; public double winterFuelConsumption; public double winterWarmingUp; private int type; private boolean driverAvailable; private int numberOfPassengers; public Car(int type, int numberOfPassengers) { this.type = type; this.numberOfPassengers = numberOfPassengers; } public int fill(double numberOfGallons) { if (numberOfGallons < 0) return -1; fuel += numberOfGallons; return 0; } public double getTripConsumption(Date date, int length, Date summerStart, Date summerEnd) { double consumption; if (date.before(summerStart) || date.after(summerEnd)) { consumption = length * winterFuelConsumption + winterWarmingUp; } else { consumption = length * summerFuelConsumption; } return consumption; } public int getNumberOfPassengersThatCanBeCarried() { if (!isDriverAvailable()) return 0; if (fuel <= 0) return 0; return numberOfPassengers; } public boolean isDriverAvailable() { return driverAvailable; } public void setDriverAvailable(boolean driverAvailable) { this.driverAvailable = driverAvailable; } public void startMoving() { if (numberOfPassengers > 0) { fastenPassengerBelts(); fastenDriverBelt(); } else { fastenDriverBelt(); } } public void fastenPassengerBelts() { } public void fastenDriverBelt() { } public int getMaxSpeed() { if (type == TRUCK) return 80; if (type == SEDAN) return 120; return 90; } }
0
Comments (2)
  • Popular
  • New
  • Old
You must be signed in to leave a comment
Guadalupe Gagnon
Level 37 , Tampa, United States
15 September 2020, 15:19solution
try making the constructor in the UP class public
+2
BlueJavaBanana
Level 37
15 September 2020, 16:30
i love you dude. Thanks
0
Learn
  • Registration
  • Java Course
  • Help with Tasks
  • Pricing
  • Game Projects
  • Java Syntax
Community
  • Users
  • Articles
  • Forum
  • Chat
  • Success Stories
  • Activity
  • Affiliate Program
Company
  • About us
  • Contacts
  • Reviews
  • Press Room
  • CodeGym for EDU
  • FAQ
  • Support
CodeGym CodeGym is an online course for learning Java programming from scratch. This course is a perfect way to master Java for beginners. It contains 1200+ tasks with instant verification and an essential scope of Java fundamentals theory. To help you succeed in education, we’ve implemented a set of motivational features: quizzes, coding projects, content about efficient learning and Java developer’s career.
Follow us
Interface language
Programmers Are Made, Not Born © 2023 CodeGym
MastercardVisa
Programmers Are Made, Not Born © 2023 CodeGym
This website uses cookies to provide you with personalized service. By using this website, you agree to our use of cookies. If you require more details, please read our Terms and Policy.