Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Please help me, and simply explain some key steps. Thank YOU! Part 1a. We already discussed Intcoll1client and Intcoll1 in class. Add any code still

Please help me, and simply explain some key steps. Thank YOU!

Part 1a. We already discussed Intcoll1client and Intcoll1 in class. Add any code still needed for the methods. Also add documentation to each of the 9 methods of the class. These methods are the default and alternate constructors - Intcoll1() and Intcoll1(int i), and void copy(Intcoll1 obj) boolean belongs(int i) void insert(int i) void omit(int i) int get_howmany() void print() boolean equals(Intcoll1 obj) Run Intcoll1client using the Intcoll1 class on a number of different inputs to test the class. Choose the inputs with some thought to try to cover special cases and more general inputs.

Part 1b. Here you must first create Intcoll2 which has the same methods as Intcoll1 but doesn't use a zero in array c to signify the end of the integers stored in c. Instead it has another private member how_many that contains the number of integers in the collection. These integers are also stored at the top of array c. After adding how_many as a member you need to write the code for each method of Intcoll2. To do this, consider the code for each method of Intcoll1 and see how it needs to be changed to carry out its task correctly for Intcoll2. Be sure to write a more efficient equals method. Of course the same documentation will be used for Intcoll2 as for Intcoll1.

Run Intcoll2client using the Intcoll2 class on a number of different inputs to test the class. Choose the inputs with some thought to try to cover special cases and more general inputs.

Part1c. This is just like Part 1b except it involves Intcoll3client and the Intcoll3 class. The Intcoll3 class uses private members c and how_many. The array c is now of type boolean and contains a true value in slot i if the integer i is in the collection and false otherwise. This version of the Intcoll class is simpler than the other versions in some ways but more complicated in others. Whenever an integer needs to be inserted into the collection and c is not large enough to accept it then you must increase the size of c to accomodate the new integer before adding it.

Intcoll1 Code:

image text in transcribedimage text in transcribed

import java.util.*;public class Intcoll1{ private int[] c; public Intcoll1() { c = new int[500+1]; c[0] = 0; } public Intcoll1(int i) { c = new int[i+1]; c[0] = 0; } public void copy(Intcoll1 obj) { if (this != obj) { c = new int[obj.c.length]; int j = 0; while (obj.c[j] != 0) {c[j] = obj.c[j]; j++; } c[j] = 0;} } public boolean belongs(int i) { int j = 0; while ((c[j] != 0)&&(c[j] != i)) j++; return (c[j] != 0); } public void insert(int i) { if (i > 0){ int j = 0; while ((c[j] != 0) && (c[j] != i)) j++; if (c[j] == 0) {if (j == c.length - 1){ // ADD CODE HERE}c[j] = i; c[j + 1] = 0;

}} } public void omit(int i) { if (i>0) { int j = 0; while ((c[j] != 0)&&(c[j] != i)) j++; if (c[j] == i) { int k = j+1; while (c[k] != 0) k++; c[j] = c[k-1]; c[k-1]=0; } } } public int get_howmany() { int j=0, howmany=0; while (c[j]!=0) {howmany++; j++;} return howmany; } public void print() { int j = 0; System.out.println(); while (c[j] != 0) { System.out.println(c[j]); j++; } } public boolean equals(Intcoll1 obj) { int j = 0; boolean result = true; while ((c[j] != 0)&&result) { result = obj.belongs(c[j]); j++; } j = 0; while ((obj.c[j] != 0)&&result) { result = belongs(obj.c[j]); j++; } return result; }}

Intcoll1client code:image text in transcribed

import java.util.*;public class Intcoll1client{ public static final int SENTINEL = 0; public static void main(String[] args) { int value; Scanner keyboard=new Scanner(System.in); Intcoll1 P=new Intcoll1(), N=new Intcoll1(), L= new Intcoll1(); System.out.println("Enter an integer to be inserted or 0 to quit:"); value=keyboard.nextInt(); while(value != SENTINEL) { if (value > 0) {P.insert(value); L.insert(value);} else {N.insert(-value); L.omit(-value);} System.out.println("Enter next integer to be inserted or 0 to quit:"); value=keyboard.nextInt(); } System.out.println(" The values in collection P are:"); P.print(); System.out.println(" The values in collection N are:"); N.print(); System.out.println(" The values in collection L are:"); L.print(); if (P.equals(N)) System.out.println(" P and N are equal."); else System.out.println(" P and N are NOT equal."); Intcoll1 A=new Intcoll1(); A.copy(L); System.out.println(" The values in the copy of L are: "); A.print(); }}

import java.util.*; public class Intcolli { private int[] c; public Intcoll10 { c = new int[500+1]; C[0] = 0; } public Intcoll1(int i) { c = new int[i+1]; C[0] = 0; } public void copy(Intcolli obj) { if (this != obj) { c = new int[obj.c. length]; int j = 0; while (obj.c[i] != 0) { c[i] = obj.c[i]; j++; } c[j] = 0; } } public boolean belongs (int i) { int j = 0; while (C[j] != 0)&&(c[i] != 1)) j++; return (c[i] != 0); } public void insert(int i) { if (i > 0) { int j = 0; while ((c[i] != ) && (c[i] != i) j++; if (c[i] == 0) { if (j == c. length - 1) { // ADD CODE HERE } c[i] = i; c[j + 1] = 0; } } } public void omit(int i) { if (i>) { int j = 0; while ((c[i] != )&&(c[i] != i) j++; if (c[i] == i) { int k = j+1; while (c[k] != 0) k++; c[i] = C[k-1]; C[k-1)=0; } } } public int get_howmany) { int j=0, howmany=0; while (c[i]!=0) {howmany++; j++;} return howmany; } public void print() { int j = 0; System.out.println(); while (c[i] != 0) { System.out.println(c[j]); j++; } } public boolean equals(Intcolli obj) { int j = 0; boolean result = true; while ((c[i] != )&&result) { result = obj. belongs (c[i]); j++; } j = 0; while ((obj.c[j] != )&&result) { result = belongs(obj.c[i]); j++; } return result; } } import java.util.*; public class Intcolliclient { public static final int SENTINEL = 0; public static void main(String[] args) { int value; Scanner keyboard=new Scanner(System.in); Intcolli P=new Intcoll1(), N=new Intcolli(), L= new Intcoll1(); System.out.println("Enter an integer to be inserted or o to quit:"); value=keyboard.nextInt(); while(value != SENTINEL) { if (value > 0) {P.insert(value); L.insert(value); } else {N.insert(value); L.omit(-value);} System.out.println("Enter next integer to be inserted or o to quit:"); value=keyboard.nextInt(); } System.out.println(" The values in collection P are:"); P.print(); System.out.println(" The values in collection N are:"); N.print(); System.out.println(" The values in collection L are:"); L.print(); if (P.equals(N)) System.out.println(" P and N are equal."); else System.out.println(" P and N are NOT equal."); Intcoll1 A=new Intcoll1(); A.copy(L); System.out.println(" The values in the copy of L are: "); A.print(); } } import java.util.*; public class Intcolli { private int[] c; public Intcoll10 { c = new int[500+1]; C[0] = 0; } public Intcoll1(int i) { c = new int[i+1]; C[0] = 0; } public void copy(Intcolli obj) { if (this != obj) { c = new int[obj.c. length]; int j = 0; while (obj.c[i] != 0) { c[i] = obj.c[i]; j++; } c[j] = 0; } } public boolean belongs (int i) { int j = 0; while (C[j] != 0)&&(c[i] != 1)) j++; return (c[i] != 0); } public void insert(int i) { if (i > 0) { int j = 0; while ((c[i] != ) && (c[i] != i) j++; if (c[i] == 0) { if (j == c. length - 1) { // ADD CODE HERE } c[i] = i; c[j + 1] = 0; } } } public void omit(int i) { if (i>) { int j = 0; while ((c[i] != )&&(c[i] != i) j++; if (c[i] == i) { int k = j+1; while (c[k] != 0) k++; c[i] = C[k-1]; C[k-1)=0; } } } public int get_howmany) { int j=0, howmany=0; while (c[i]!=0) {howmany++; j++;} return howmany; } public void print() { int j = 0; System.out.println(); while (c[i] != 0) { System.out.println(c[j]); j++; } } public boolean equals(Intcolli obj) { int j = 0; boolean result = true; while ((c[i] != )&&result) { result = obj. belongs (c[i]); j++; } j = 0; while ((obj.c[j] != )&&result) { result = belongs(obj.c[i]); j++; } return result; } } import java.util.*; public class Intcolliclient { public static final int SENTINEL = 0; public static void main(String[] args) { int value; Scanner keyboard=new Scanner(System.in); Intcolli P=new Intcoll1(), N=new Intcolli(), L= new Intcoll1(); System.out.println("Enter an integer to be inserted or o to quit:"); value=keyboard.nextInt(); while(value != SENTINEL) { if (value > 0) {P.insert(value); L.insert(value); } else {N.insert(value); L.omit(-value);} System.out.println("Enter next integer to be inserted or o to quit:"); value=keyboard.nextInt(); } System.out.println(" The values in collection P are:"); P.print(); System.out.println(" The values in collection N are:"); N.print(); System.out.println(" The values in collection L are:"); L.print(); if (P.equals(N)) System.out.println(" P and N are equal."); else System.out.println(" P and N are NOT equal."); Intcoll1 A=new Intcoll1(); A.copy(L); System.out.println(" The values in the copy of L are: "); A.print(); } }

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Logistics Lifeline Supply Chain Strategies

Authors: Ehsan Sheroy

1st Edition

7419377502, 978-7419377503

More Books

Students also viewed these Databases questions