Answered step by step
Verified Expert Solution
Question
1 Approved Answer
When compiling a class in Java, I am getting these errors. Any suggestions? error: incompatible types: void cannot be converted to Item[] Item[] result =
When compiling a class in Java, I am getting these errors. Any suggestions?
error: incompatible types: void cannot be converted to Item[] Item[] result = t1.sortName(); ^ error: incompatible types: void cannot be converted to Item[] result = t1.sortName(); ^ error: incompatible types: void cannot be converted to Item[] Item[] result = t1.sortQuant(); ^ error: incompatible types: void cannot be converted to Item[] result = t1.sortQuant(); ^ error: incompatible types: void cannot be converted to Item[] Item[] result = t1.sortName();
Here is my code:
public class GroceryList { private int count; private Item list[]; private static final int MAX = 30; public GroceryList() { this.count = 0; this.list = new Item[MAX]; } public GroceryList(Item[] source) { this.count = 0; this.list = new Item[MAX]; for (int i = 0; i < source.length; i++) { list[count] = source[i]; count++; } } public int getCount() { return count; } public void addItem(Item item) { if (count != MAX) { this.list[count] = item; count++; } else { System.out.println("** List is full **"); } } public void deleteItem(int indx) { if (count != 0) { for (int i = indx - 1; i < count - 1; i++) { list[i] = list[i + 1]; } count--; } } public void sortName() { Item temp; if (count > 0) { for (int i = 0; i < count; i++) { for (int j = i + 1; j < count; j++) { if (list[i].getItem().compareTo(list[j].getItem()) > 0) { temp = list[i]; list[i] = list[j]; list[j] = temp; } } } } } public Item getItem(int i) { if(i < 0 || i > count - 1 ) { return null; }else { return list[i]; } } public void sortQuant() { Item temp; if (count > 0) { for (int i = 0; i < count; i++) { for (int j = i + 1; j < count; j++) { if (list[j].getQuantity() > list[i].getQuantity()) { temp = list[i]; list[i] = list[j]; list[j] = temp; } } } } } @Override public String toString() { String str=""; for(int z = 0;z
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started