Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

*IN JAVA* ADD TO THE FOLLOWING CODE BELOW at the //add code here. FOLLOW ALL DIRECTIONS AND SHOW PROOF OF CODE WORKING LOOK AT PICS

*IN JAVA* ADD TO THE FOLLOWING CODE BELOW at the //add code here. FOLLOW ALL DIRECTIONS AND SHOW PROOF OF CODE WORKING LOOK AT PICS FOR CODE GIVEN
1) Code to create a Selection Sort algorithm that sorts the elements in the arrayList based on the integers that are in the arrayList given below. Then print the arrayList after sorting it
2Now, code to randomize the order of the objects in the arrayList given below. Print the arrayList after randomizing it.
3Finally, code to create an Insertion Sort Algorithm that sorts the elements in the arrayList based on the integers that are in the arrayList given below. Then print the arrayList after sorting it.
image text in transcribed
image text in transcribed
image text in transcribed
import java.util.*;
class Main {
public static void main(String[] args) {
class Restaurant
{
private String food;
private int orderNumber;
private double cost;
public Restaurant(String foodName, int orderNum, double price)
{
food = foodName;
orderNumber = orderNum;
cost = price;
}
public String toString()
{
return food + ": #" + orderNumber + ": $" + cost;
}
}
ArrayList chickFilA = new ArrayList();
chickFilA.add(new Restaurant("Chick-fil-A Chicken", 1, 6.75));
chickFilA.add(new Restaurant("Chick-fil-A Nuggets", 3, 5.75));
chickFilA.add(new Restaurant("Grilled Chicken", 5, 8.15));
chickFilA.add(new Restaurant("Spicy Deluxe", 2, 7.59));
chickFilA.add(new Restaurant("Waffle Potato Fries", 10, 2.35));
chickFilA.add(new Restaurant("Grilled Cool Wrap", 8, 9.09));
chickFilA.add(new Restaurant("Chick-n-Strips", 4, 7.09));
chickFilA.add(new Restaurant("Chicken Salad Sandwich", 9, 7.69));
chickFilA.add(new Restaurant("Grilled Nuggets", 6, 7.65));
chickFilA.add(new Restaurant("Grilled Chicken Club", 7, 9.45));
System.out.println(chickFilA);
chickFilA.add(3,new Restaurant("Soup and Salad", 12, 7.19));
System.out.println(chickFilA);
chickFilA.remove(7);
System.out.println(chickFilA);
chickFilA.set(5, chickFilA.get(0));
//add code here
}
}
M Main.java 1. import java.util.; 2. class Main 3- public static void main(String[] args) { 4 class Restaurant { private String food; private int orderNumber: private double cost; public Restaurant (String foodName, int ordernum, double price) { food = foodName; order Number = ordernum; cost = price; } public String toString() { return food + ": #" + orderNumber + ": $" + cost; } } 5 6 7- 8 9 10 11 12 13- 14 15 16 17 18 19 20 21 - 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 - 49 50- 51 52 53 54 55 ArrayList(); chickFilA.add(new Restaurant("Chick-fil-A Chicken", 1, 6.75)); chickFil.add(new Restaurant("Chick-fil-A Nuggets", 3, 5.75)); chickFilA.add(new Restaurant("Grilled Chicken", 5, 8.15)); chickFilA.add(new Restaurant ("Spicy Deluxe", 2, 7.59)); chickFilA.add(new Restaurant ("Waffle Potato Fries", 10, 2.35)); chickFilA.add(new Restaurant("Grilled Cool Wrap", 8, 9.09)); chickFilA.add(new Restaurant("Chick-n-Strips", 4, 7.09)); chickFilA.add(new Restaurant("Chicken Salad Sandwich", 9, 7.69)); chickFilA.add(new Restaurant ("Grilled Nuggets", 6, 7.65)); chickFilA.add(new Restaurant ("Grilled Chicken Club", 7, 9.45)); System.out.println(chickFilA); chickFilA.add(3, new Restaurant ("Soup and Salad", 12, 7.19)); System.out.println(chickFilA); chickFilA.remove(7); System.out.println(chickFilA); chickFilA.set(5, chickFilA.get(0)); double minDouble = 99; for(Restaurant restaurant: chickFil) { if(restaurant.cost maxInt) { maxInt - restaurant.orderNumber; } System.out.println("Maximum of the integers is " + max Int); int lengthSum = 0; int count = 0; for(Restaurant restaurant:chickFila) { lengthSum=restaurant.food. Length(); count++; } System.out.println("Average Length of Strings is " + lengthSum/count); //duplicates here later for(Restaurant restaurant:chickFila) { if(restaurant.orderNumber 3 == ) System.out.println("Number" + restaurant.orderNumber +" is divisible by 3"); { > } Collections.reversechickFilA)://yes I know there is another way to reverse the ArrayList but this method is much more efficient System.out.println(chickFil); int index = 0, i=0; Restaurant currentobj = chickFit.get(index); Restaurant temp = null; while(i

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

Pro Database Migration To Azure Data Modernization For The Enterprise

Authors: Kevin Kline, Denis McDowell, Dustin Dorsey, Matt Gordon

1st Edition

1484282299, 978-1484282298

More Books

Students also viewed these Databases questions

Question

what is a peer Group? Importance?

Answered: 1 week ago

Question

What are Measures in OLAP Cubes?

Answered: 1 week ago

Question

How do OLAP Databases provide for Drilling Down into data?

Answered: 1 week ago

Question

How are OLAP Cubes different from Production Relational Databases?

Answered: 1 week ago