+ 1

The code does not work JAVA

CODE: package Item; import java.util.ArrayList; import java.util.Scanner; import java.io.FileNotFoundException; import java.io.PrintWriter; import java.util.List; import java.io.File; class List { List <Integer> list = new ArrayList <Integer> (); private int [] numbers; private static int max. Capacity; private int size; List (int max Capacity, int size) { numbers = new int [maxCapacity]; this.maksCapacity = maxCapacity; this.size = size; } / * public int getLiczby () { return this.numbers [10]; } public int getMaksPoamnosc () { return this.maksCapacity; } public int getSize () { return this. size; } * / public int addElement (int j) { for (int i = 0; i <maxCapacity; ++ i) { if (maxCapacity == 0) { } } return max. Capacity; //? } public int find (int search number) {         boolean number = false;         for (int i = 0; i <size; i ++) {             if (numbers [i] == number searched) {                 number = true;                 return i;             }         }         if (number = false) {             return -1;         } return search number;     } public String write () { return "size:" + size + "capacity" + max. Capacity + "elements:"; } public int deleted First (int given number) { for (int i = 0; i <size; i ++) {             if (numbers [i] == number given) {                 numbers [i] = 0;             }         } return givenNumber; } public int deleted Repetition () { for (int i = 0; i <10; i ++) { for (int j = 0; j <10; j ++) { if (the number of [i] == number [j]) { numbers [i] = 0; } } } return max. Capacity; } public int versus () { for (int i = size; i> = 0; i ++) { return numbers [i]; } return max. Capacity; } public static void main (String [] args) / * throws FileNotFoundException * / { List l = new List (max Capacity, max Capacity);    / * File file = new File ("List.txt");     Scanner scanner = new Scanner (file);          String line1 = scanner.nextLine ();  

15th Jan 2020, 3:14 PM
Ivan
2 odpowiedzi
+ 6
Ivan You did lots of mistakes in your program. I think you need to clear your basic first. If you will ignore basics you can't do big program like this 1 - Why you have declared variable like this. max. Capacity Do you know there should not be space in variable? 2 - List (int max Capacity, int size) { check above line there is also space in variable maxCapacity. 3 - public int find (int search number) why there is space in variable searchNumber 4 - return search number; //wrong 5 - public int deleted First (int given number) //wrong parameter declaration 6 - if (the number of [i] == number [j]) {//Wrong. what is 'the number of'
15th Jan 2020, 10:32 PM
A͢J
A͢J - avatar
+ 2
https://code.sololearn.com/cG7knRElFRg1/#java Write a List class that will store a list of integers. This class should have the following private fields: • int [] numbers; - table in which numbers will be stored, • int capacity; - the maximum number of elements that can be stored, • int size; - current number of stored items. The List class should also have the following methods: • a constructor with a capacity parameter that allocates memory for array of numbers and sets values ​​of other class fields; • the addElement method, which takes exactly one element - an integer that is added to the list; in case the list is full should an error message appears; • find method, whose only parameter should be the searched number, while the result of the position of the given number in the list (counting from 0) or -1, when the numbers is not on the list; • a parameterless write method that prints information about the list, including its size, capacity and list of stored items; • deletePirst method, which removes the first occurrence given as a parameter number if it is on the list, i.e. if the number given is more than one than once, only its first occurrence is deleted; 21 • deleteRepeat method, which removes all element repetitions on leaves, i.e. after its completion, the list should not be repeated numbers; • the reverse method, which reverses the order of the items stored in the list; • method save.ToPlik, which saves the contents of the list to a text file whose name should be given as the first parameter; For example, after completing the following fragment: final int N = 10; List l = new List (N); for (int i = 0; i <N / 2; ++ i) { l. add Element ((1 << i)); } l.dodajElement (2); l.dodajElement (8); l.pisz (); l.usunPierwszy (2); l.pisz (); for (int i = 0; i <N / 2; ++ i) { l. add Element ((1 << i)); } l.pisz (); System.out.println ("After removing repetitions:"); l.usunPowtorzenia (); l.pisz (); The screen should display: List: Capacity: 10
15th Jan 2020, 3:39 PM
Ivan