Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Last login: Thu Oct 1 14:34:39 on ttys000
- MacBook-Pro-di-Leonardo:~ leonardo$ jshell
- | Welcome to JShell -- Version 13.0.2
- | For an introduction type: /help intro
- jshell> public interface IntMultiSet {
- ...> /**
- ...> * Restitusice il numero delle occorrence dell’intero elem nel multi-insieme. * Apublic interface IntMultiSet {nsieme restituisce 0
- ...> /**
- ...> * Restitusice il numero delle occorrence dell’intero elem nel multi-insi
- eme. * A elem non appartimene al multiinsieme restituisce 0
- ...> **/ggiunge al multi-insieme una occorrenza di elem
- ...> int getCount(int elem);
- ...> /** void add(int elem);
- ...> * Aggiunge al multi-insieme una occorrenza di elem
- ...> * */e di elem al multi-insieme **/
- ...> void add(int elem); int n);
- ...> /**
- ...> * Aggiunge n copie di elem al multi-insieme **/-insieme. * Restituisce false se void add(int elem, int n);
- ...> /**
- ...> * Rimuove tutte le occorrenze di elem dal multi-insieme. * Restituisce f
- alse se elem non e’ presente
- ...> */Rimuove n copie of di elem dal multi-insieme * Restituisce false se elem non e boolean remove(int elem);
- ...> /** * */
- ...> * Rimuove n copie of di elem dal multi-insieme * Restituisce false se el
- em non e’ presente
- ...> * */mero degli elementi del multi-insieme. **/
- ...> boolean remove(int elem, int n);
- ...> /**
- * Restuisce il numero degli elementi del multi-insieme. **/
- int size(); }
- | created interface IntMultiSet
- jshell>
- jshell>
- jshell> public class Foo {
- ...> private int a[];
- ...> class Foo (int[] arr_in) {
- ...> a = arr_in;
- ...> }
- ...>
- ...> }
- | Error:
- | '{' expected
- | class Foo (int[] arr_in) {
- | ^
- | Error:
- | ';' expected
- | class Foo (int[] arr_in) {
- | ^
- | Error:
- | reached end of file while parsing
- | }
- | ^
- jshell> public class Foo {
- ...> private int a[];
- ...> class Foo(int[] arr_in) {
- ...> a = arr_in;
- ...> }
- ...>
- ...> }
- | Error:
- | '{' expected
- | class Foo(int[] arr_in) {
- | ^
- | Error:
- | ';' expected
- | class Foo(int[] arr_in) {
- | ^
- | Error:
- | reached end of file while parsing
- | }
- | ^
- jshell> public class Foo {
- ...> private int a[];
- ...> class Foo(int arr_in[]) {
- ...> a = arr_in;
- ...> }
- ...>
- ...> }
- | Error:
- | '{' expected
- | class Foo(int arr_in[]) {
- | ^
- | Error:
- | ';' expected
- | class Foo(int arr_in[]) {
- | ^
- | Error:
- | reached end of file while parsing
- | }
- | ^
- jshell>
- jshell>
- jshell>
- jshell>
- jshell> public class Foo {
- ...> private int a[];
- ...> public Foo(int arr_in[]) {
- ...> a = arr_in;
- ...> }
- ...>
- ...> }
- | created class Foo
- jshell> private int[] a;
- a ==> null
- jshell> private int[] a = new int[5];
- a ==> int[5] { 0, 0, 0, 0, 0 }
- jshell> System.out.println("a length" + a.length);
- a length5
- jshell> int a[] = new int[5];
- a ==> int[5] { 0, 0, 0, 0, 0 }
- jshell> a[1] = 3;
- $7 ==> 3
- jshell> a[2] = 5;
- $8 ==> 5
- jshell> a[3] = 7;
- $9 ==> 7
- jshell> a[4] = 9;
- $10 ==> 9
- jshell> a[5] = 9
- | Exception java.lang.ArrayIndexOutOfBoundsException: Index 5 out of bounds for length 5
- | at (#11:1)
- jshell> a[0] = 1;
- $12 ==> 1
- jshell> int[] b = new int[5];
- b ==> int[5] { 0, 0, 0, 0, 0 }
- jshell> b[0]= 281;
- $14 ==> 281
- jshell> b[1] = 293
- $15 ==> 293
- jshell> b[2] = 1;
- $16 ==> 1
- jshell> b[3] = 203
- $17 ==> 203
- jshell> b[4] = 92392;
- $18 ==> 92392
- jshell> public int getCount(int elem) {
- ...> //cerca l'elemento
- ...> for(int i = 0; i < a.lenght; i++)
- ...> if(a[i] == elem)
- ...> return b[i];
- ...> return 0;
- ...> }
- | Error:
- | cannot find symbol
- | symbol: variable lenght
- | for(int i = 0; i < a.lenght; i++)
- | ^------^
- jshell> public int[] a = a;
- a ==> int[5] { 1, 3, 5, 7, 9 }
- jshell> public int getCount(int elem) {
- ...> //cerca l'elemento
- ...> for(int i = 0; i < a.lenght; i++)
- ...> if(a[i] == elem)
- ...> return b[i];
- ...> return 0;
- ...> }
- | Error:
- | cannot find symbol
- | symbol: variable lenght
- | for(int i = 0; i < a.lenght; i++)
- | ^------^
- jshell> public class Foo implements IntMultiSet {
- ...> private int[] a;
- ...> private int[] b;
- ...> public Foo(int a_in[], int b_in) {
- ...> a = a_in;
- ...> b = b_in;
- ...> }
- ...>
- ...> public int getCount(int elem) {
- ...> //cerca l'elemento
- ...> for(int i = 0; i < a.lenght; i++)
- ...> if(a[i] == elem)
- ...> return b[i];
- ...> return 0;
- ...> }
- ...> }
- ...>
- | Error:
- | Foo is not abstract and does not override abstract method size() in IntMultiSet
- | public class Foo implements IntMultiSet {
- | ^----------------------------------------...
- | Error:
- | incompatible types: int cannot be converted to int[]
- | b = b_in;
- | ^--^
- | Error:
- | cannot find symbol
- | symbol: variable lenght
- | for(int i = 0; i < a.lenght; i++)
- | ^------^
- jshell> public class Foo {
- ...> private int[] a;
- ...> private int[] b;
- ...> public Foo(int a_in[], int b_in) {
- ...> a = a_in;
- ...> b = b_in;
- ...> }
- ...>
- ...> public int getCount(int elem) {
- ...> //cerca l'elemento
- ...> for(int i = 0; i < a.lenght; i++)
- ...> if(a[i] == elem)
- ...> return b[i];
- ...> return 0;
- ...> }
- ...> }
- | Error:
- | incompatible types: int cannot be converted to int[]
- | b = b_in;
- | ^--^
- | Error:
- | cannot find symbol
- | symbol: variable lenght
- | for(int i = 0; i < a.lenght; i++)
- | ^------^
- jshell> public class Foo {
- ...> private int[] a;
- ...> private int[] b;
- ...> public Foo(int a_in[], int b_in[]) {
- ...> a = a_in;
- ...> b = b_in;
- ...> }
- ...>
- ...> public int getCount(int elem) {
- ...> //cerca l'elemento
- ...> for(int i = 0; i < a.lenght; i++)
- ...> if(a[i] == elem)
- ...> return b[i];
- ...> return 0;
- ...> }
- ...> }
- ...>
- | Error:
- | cannot find symbol
- | symbol: variable lenght
- | for(int i = 0; i < a.lenght; i++)
- | ^------^
- jshell> public class Foo {
- ...> int[] a;
- ...> private int[] b;
- ...> public Foo(int a_in[], int b_in[]) {
- ...> a = a_in;
- ...> b = b_in;
- ...> }
- ...>
- ...> public int getCount(int elem) {
- ...> //cerca l'elemento
- ...> for(int i = 0; i < a.lenght; i++)
- ...> if(a[i] == elem)
- ...> return b[i];
- ...> return 0;
- ...> }
- ...> }
- ...>
- | Error:
- | cannot find symbol
- | symbol: variable lenght
- | for(int i = 0; i < a.lenght; i++)
- | ^------^
- jshell> public class Foo {
- ...> public int[] a;
- ...> private int[] b;
- ...> public Foo(int a_in[], int b_in[]) {
- ...> a = a_in;
- ...> b = b_in;
- ...> }
- ...>
- ...> public int getCount(int elem) {
- ...> //cerca l'elemento
- ...> for(int i = 0; i < a.lenght; i++)
- ...> if(a[i] == elem)
- ...> return b[i];
- ...> return 0;
- ...> }
- ...> }
- ...>
- | Error:
- | cannot find symbol
- | symbol: variable lenght
- | for(int i = 0; i < a.lenght; i++)
- | ^------^
- jshell> public class Foo {
- ...> private int[] a;
- ...> private int[] b;
- ...> public Foo(int a_in[], int b_in[]) {
- ...> a = a_in;
- ...> b = b_in;
- ...> }
- ...>
- ...> public int getCount(int elem) {
- ...> //cerca l'elemento
- ...> for(int i = 0; i < a.length; i++)
- ...> if(a[i] == elem)
- ...> return b[i];
- ...> return 0;
- ...> }
- ...> }
- ...>
- | created class Foo
- jshell> a;
- a ==> int[5] { 1, 3, 5, 7, 9 }
- jshell> b;
- b ==> int[5] { 281, 293, 1, 203, 92392 }
- jshell> getCount(7);
- | Error:
- | cannot find symbol
- | symbol: method getCount(int)
- | getCount(7);
- | ^------^
- jshell> public int getCount(int elem) {
- ...> //cerca l'elemento
- ...> for(int i = 0; i < a.length; i++)
- ...> if(a[i] == elem)
- ...> return b[i];
- ...> return 0;
- ...> }
- | created method getCount(int)
- jshell> getCount(7);
- $24 ==> 203
- jshell> public void add(int elem, int n) {
- ...> //aggiunge n occorrenze di elem
- ...> private int position = position(elem);
- ...> if(position == -1) {
- ...> //l'elemento non è presente nel multi-insieme, va aggiunta una posizione all'array
- ...> a = java.util.Arrays.copyOf(a, a.length + 1);
- ...> b = java.util.Arrays.copyOf(b, b.length + 1);
- ...> position = a.length - 1;
- ...> a[position] = elem;
- ...> b[position] = 0;
- ...>
- ...> }
- ...>
- ...> b[position]+=n;
- ...> }
- | Error:
- | illegal start of expression
- | private int position = position(elem);
- | ^
- jshell> public void add(int elem, int n) {
- ...> //aggiunge n occorrenze di elem
- ...> int position = position(elem);
- ...> if(position == -1) {
- ...> //l'elemento non è presente nel multi-insieme, va aggiunta una posizione all'array
- ...> a = java.util.Arrays.copyOf(a, a.length + 1);
- ...> b = java.util.Arrays.copyOf(b, b.length + 1);
- ...> position = a.length - 1;
- ...> a[position] = elem;
- ...> b[position] = 0;
- ...>
- ...> }
- ...>
- ...> b[position]+=n;
- ...> }
- | created method add(int,int), however, it cannot be invoked until method position(int) is declared
- jshell> public void position(int elem) {
- ...> //cerca la posizione dell'elemento elem in a. Se lo trova restituisce la posizione altrimenti -1
- ...> for(int i = 0; i < a.length; i++)
- ...> if(a[i] == elem)
- ...> return i;
- ...> return -1;
- ...> }
- | Error:
- | incompatible types: unexpected return value
- | return i;
- | ^
- | Error:
- | incompatible types: unexpected return value
- | return -1;
- | ^^
- jshell> public int position(int elem) {
- ...> //cerca la posizione dell'elemento elem in a. Se lo trova restituisce la posizione altrimenti -1
- ...> for(int i = 0; i < a.length; i++)
- ...> if(a[i] == elem)
- ...> return i;
- ...> return -1;
- ...> }
- | created method position(int)
- jshell> public void add(int elem, int n) {
- ...> //aggiunge n occorrenze di elem
- ...> int position = position(elem);
- ...> if(position == -1) {
- ...> //l'elemento non è presente nel multi-insieme, va aggiunta una posizione all'array
- ...> a = java.util.Arrays.copyOf(a, a.length + 1);
- ...> b = java.util.Arrays.copyOf(b, b.length + 1);
- ...> position = a.length - 1;
- ...> a[position] = elem;
- ...> b[position] = 0;
- ...>
- ...> }
- ...>
- ...> b[position]+=n;
- ...> }
- | modified method add(int,int)
- jshell> a;
- a ==> int[5] { 1, 3, 5, 7, 9 }
- jshell> b;
- b ==> int[5] { 281, 293, 1, 203, 92392 }
- jshell> add(1, 3);
- jshell> a;
- a ==> int[5] { 1, 3, 5, 7, 9 }
- jshell> b;
- b ==> int[5] { 284, 293, 1, 203, 92392 }
- jshell> add(8, 1023910);
- jshell> a;
- a ==> int[6] { 1, 3, 5, 7, 9, 8 }
- jshell> b;
- b ==> int[6] { 284, 293, 1, 203, 92392, 1023910 }
- jshell> a;
- a ==> int[6] { 1, 3, 5, 7, 9, 8 }
- jshell> a = java.util.Arrays.copyOf(a, a.length - 1);
- a ==> int[5] { 1, 3, 5, 7, 9 }
- jshell> public boolean remove(int elem, int n) {
- ...> int position = position(elem);
- ...> if(position == -1)
- ...> return false;
- ...>
- ...> b[position]-=n;
- ...> if(b[position] <= 0) {
- ...> //l'elemento va eliminato dall'array a e b
- ...> for(int i = position + 1; i < a.length; i++) {
- ...> a[i - 1] = a[i];
- ...> b[i - 1] = b[i];
- ...> }
- ...> a = java.util.Arrays.copyOf(a, a.length - 1);
- ...> b = java.util.Arrays.copyOf(b, b.length - 1);
- ...> }
- ...>
- ...> return true;
- ...> }
- | created method remove(int,int)
- jshell> a;
- a ==> int[5] { 1, 3, 5, 7, 9 }
- jshell> remve(2932, 1);
- | Error:
- | cannot find symbol
- | symbol: method remve(int,int)
- | remve(2932, 1);
- | ^---^
- jshell> remove(2932, 1);
- $40 ==> false
- jshell> a; b;
- a ==> int[5] { 1, 3, 5, 7, 9 }
- b ==> int[6] { 284, 293, 1, 203, 92392, 1023910 }
- jshell> remove(1, 280);
- $43 ==> true
- jshell> a;b;
- a ==> int[5] { 1, 3, 5, 7, 9 }
- b ==> int[6] { 4, 293, 1, 203, 92392, 1023910 }
- jshell> remove(3, 1);
- $46 ==> true
- jshell> a;b;
- a ==> int[5] { 1, 3, 5, 7, 9 }
- b ==> int[6] { 4, 292, 1, 203, 92392, 1023910 }
- jshell> b = java.util.Arrays.copyOf(b, b.length - 1);
- b ==> int[5] { 4, 292, 1, 203, 92392 }
- jshell> a;b;
- a ==> int[5] { 1, 3, 5, 7, 9 }
- b ==> int[5] { 4, 292, 1, 203, 92392 }
- jshell> remove(1, 4);
- $52 ==> true
- jshell> a;b;
- a ==> int[4] { 3, 5, 7, 9 }
- b ==> int[4] { 292, 1, 203, 92392 }
- jshell> remove(5, 3);
- $55 ==> true
- jshell> a;b;
- a ==> int[3] { 3, 7, 9 }
- b ==> int[3] { 292, 203, 92392 }
- jshell> remove(9, 9232983);
- $58 ==> true
- jshell> a;b;
- a ==> int[2] { 3, 7 }
- b ==> int[2] { 292, 203 }
- jshell> public int size() {
- ...> int sum = 0;
- ...> for(int i = 0; i < b.length; i++)
- ...> sum+=b[i];
- ...> return sum;
- ...> }
- | created method size()
- jshell> size();
- $62 ==> 495
- jshell> public class Foo implements IntMultiSet{
- ...> private int[] a;
- ...> private int[] b;
- ...> public Foo(int a_in[], int b_in[]) {
- ...> a = a_in;
- ...> b = b_in;
- ...> }
- ...>
- ...> public int getCount(int elem) {
- ...> //cerca l'elemento e ne restituisce quante copie ve ne sono
- ...> for(int i = 0; i < a.length; i++)
- ...> if(a[i] == elem)
- ...> return b[i];
- ...> return 0;
- ...> }
- ...>
- ...> public int position(int elem) {
- ...> //cerca la posizione dell'elemento elem in a. Se lo trova restituisce la posizione altrimenti -1
- ...> for(int i = 0; i < a.length; i++)
- ...> if(a[i] == elem)
- ...> return i;
- ...> return -1;
- ...> }
- ...>
- ...> public void add(int elem, int n) {
- ...> //aggiunge n occorrenze di elem
- ...> int position = position(elem);
- ...> if(position == -1) {
- ...> //l'elemento non è presente nel multi-insieme, va aggiunta una posizione all'array
- ...> a = java.util.Arrays.copyOf(a, a.length + 1);
- ...> b = java.util.Arrays.copyOf(b, b.length + 1);
- ...> position = a.length - 1;
- ...> a[position] = elem;
- ...> b[position] = 0;
- ...> }
- ...>
- ...> b[position]+=n;
- ...> }
- ...>
- ...> public void add(int elem) {
- ...> //aggiunge una copia di elem nell'array
- ...> add(elem, 1);
- ...> }
- ...>
- ...> public boolean remove(int elem, int n) {
- ...> int position = position(elem);
- ...> if(position == -1)
- ...> return false;
- ...> public class Foo implements IntMultiSet{
- ...> private int[] a;;
- ...> private int[] b; <= 0) {
- ...> public Foo(int a_in[], int b_in[]) {rray a e b
- ...> a = a_in; i = position + 1; i < a.length; i++) {
- ...> b = b_in; 1] = a[i];
- ...> } b[i - 1] = b[i];
- ...> }
- ...> public int getCount(int elem) {(a, a.length - 1);
- ...> //cerca l'elemento e ne restituisce quante copie ve ne sono
- ...> for(int i = 0; i < a.length; i++)
- ...> if(a[i] == elem)
- ...> return b[i];
- ...> return 0;
- ...> }
- ...> public int size() {
- ...> public int position(int elem) {
- ...> //cerca la posizione dell'elemento elem in a. Se lo trova restituisc
- e la posizione altrimenti -1
- ...> for(int i = 0; i < a.length; i++)
- ...> if(a[i] == elem)
- ...> return i;
- ...> return -1;
- ...> }
- public void add(int elem, int n) {
- //aggiunge n occorrenze di elem
- int position = position(elem);
- if(position == -1) {
- //l'elemento non è presente nel multi-insieme, va aggiunta una pos
- izione all'array
- a = java.util.Arrays.copyOf(a, a.length + 1);
- b = java.util.Arrays.copyOf(b, b.length + 1);
- position = a.length - 1;
- a[position] = elem;
- b[position] = 0;
- }
- b[position]+=n;
- }
- public void add(int elem) {
- //aggiunge una copia di elem nell'array
- add(elem, 1);
- }
- public boolean remove(int elem, int n) {
- int position = position(elem);
- if(position == -1)
- return false;
- b[position]-=n;
- if(b[position] <= 0) {
- //l'elemento va eliminato dall'array a e b
- for(int i = position + 1; i < a.length; i++) {
- a[i - 1] = a[i];
- b[i - 1] = b[i];
- }
- a = java.util.Arrays.copyOf(a, a.length - 1);
- b = java.util.Arrays.copyOf(b, b.length - 1);
- }
- return true;
- }
- public int size() {
- int sum = 0;
- for(int i = 0; i < b.length; i++)
- sum+=b[i];
- return sum;
- }
- }
- | Error:
- | Foo is not abstract and does not override abstract method remove(int) in IntMultiSet
- | public class Foo implements IntMultiSet{
- | ^---------------------------------------...
- jshell> public class Foo implements IntMultiSet{
- ...> private int[] a;
- ...> private int[] b;
- ...> public Foo(int a_in[], int b_in[]) {
- ...> a = a_in;
- ...> b = b_in;
- ...> }
- ...>
- ...> public int getCount(int elem) {
- ...> //cerca l'elemento e ne restituisce quante copie ve ne sono
- ...> for(int i = 0; i < a.length; i++)
- ...> if(a[i] == elem)
- ...> return b[i];
- ...> return 0;
- ...> }
- ...>
- ...> public int position(int elem) {
- ...> //cerca la posizione dell'elemento elem in a. Se lo trova restituisce la posizione altrimenti -1
- ...> for(int i = 0; i < a.length; i++)
- ...> if(a[i] == elem)
- ...> return i;
- ...> return -1;
- ...> }
- ...>
- ...> public void add(int elem, int n) {
- ...> //aggiunge n occorrenze di elem
- ...> int position = position(elem);
- ...> if(position == -1) {
- ...> //l'elemento non è presente nel multi-insieme, va aggiunta una posizione all'array
- ...> a = java.util.Arrays.copyOf(a, a.length + 1);
- ...> b = java.util.Arrays.copyOf(b, b.length + 1);
- ...> position = a.length - 1;
- ...> a[position] = elem;
- ...> b[position] = 0;
- ...> }
- ...>
- ...> b[position]+=n;
- ...> }
- ...>
- ...> public void add(int elem) {
- ...> //aggiunge una copia di elem nell'array
- ...> add(elem, 1);
- ...> }
- ...>
- ...> public boolean remove(int elem, int n) {
- ...> int position = position(elem);
- ...> if(position == -1)
- ...> return false;
- ...>
- ...> b[position]-=n;
- ...> if(b[position] <= 0) {
- ...> //l'elemento va eliminato dall'array a e b
- ...> public class Foo implements IntMultiSet{ngth; i++) {
- ...> private int[] a; a[i];
- ...> private int[] b; b[i];
- ...> public Foo(int a_in[], int b_in[]) {
- ...> a = a_in;a.util.Arrays.copyOf(a, a.length - 1);
- ...> b = b_in;a.util.Arrays.copyOf(b, b.length - 1);
- ...> } }
- ...>
- ...> public int getCount(int elem) {
- ...> //cerca l'elemento e ne restituisce quante copie ve ne sono
- ...> for(int i = 0; i < a.length; i++)
- ...> if(a[i] == elem)e(int elem) {
- ...> return b[i];em, 1);
- ...> return 0;
- ...> }
- ...> public int size() {
- ...> public int position(int elem) {
- ...> //cerca la posizione dell'elemento elem in a. Se lo trova restituisc
- e la posizione altrimenti -1
- ...> for(int i = 0; i < a.length; i++)
- ...> if(a[i] == elem)
- ...> return i;
- ...> return -1;
- ...> }
- public void add(int elem, int n) {
- //aggiunge n occorrenze di elem
- int position = position(elem);
- if(position == -1) {
- //l'elemento non è presente nel multi-insieme, va aggiunta una pos
- izione all'array
- a = java.util.Arrays.copyOf(a, a.length + 1);
- b = java.util.Arrays.copyOf(b, b.length + 1);
- position = a.length - 1;
- a[position] = elem;
- b[position] = 0;
- }
- b[position]+=n;
- }
- public void add(int elem) {
- //aggiunge una copia di elem nell'array
- add(elem, 1);
- }
- public boolean remove(int elem, int n) {
- int position = position(elem);
- if(position == -1)
- return false;
- b[position]-=n;
- if(b[position] <= 0) {
- //l'elemento va eliminato dall'array a e b
- for(int i = position + 1; i < a.length; i++) {
- a[i - 1] = a[i];
- b[i - 1] = b[i];
- }
- a = java.util.Arrays.copyOf(a, a.length - 1);
- b = java.util.Arrays.copyOf(b, b.length - 1);
- }
- return true;
- }
- public boolean remove(int elem) {
- return remove(elem, 1);
- }
- public int size() {
- int sum = 0;
- for(int i = 0; i < b.length; i++)
- sum+=b[i];
- return sum;
- }
- }
- | created class Foo
- jshell> a;
- a ==> int[2] { 3, 7 }
- jshell> int a[5] = { 1, 3, 5, 7, 9 }
- | Error:
- | ']' expected
- | int a[5] = { 1, 3, 5, 7, 9 };
- | ^
- jshell> add (19, 382);
- jshell> add(283, 4924);
- jshell> add (1283, 293020392);
- jshell> a;b;
- a ==> int[5] { 3, 7, 19, 283, 1283 }
- b ==> int[5] { 292, 203, 382, 4924, 293020392 }
- jshell> Foo obj = new obj(a, b);
- | Error:
- | cannot find symbol
- | symbol: class obj
- | Foo obj = new obj(a, b);
- | ^-^
- jshell> Foo obj = new Foo(a, b);
- obj ==> Foo@200a570f
- jshell> obj.size;
- | Error:
- | cannot find symbol
- | symbol: variable size
- | obj.size;
- | ^------^
- jshell> obj.size();
- $71 ==> 293026193
- jshell> a;b;
- a ==> int[5] { 3, 7, 19, 283, 1283 }
- b ==> int[5] { 292, 203, 382, 4924, 293020392 }
- jshell> remove(3, 2934392);
- $74 ==> true
- jshell> int[] arr_fin = new int[0];
- arr_fin ==> int[0] { }
- jshell> obj.arr1;
- | Error:
- | cannot find symbol
- | symbol: variable arr1
- | obj.arr1;
- | ^------^
- jshell> obj.a;
- | Error:
- | a has private access in Foo
- | obj.a;
- | ^---^
- jshell> public class Foo implements IntMultiSet{
- ...> public int[] a;
- ...> public int[] b;
- ...> public Foo(int a_in[], int b_in[]) {
- ...> a = a_in;
- ...> b = b_in;
- ...> }
- ...>
- ...> public int getCount(int elem) {
- ...> //cerca l'elemento e ne restituisce quante copie ve ne sono
- ...> for(int i = 0; i < a.length; i++)
- ...> if(a[i] == elem)
- ...> return b[i];
- ...> return 0;
- ...> }
- ...>
- ...> public int position(int elem) {
- ...> //cerca la posizione dell'elemento elem in a. Se lo trova restituisce la posizione altrimenti -1
- ...> for(int i = 0; i < a.length; i++)
- ...> if(a[i] == elem)
- ...> return i;
- ...> return -1;
- ...> }
- ...>
- ...> public void add(int elem, int n) {
- ...> //aggiunge n occorrenze di elem
- ...> int position = position(elem);
- ...> if(position == -1) {
- ...> //l'elemento non è presente nel multi-insieme, va aggiunta una posizione all'array
- ...> a = java.util.Arrays.copyOf(a, a.length + 1);
- ...> b = java.util.Arrays.copyOf(b, b.length + 1);
- ...> position = a.length - 1;
- ...> a[position] = elem;
- ...> b[position] = 0;
- ...> }
- ...>
- ...> b[position]+=n;
- ...> }
- ...>
- ...> public void add(int elem) {
- ...> //aggiunge una copia di elem nell'array
- ...> add(elem, 1);
- ...> }
- ...>
- ...> public boolean remove(int elem, int n) {
- ...> int position = position(elem);
- ...> if(position == -1)
- ...> return false;
- ...>
- ...> b[position]-=n;
- ...> if(b[position] <= 0) {
- ...> public class Foo implements IntMultiSet{ay a e b
- ...> public int[] a; position + 1; i < a.length; i++) {
- ...> public int[] b;= a[i];
- ...> public Foo(int a_in[], int b_in[]) {
- ...> a = a_in;
- ...> b = b_in;a.util.Arrays.copyOf(a, a.length - 1);
- ...> } b = java.util.Arrays.copyOf(b, b.length - 1);
- ...> }
- ...> public int getCount(int elem) {
- ...> //cerca l'elemento e ne restituisce quante copie ve ne sono
- ...> for(int i = 0; i < a.length; i++)
- ...> if(a[i] == elem)
- ...> return b[i];ove(int elem) {
- ...> return 0;move(elem, 1);
- ...> }
- ...>
- ...> public int position(int elem) {
- ...> //cerca la posizione dell'elemento elem in a. Se lo trova restituisc
- e la posizione altrimenti -1 < b.length; i++)
- ...> for(int i = 0; i < a.length; i++)
- ...> if(a[i] == elem)
- ...> return i;
- ...> return -1;
- ...> }
- public void add(int elem, int n) {
- //aggiunge n occorrenze di elem
- int position = position(elem);
- if(position == -1) {
- //l'elemento non è presente nel multi-insieme, va aggiunta una pos
- izione all'array
- a = java.util.Arrays.copyOf(a, a.length + 1);
- b = java.util.Arrays.copyOf(b, b.length + 1);
- position = a.length - 1;
- a[position] = elem;
- b[position] = 0;
- }
- b[position]+=n;
- }
- public void add(int elem) {
- //aggiunge una copia di elem nell'array
- add(elem, 1);
- }
- public boolean remove(int elem, int n) {
- int position = position(elem);
- if(position == -1)
- return false;
- b[position]-=n;
- if(b[position] <= 0) {
- //l'elemento va eliminato dall'array a e b
- for(int i = position + 1; i < a.length; i++) {
- a[i - 1] = a[i];
- b[i - 1] = b[i];
- }
- a = java.util.Arrays.copyOf(a, a.length - 1);
- b = java.util.Arrays.copyOf(b, b.length - 1);
- }
- return true;
- }
- public boolean remove(int elem) {
- return remove(elem, 1);
- }
- public int size() {
- int sum = 0;
- for(int i = 0; i < b.length; i++)
- sum+=b[i];
- return sum;
- }
- }
- | replaced class Foo
- | update replaced variable obj, reset to null
- jshell> public class Foo implements IntMultiSet{
- ...> public int[] a;
- ...> public int[] b;
- ...> public Foo(int a_in[], int b_in[]) {
- ...> a = a_in;
- ...> b = b_in;
- ...> }
- ...>
- ...> public int getCount(int elem) {
- ...> //cerca l'elemento e ne restituisce quante copie ve ne sono
- ...> for(int i = 0; i < a.length; i++)
- ...> if(a[i] == elem)
- ...> return b[i];
- ...> return 0;
- ...> }
- ...>
- ...> public int position(int elem) {
- ...> //cerca la posizione dell'elemento elem in a. Se lo trova restituisce la posizione altrimenti -1
- ...> for(int i = 0; i < a.length; i++)
- ...> if(a[i] == elem)
- ...> return i;
- ...> return -1;
- ...> }
- ...>
- ...> public void add(int elem, int n) {
- ...> //aggiunge n occorrenze di elem
- ...> int position = position(elem);
- ...> if(position == -1) {
- ...> //l'elemento non è presente nel multi-insieme, va aggiunta una posizione all'array
- ...> a = java.util.Arrays.copyOf(a, a.length + 1);
- ...> b = java.util.Arrays.copyOf(b, b.length + 1);
- ...> position = a.length - 1;
- ...> a[position] = elem;
- ...> b[position] = 0;
- ...> }
- ...>
- ...> b[position]+=n;
- ...> }
- ...>
- ...> public void add(int elem) {
- ...> //aggiunge una copia di elem nell'array
- ...> add(elem, 1);
- ...> }
- ...>
- ...> public boolean remove(int elem, int n) {
- ...> int position = position(elem);
- ...> if(position == -1)
- ...> return false;
- ...>
- ...> b[position]-=n;
- ...>
- obj.a;
- | Exception java.lang.NullPointerException
- | at (#77:1)
- jshell> obj.a;
- | Exception java.lang.NullPointerException
- | at (#78:1)
- jshell> obj;
- obj ==> null
- jshell> Foo obj = new Foo(a, b);
- obj ==> Foo@299a06ac
- jshell> obj;
- obj ==> Foo@299a06ac
- jshell> obj.a;
- $82 ==> int[4] { 7, 19, 283, 1283 }
- jshell> obj1.a.length
- | Error:
- | package obj1 does not exist
- | obj1.a.length
- | ^----^
- jshell> obj.a.length;
- $83 ==> 4
- jshell> public void Union(Foo obj1, Foo obj2) {
- ...> private int[] arr_a_tmp = new int[0];
- ...> private int arr_b_tmp = new int[0];
- ...> Foo obj_fin = new Foo(arr_a_tmp, arr_b_tmp);
- ...> for(int i = 0; i < obj1.a.length; i++) {
- ...> if(obj2.position(obj1.a[i]) != -1)
- ...> obj_fin.add(obj1.a[i], max(obj1.b[i], obj2.position(obj1.a[i])));
- ...> }
- ...> }
- | Error:
- | illegal start of expression
- | private int[] arr_a_tmp = new int[0];
- | ^
- jshell> public void Union(Foo obj1, Foo obj2) {
- ...> int[] arr_a_tmp = new int[0];
- ...> int arr_b_tmp = new int[0];
- ...> Foo obj_fin = new Foo(arr_a_tmp, arr_b_tmp);
- ...> for(int i = 0; i < obj1.a.length; i++) {
- ...> if(obj2.position(obj1.a[i]) != -1)
- ...> obj_fin.add(obj1.a[i], max(obj1.b[i], obj2.position(obj1.a[i])));
- ...> }
- ...> }
- | Error:
- | incompatible types: int[] cannot be converted to int
- | int arr_b_tmp = new int[0];
- | ^--------^
- | Error:
- | incompatible types: int cannot be converted to int[]
- | Foo obj_fin = new Foo(arr_a_tmp, arr_b_tmp);
- | ^-------^
- | Error:
- | cannot find symbol
- | symbol: method max(int,int)
- | obj_fin.add(obj1.a[i], max(obj1.b[i], obj2.position(obj1.a[i])));
- | ^-^
- jshell> public int max (int el1, int el2) {
- ...> if(el1 > el2)
- ...> return el1;
- ...> else
- ...> return el2;
- ...> }
- | created method max(int,int)
- jshell> public void Union(Foo obj1, Foo obj2) {
- ...> int[] arr_a_tmp = new int[0];
- ...> int arr_b_tmp = new int[0];
- ...> Foo obj_fin = new Foo(arr_a_tmp, arr_b_tmp);
- ...> for(int i = 0; i < obj1.a.length; i++) {
- ...> if(obj2.position(obj1.a[i]) != -1)
- ...> obj_fin.add(obj1.a[i], max(obj1.b[i], obj2.position(obj1.a[i])));
- ...> }
- ...> }
- ...>
- | Error:
- | incompatible types: int[] cannot be converted to int
- | int arr_b_tmp = new int[0];
- | ^--------^
- | Error:
- | incompatible types: int cannot be converted to int[]
- | Foo obj_fin = new Foo(arr_a_tmp, arr_b_tmp);
- | ^-------^
- jshell> public void Union(Foo obj1, Foo obj2) {
- ...> int[] arr_a_tmp = new int[0];
- ...> int arr_b_tmp = new int[0];
- ...> Foo obj_fin = new Foo(arr_a_tmp, arr_b_tmp);
- ...> for(int i = 0; i < obj1.a.length; i++) {
- ...> if(obj2.position(obj1.a[i]) != -1)
- ...> obj_fin.add(obj1.a[i], max(obj1.b[i], obj2.b[obj2.position(obj1.a[i])]);
- ...> }
- ...> }
- | Error:
- | ')' expected
- | obj_fin.add(obj1.a[i], max(obj1.b[i], obj2.b[obj2.position(obj1.a[i])]);
- | ^
- jshell> public void Union(Foo obj1, Foo obj2) {
- ...> int[] arr_a_tmp = new int[0];
- ...> int arr_b_tmp = new int[0];
- ...> Foo obj_fin = new Foo(arr_a_tmp, arr_b_tmp);
- ...> for(int i = 0; i < obj1.a.length; i++) {
- ...> if(obj2.position(obj1.a[i]) != -1)
- ...> obj_fin.add(obj1.a[i], max(obj1.b[i], obj2.b[obj2.position(obj1.a[i])]));
- ...> }
- ...> }
- | Error:
- | incompatible types: int[] cannot be converted to int
- | int arr_b_tmp = new int[0];
- | ^--------^
- | Error:
- | incompatible types: int cannot be converted to int[]
- | Foo obj_fin = new Foo(arr_a_tmp, arr_b_tmp);
- | ^-------^
- jshell> public void Union(Foo obj1, Foo obj2) {
- ...> int[] arr_a_tmp = new int[0];
- ...> int[] arr_b_tmp = new int[0];
- ...> Foo obj_fin = new Foo(arr_a_tmp, arr_b_tmp);
- ...> for(int i = 0; i < obj1.a.length; i++) {
- ...> if(obj2.position(obj1.a[i]) != -1)
- ...> obj_fin.add(obj1.a[i], max(obj1.b[i], obj2.b[obj2.position(obj1.a[i])]));
- ...> }
- ...> }
- ...>
- | created method Union(Foo,Foo)
- jshell> a;b;
- a ==> int[4] { 7, 19, 283, 1283 }
- b ==> int[4] { 203, 382, 4924, 293020392 }
- jshell> int[] c = new int {7, 19, 28, 39, 27, 47 };
- | Error:
- | '[' expected
- | int[] c = new int {7, 19, 28, 39, 27, 47 };
- | ^
- | Error:
- | illegal start of expression
- | int[] c = new int {7, 19, 28, 39, 27, 47 };
- | ^
- jshell> int[] c = {7, 19, 28, 39, 27, 47 };
- c ==> int[6] { 7, 19, 28, 39, 27, 47 }
- jshell> int[] d = {200, 10, 2391, 28283, 2993, 2939 }
- d ==> int[6] { 200, 10, 2391, 28283, 2993, 2939 }
- jshell> foo.a;
- | Error:
- | cannot find symbol
- | symbol: variable foo
- | foo.a;
- | ^-^
- jshell> Foo obj1 = new Foo(a, b);
- obj1 ==> Foo@5577140b
- jshell> Foo obj2 = new Foo(c, d);
- obj2 ==> Foo@67f89fa3
- jshell> public Foo Union(Foo obj1, Foo obj2) {
- ...> int[] arr_a_tmp = new int[0];
- ...> int[] arr_b_tmp = new int[0];
- ...> Foo obj_fin = new Foo(arr_a_tmp, arr_b_tmp);
- ...> for(int i = 0; i < obj1.a.length; i++) {
- ...> if(obj2.position(obj1.a[i]) != -1)
- ...> obj_fin.add(obj1.a[i], max(obj1.b[i], obj2.b[obj2.position(obj1.a[i])]));
- ...> }
- ...> return obj_fin;
- ...> }
- | replaced method Union(Foo,Foo)
- jshell> Union(obj1, obj2);
- $93 ==> Foo@6073f712
- jshell> Foo objunion = Union(obj1, obj2);
- objunion ==> Foo@3d04a311
- jshell> obj1.a; obj1.b; obj2.a; obj2.b;
- $95 ==> int[4] { 7, 19, 283, 1283 }
- $96 ==> int[4] { 203, 382, 4924, 293020392 }
- $97 ==> int[6] { 7, 19, 28, 39, 27, 47 }
- $98 ==> int[6] { 200, 10, 2391, 28283, 2993, 2939 }
- jshell> objunion.a; objunion.b;
- $99 ==> int[2] { 7, 19 }
- $100 ==> int[2] { 203, 382 }
- jshell> public int min (int el1, int el2) {
- ...> if(el1 > el2)
- ...> return el2;
- ...> else
- ...> return el1;
- ...> }
- ...>
- ...> public Foo Intersect(Foo obj1, Foo obj2) {
- ...> int[] arr_a_tmp = new int[0];
- ...> int[] arr_b_tmp = new int[0];
- ...> Foo obj_fin = new Foo(arr_a_tmp, arr_b_tmp);
- ...> for(int i = 0; i < obj1.a.length; i++) {
- ...> if(obj2.position(obj1.a[i]) != -1)
- ...> obj_fin.add(obj1.a[i], min(obj1.b[i], obj2.b[obj2.position(obj1.a[i])]));
- ...> }
- ...> return obj_fin;
- ...> }
- | created method min(int,int)
- | created method Intersect(Foo,Foo)
- jshell> Foo objintersect = Intersect(obj1,obj2);
- objintersect ==> Foo@57fa26b7
- jshell> objintersect.a; onjintersect.b;
- $104 ==> int[2] { 7, 19 }
- | Error:
- | cannot find symbol
- | symbol: variable onjintersect
- | onjintersect.b;
- | ^----------^
- jshell> objintersect.a; objintersect.b;
- $105 ==> int[2] { 7, 19 }
- $106 ==> int[2] { 200, 10 }
- jshell> public Foo Union(Foo obj1, Foo obj2) {
- ...> int[] arr_a_tmp = new int[0];
- ...> int[] arr_b_tmp = new int[0];
- ...> Foo obj_fin = new Foo(arr_a_tmp, arr_b_tmp);
- ...> for(int i = 0; i < obj1.a.length; i++)
- ...> obj_fin.add(obj1.a[i], obj1.b[i]);
- ...> for(int i = 0; i < obj1.a.length; i++)
- ...> obj_fin.add(obj2.a[i], obj2.b[i]);
- ...> return obj_fin;
- ...> }
- | modified method Union(Foo,Foo)
- jshell> Foo objunion = Union(obj1, obj2);
- objunion ==> Foo@4141d797
- jshell> obj1.a; obj1.b; obj2.a; obj2.b; objintersect.a; onjintersect.b; objunion.a; objunion.b;
- $109 ==> int[4] { 7, 19, 283, 1283 }
- $110 ==> int[4] { 203, 382, 4924, 293020392 }
- $111 ==> int[6] { 7, 19, 28, 39, 27, 47 }
- $112 ==> int[6] { 200, 10, 2391, 28283, 2993, 2939 }
- $113 ==> int[2] { 7, 19 }
- | Error:
- | cannot find symbol
- | symbol: variable onjintersect
- | onjintersect.b;
- | ^----------^
- jshell> obj1.a; obj1.b; obj2.a; obj2.b; objintersect.a; objintersect.b; objunion.a; objunion.b;
- $114 ==> int[4] { 7, 19, 283, 1283 }
- $115 ==> int[4] { 203, 382, 4924, 293020392 }
- $116 ==> int[6] { 7, 19, 28, 39, 27, 47 }
- $117 ==> int[6] { 200, 10, 2391, 28283, 2993, 2939 }
- $118 ==> int[2] { 7, 19 }
- $119 ==> int[2] { 200, 10 }
- $120 ==> int[6] { 7, 19, 283, 1283, 28, 39 }
- $121 ==> int[6] { 403, 392, 4924, 293020392, 2391, 28283 }
- jshell> public Foo Union(Foo obj1, Foo obj2) {
- ...> int[] arr_a_tmp = new int[0];
- ...> int[] arr_b_tmp = new int[0];
- ...> Foo obj_fin = new Foo(arr_a_tmp, arr_b_tmp);
- ...> for(int i = 0; i < obj1.a.length; i++)
- ...> obj_fin.add(obj1.a[i], obj1.b[i]);
- ...> for(int i = 0; i < obj2.a.length; i++)
- ...> obj_fin.add(obj2.a[i], obj2.b[i]);
- ...> return obj_fin;
- ...> }
- | modified method Union(Foo,Foo)
- jshell> Foo objunion = Union(obj1, obj2);
- objunion ==> Foo@3339ad8e
- jshell> obj1.a; obj1.b; obj2.a; obj2.b; objintersect.a; objintersect.b; objunion.a; objunion.b;
- ...>
- $124 ==> int[4] { 7, 19, 283, 1283 }
- $125 ==> int[4] { 203, 382, 4924, 293020392 }
- $126 ==> int[6] { 7, 19, 28, 39, 27, 47 }
- $127 ==> int[6] { 200, 10, 2391, 28283, 2993, 2939 }
- $128 ==> int[2] { 7, 19 }
- $129 ==> int[2] { 200, 10 }
- $130 ==> int[8] { 7, 19, 283, 1283, 28, 39, 27, 47 }
- $131 ==> int[8] { 403, 392, 4924, 293020392, 2391, 28283, 2993, 2939 }
- jshell>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement