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
ddi
Level 18
Dortmund
  • 28.09.2019
  • 1182views
  • 10comments

Is this what they want? Help! I dont get the question..

Question about the task Shared list
Java Core,  Level 7,  Lesson 10
Under discussion

1. Change the Solution class so that it becomes a list. (It must implement the java.util.List interface).
2. The Solution list should only work with Longs.
3. Use the original field.
4. The list will be used by threads, so you need to ensure that all the methods are synchronized.

Requirements:
  • The Solution class must implement the List<Long> interface.
  • The Solution class must have a private ArrayList<Long> field called original.
  • All of the List interface's overridden methods must delegate calls to the methods of the original object.
  • All of the Solution class's methods, except for the main method, must be synchronized
package com.codegym.task.task17.task1713; import java.util.*; /* Shared list */ public class Solution implements List<Long>{ private ArrayList<Long> original = new ArrayList<>(); public static void main(String[] args) {} @Override public synchronized List<Long> boolean isEmpty(){ return original.isEmpty(); } @Override public synchronized List<Long> boolean contains(Object o){ return original.contains(Object o); } @Override public synchronized List<Long> Iterator iterator(){ return original.iterator(); } @Override public synchronized List<Long> Object[] toArray(){ return original.toArray(); } @Override public synchronized List<Long> Object[] toArray(Object[] a){ return original.toArray(Object[] a); } @Override public synchronized List<Long> add(Object o){ return original.add(Object o); } @Override public synchronized List<Long> boolean remove(Object o){ return original.remove(Object o); } @Override public synchronized List<Long> boolean containsAll(Collection c){ return original.containsAll(Collection c); } @Override public synchronized List<Long> boolean addAll(Collection c){ return original.addAll(Collection c); } @Override public synchronized List<Long> boolean addAll(int index, Collection c){ return original.addAll(int index, Collection c); } @Override public synchronized List<Long> boolean removeAll(Collection c){ return original.removeAll(Collection c); } @Override public synchronized List<Long> boolean retainAll(Collection c){ return original.retainAll(Collection c); } @Override public synchronized List<Long> boolean equals(Object o){ return original.equals(Object o); } @Override public synchronized List<Long> int hashCode(){ return original.hashCode(); } @Override public synchronized List<Long> Object get(int index){ return original.get(int index); } @Override public synchronized List<Long> Object set(int index, Object element){ return original.set(int index, Object element); } @Override public synchronized List<Long> void add(int index, Object element){ return original.add(int index, Object element); } @Override public synchronized List<Long> Object remove(int index){ return original.remove(int index); } @Override public synchronized List<Long> int indexOf(Object o){ return original.indexOf(Object o); } @Override public synchronized List<Long> int lastIndexOf(Object o){ return original.lastIndexOf(Object o); } @Override public synchronized List<Long> ListIterator listIterator(){ return original.listIterator(); } @Override public synchronized List<Long> ListIterator listIterator(int index){ return original.listIterator(int index); } @Override public synchronized List<Long> List subList(int fromIndex,int toIndex){ return original.subList(int fromIndex, int toIndex); } }
0
Comments (10)
  • Popular
  • New
  • Old
You must be signed in to leave a comment
Jason
Level 26 , Rancho Cucamonga, United States
29 September 2019, 23:40
It looks like your problem is that you a declaring new variables instead of using the ones from the constructor.
@Override
    public synchronized List<Long> boolean containsAll(Collection c){
        return original.containsAll(Collection c);
    }
should be
@Override
    public synchronized List<Long> boolean containsAll(Collection c){
        return original.containsAll(c);
    }
0
ddi
Level 18 , Dortmund, Germany
30 September 2019, 12:15
That can be one of the problems, i have correct it but its not yet working... : Any oder ideas?
0
Jason
Level 26 , Rancho Cucamonga, United States
1 October 2019, 21:04
oh it looks like you also put to return "List<Long>" in all you methods but that is not what it is asking for when you did the "original.<methodname>()" in the overridden methods is what satisfies the "delegate calls to the methods of the original object." so if I believe if you just put the method modifiers back to their original state you should be good to go
0
ddi
Level 18 , Dortmund, Germany
2 October 2019, 06:43
Sorry but i don´t get it. I have corrected the program to what u said, and now i am returning : return original.containsAll(c); not the List<Long>. Can you explain it?
0
ddi
Level 18 , Dortmund, Germany
2 October 2019, 06:48
now i am calling this: public synchronized List<Long>original boolean isEmpty(){ return original.isEmpty(); } the error that i receive is that am i missing and ; in the method
0
Jason
Level 26 , Rancho Cucamonga, United States
2 October 2019, 16:35
well the conditions aren't asking you to return a list
0
Jason
Level 26 , Rancho Cucamonga, United States
2 October 2019, 16:39
that method would go...
public synchronized boolean isEmpty() {
     return original.isEmpty();
}
0
ddi
Level 18 , Dortmund, Germany
10 October 2019, 13:20
So i set on error and get another lol now is this : Solution is not abstract and does not override abstract method remove(int) in java.util.List public class Solution implements List<Long> { I am using this : public class Solution implements List<Long> { No idea where does the problem come from..
0
Jason
Level 26 , Rancho Cucamonga, United States
11 October 2019, 00:52
I'm kind of confused at this point. It might be worth submitting a new topic to get all of your current code republished so we can all read it over.
0
ddi
Level 18 , Dortmund, Germany
11 October 2019, 12:11
I have created a new post :) 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.