Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Hello, I want comments on each of the following coding lines. short comments for understanding the codes. Thank you. public class FoodListArray implements FoodListInterface {

Hello, I want comments on each of the following coding lines. short comments for understanding the codes. Thank you.

public class FoodListArray implements FoodListInterface { protected String[] foods; protected final int DEFSIZE = 100; protected int numElements; public FoodListArray() { foods = new String[DEFSIZE]; } public FoodListArray(int size) { foods = new String[size]; }

@Override public void add(String food) { foods[numElements] = food; numElements++; }

@Override public boolean onThisList(String food) { for (int i = 0; i < numElements; i++) { if (food.equalsIgnoreCase(foods[i])) { return true; } }

return false; } public String toString() { String list = ""; for (int i = 0; i < numElements; i++) { list = list + foods[i] + " "; } return list; }

}

public interface FoodListInterface { void add(String food); boolean onThisList(String food);

}

public class Array_Test {

public static void main(String[] args) { FoodListArray fav1 = new FoodListArray(); fav1.add("Bhagiya"); fav1.add("pasta"); fav1.add("chicken"); fav1.add("burger"); fav1.add("fries"); fav1.add("chips"); fav1.add("wings"); System.out.println("My favorite foods are: "); System.out.println(fav1); System.out.println("Is Fettucine alfredo on your favorites list?"); if (fav1.onThisList("Fettucine alfredo")) System.out.println("Yes, Fettucine alfredo is one of my favorites. "); else System.out.println("No, Fettucine alfredo is not one of my favorites. "); System.out.println("Is chicken on your favorites list?"); System.out.println(fav1.onThisList("chicken") ? "Yes, chicken is on the list" : "No, chicken is not on the list"); }

}

public class LLStringNode { private String info; private LLStringNode next; public LLStringNode(String info) { this.info = info; next = null; } public void setInfo(String info) { this.info = info; }

public String getInfo() { return info; } public void setNext(LLStringNode next) { this.next = next; }

public LLStringNode getNext() { return next; }

}

import java.util.ArrayList; public class FoodArrayList_Test { public static void main(String[] args) { ArrayList list = new ArrayList(); list.add("Bhagiya"); list.add("pasta"); list.add("chicken"); list.add("burger"); list.add("fries"); list.add("chips"); list.add("wings");

System.out.println(" My favorite foods are: " + list + " "); System.out.println("Is Fettucine alfredo on your favorites list?"); if (list.contains(" Fettucine alfredo ")) System.out.println("Yes, Fettucine alfredo is one of my favorites. "); else System.out.println("No, Fettucine alfredo is not one of my favorites. "); System.out.println("Is chicken on your favorites list?"); System.out.println(list.contains("chicken ") ? "Yes, chicken is on the list" : "No, chicken is not the list");

}

}

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

Information Modeling And Relational Databases

Authors: Terry Halpin, Tony Morgan

2nd Edition

0123735688, 978-0123735683

More Books

Students also viewed these Databases questions

Question

1. Which position would you take?

Answered: 1 week ago