Answered step by step
Verified Expert Solution
Link Copied!

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

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

Introduction to Wireless and Mobile Systems

Authors: Dharma P. Agrawal, Qing An Zeng

4th edition

1305087135, 978-1305087132, 9781305259621, 1305259629, 9781305537910 , 978-130508713

More Books

Students also viewed these Programming questions