NameSorter.java Name.java import java.util.Scanner; import java.util.ArrayList; import java.util.Collections; public class NameSorter { public static void main (String [] args) { Scanner scnr = new Scanner (System.in); final int NUM_ELEMENTS = 4; Name newName; ArrayList userNames = new ArrayList (); String firstName; String lastName; Input Ethan Phegley Ethan Kreider Chris Kreider Ginny Edger int i; for (i = 0; i < NUM_ELEMENTS; ++i) { firstName - scnr.next (); lastName - scnr.next (); newName - new Name (firstName, lastName); userNames.add (newName); Output Collections.sort (userNames); for (1 - 0; i < NUM_ELEMENTS; ++1) { System.out.println (userNames.get (i));
Q: A supermarket wants to reward its best customer of each day, showing the customer’s name on a screen…
A: Actually, Java is an Object Oriented Programming language which is platform independent and robust…
Q: java Create a static method that: is called appendPosSum returns an ArrayList of Integers takes…
A: public static void main(String[] args) { Scanner in = new Scanner(System.in); int size =…
Q: For any element in keysList with a value greater than 40, print the corresponding value in…
A: import java.util.Scanner;public class LongestLine {public static void main(String args[]) {final int…
Q: nd customer code (either R for residential, C for commercial) for each row. For residential…
A: Solution for the following question is as follows:
Q: I have a code for an assignment, but the code isn't working please help me. The code of the…
A: The exception shown in the picture occurs when we try to access the file which is not available in…
Q: Write a for loop to initialize the objects in the ArrayList created in question number 2 above to…
A: ArrayList is a dynamic data structure class that takes Object data type. The array list grows and…
Q: Create a data class named Automobile that implements the Comparable interface. Give the class data…
A: the java program is an given below :
Q: Write the missing statements as per given comments to complete the programs. Java program for…
A: The required code is as follows:-
Q: Consider the following "SequenceList" class: import java.util.ArrayList; public class SequenceList {…
A: 1. a) listA obj=new listA(); obj.displaylist(); b) bool a,b; int b=new int[-18,-1,6,9,12];…
Q: I keep getting Java null point exception for makeMovielist
A: import java.util.ArrayList; import java.util.Arrays; public class MovieList { /** * This method…
Q: Write a method that resizes an array based queue to be exactly the size of the data it contains.…
A: Program Explanation: Import the exception class Define a class for queue Declare the attributes for…
Q: Data Structure Add this two methods for the following class
A: Two double arrays are declared and initialized with values for 2 polynomials in PolynomialMain.java…
Q: Please write missing statements to make the following method buildMap complete. The buildMap method…
A: If you clearly observe this the key we are going to map a Book object is same as that of ISBN number…
Q: Write a Java program that uses ArrayList and Iterator. It should input from user the names and ages…
A: Given:
Q: A string containing text and possibly delimiters has been split into tokens and stored in String[]…
A: Below answer is coded in Java language.
Q: Please answer the problem in the screenshot. Please use the methods below as a base. import…
A: import java.util.ArrayList; /** * Class to implement a min-priority queue with a heap in an…
Q: 2. Write a java program to create class Student with the following Marks) : States:Id, Name,…
A: The ArrayList is a type of list and it implements the List interface of Java. Unlike an array an…
Q: Make a class TestArrayList with a main method: import java.util.*; public class TestArrayList {…
A: Note: The modified code is in bold for your reference. import java.util.*; public class…
Q: java Create a static method that: is called removeAll returns ArrayList takes two parameters: an…
A: public static void main(String[] args) { Scanner in = new Scanner(System.in); int size =…
Q: Given part of the ArrayStack class Java code, implement its pop) operation in Java based on the data…
A: Java program to implement pop () operation in array stack
Q: Write a Java method named average. The method should take an ArrayList of Integers as a parameter,…
A: To Do: To write the java code.
Q: Assume we have Dessert.java whcih private String flavor has private double sweetness in it.…
A: Subject 1 ExplanationtoString() method converts the object to a string. equals() method will compare…
Q: Create an arraylist in Java of 10 students. Use the following methods: add, remove, insert, size,…
A: Introduction of the ArrayList: ArrayList in java is an array that size can be change so ArrayList is…
Q: CONVERT this code into C language. Thanks .............. import java.util.*; public class Anagram…
A: Solution:-- 1)The given question has required for the solution which is been expected to be…
Q: Write a JAVA program for a store where you have to store data of items present in a bill e.g. item…
A: For a shopping bill generator using java programming, we have to get the details of the items in…
Q: Given an ArrayList of integers, return an ArrayList where all the odds are before the evens in the…
A: Use an index to keep track where to insert the element and use another list to store the values in…
Q: Make the following class generic so that it can deal with an arbitrary class rather than only String…
A: Generics mean parameterized types. The idea is to allow type (Integer, String, … etc, and…
Q: Please answer the problem in the screenshot. Please use the methods below as a base. The language is…
A: Coded in Java.
Q: Add further functionality to the Java program below so that it searches the ArrayList to find the…
A: Given program: import java.util.*; public class Main{ public static void main(String[] args) {…
Q: How do I sort tiles from least valuable to most valuable? import java.util.ArrayList; class Rack…
A: To sort the Tile objects, I have used comparator which will sort tiles by its value
Q: Implement MyLinkedList) The implementations of the methods contains(E e), get(int index),…
A: According to the information given:- We have to create implement MyLinkedList and the method…
Q: Write a Java class DemoList, the class has: a private attribute list1 as an ArrayList of Integer.…
A: Code: import java.io.*;import java.util.*; class DemoList…
Q: Type the program's output ColorSorter.java Color.java import java.util.Scanner; import…
A: The solution to the given problem is below.
Q: import java.util.ArrayList; import java.util.Arrays; public class PS07A { /** * Write the method…
A: Actually, array is a collection of elements.
Q: What is output? import java.util.ArrayList; public class SimpleCar { @Override public String…
A: Given:
Q: Make a copy of an ArrayList with an explicit loop. Complete the following code. ArrayListCopy.java 1…
A: Given: A code snippet in Java Objective: Error Correction within the code Discussion: There is a…
Q: java Create a static method that: is called repeatAll returns ArrayList of Booleans takes in a…
A: I have provided JAVA CODE along with CODE SCREENSHOT and 2 OUTPUT…
Q: java Create a method that: is called timesTwo returns an ArrayList of Integers takes in a single…
A: In this question create static methods and return ArrayList values and that takes two parameters.…
Q: Java Program This assignment requires one project with two classes. Class Employee Class…
A: Here is the complete code and will comments and screenshot. You should have shared the Employee…
Q: Write a Java class Course for dealing with courses. Your class must have the following features:…
A: Program Approach: 1- As per the assignment requirement, create all the classes as mentioned in the…
Q: Given part or the ArrayStack class Javà code, implement its popO operation Java based on the data…
A: The given problem is to be solved in Java where the interface is implemented in ArrayStack and need…
Q: in java language import java.util.ArrayList; import java.util.Arrays; Write the method named…
A: Sample Code: package Vishal; import java.util.ArrayList;import java.util.Arrays; public class PS13…
Q: is called appendPosSum returns an ArrayList of Integers takes one parameter: an ArrayList of…
A: Step 1: Declare class ArrayListDemo. Step 2: Define method appendPosSum() that takes input list as…
Q: c) Write Java code to add all the elements in myList import java.util.ArrayList; import…
A: We need to explain the given code.
Q: PROBLEM STATEMENT: Return a sublist of a given list from the range of the two integer inputs from,…
A: We need to define a java method FindSublistFromRange that returns a list of numbers between a…
Q: Given main() and an IntNode class, complete the IntList class (a linked list of IntNodes) by writing…
A: public class IntNode { public int dataVal; public IntNode prevNode; //…
Q: Java (Sort, IComparable) The librarian wants to sort the media in the ArrayList by title. For this…
A: Start Take the array of elements Sort that elements. Array list will be search for one element.…
Q: Given main() and an IntNode class, complete the IntList class (a linked list of IntNodes) by writing…
A: Given main() and an IntNode class, complete the IntList class (a linked list of IntNodes) by…
mcq
Trending now
This is a popular solution!
Step by step
Solved in 2 steps
- public class CustomLinkedList { public static int findMax(IntNode headObj) { /* Type your code here */ } public static void main(String[] args) { IntNode headObj; IntNode currObj; IntNode lastObj; int i; int max; // Create head node headObj = new IntNode(-1); lastObj = headObj; // Add nodes to the list for (i = 0; i < 20; ++i) { currObj = new IntNode(i); lastObj.insertAfter(currObj); lastObj = currObj; } max = findMax(headObj); System.out.println(max); }}import java.util.Scanner;import java.util.ArrayList; public class LabProgram { public static void main(String[] args) { Course cop3804=new Course(); String fn, ln; int score; String studentType; Scanner kb=new Scanner(System.in); studentType=kb.next(); while (!studentType.equals("q")) { fn = kb.next(); ln = kb.next(); score=kb.nextInt(); if (studentType.equals("R")) cop3804.addStudent(new Student(fn, ln, score)); else cop3804.addStudent(new HonorStudent(fn, ln, score)); studentType = kb.next(); } cop3804.print(); } } import java.util.ArrayList; public class Course { private ArrayList<Student> roster; //collection of Student objects public Course() { roster = new ArrayList<Student>(); } public void addStudent(Student s) { roster.add(s); } public void…import java.util.Scanner; public class ShoppingList { public static void main (String[] args) { Scanner scnr = new Scanner(System.in); ItemNode headNode; // Create intNode objects ItemNode currNode; ItemNode lastNode; String item; int i; // Front of nodes list headNode = new ItemNode(); lastNode = headNode; int input = scnr.nextInt(); for(i = 0; i < input; i++ ){ item = scnr.next(); currNode = new ItemNode(item); lastNode.insertAtEnd(headNode, currNode); lastNode = currNode; } // Print linked list currNode = headNode.getNext(); while (currNode != null) { currNode.printNodeData(); currNode = currNode.getNext(); } }}
- class WaterSort { Character top = null; // create constants for colors static Character red= new Character('r'); static Character blue = new Character('b'); static Character yellow= new Character('g'); // Bottles declaration public static void showAll( StackAsMyArrayList bottles[]) { for (int i = 0; i<=4; i++) { System.out.println("Bottle "+ i+ ": " + bottles[i]); } } public static void main(String args[]) { //part 1 //create the bottle StackAsMyArrayList bottleONE = new StackAsMyArrayList<Character>(); System.out.println("\nbottleONE:"+ bottleONE+ " size:" + bottleONE.getStackSize()+" uniform? "+ bottleONE.checkStackUniform());…import java.util.Scanner; public class Playlist { // TODO: Write method to ouptut list of songs public static void main (String[] args) { Scanner scnr = new Scanner(System.in); SongNode headNode; SongNode currNode; SongNode lastNode; String songTitle; int songLength; String songArtist; // Front of nodes list headNode = new SongNode(); lastNode = headNode; // Read user input until -1 entered songTitle = scnr.nextLine(); while (!songTitle.equals("-1")) { songLength = scnr.nextInt(); scnr.nextLine(); songArtist = scnr.nextLine(); currNode = new SongNode(songTitle, songLength, songArtist); lastNode.insertAfter(currNode); lastNode = currNode; songTitle = scnr.nextLine(); } // Print linked list…import java.util.Scanner;import java.util.ArrayList;import java.util.Collections; public class ColorSorter { public static void main(String[] args) { Scanner scnr = new Scanner(System.in); final int NUM_ELEMENTS = 5; ArrayList<Color> colors = new ArrayList<Color>(); int i; short red; short green; short blue; for (i = 0; i < NUM_ELEMENTS; ++i) { red = (short)(scnr.nextShort()); green = (short)scnr.nextShort(); blue = (short)scnr.nextShort(); colors.add(new Color(red, green, blue)); } Collections.sort(colors); for (i = 0; i < NUM_ELEMENTS; ++i) { System.out.println(colors.get(i)); } }} other : public class Color implements Comparable<Color> { private short red; private short green; private short blue; Color(short red, short green, short blue) { this.red = red; this.green = green; this.blue = blue; } @Override public int…
- import java.util.Scanner;import java.util.ArrayList;import java.util.StringTokenizer; public class PlantArrayListExample { // TODO: Define a printArrayList method that prints an ArrayList of plant (or flower) objects public static void main(String[] args) { Scanner scnr = new Scanner(System.in); String input; // TODO: Declare an ArrayList called myGarden that can hold object of type plant // TODO: Declare variables - plantName, plantCost, flowerName, flowerCost, colorOfFlowers, isAnnual input = scnr.next(); while(!input.equals("-1")){ // TODO: Check if input is a plant or flower // Store as a plant object or flower object // Add to the ArrayList myGarden input = scnr.next(); } // TODO: Call the method printArrayList to print myGarden }}import java.util.ArrayList; public class Bus { privateStringname; privateintsize; privateintbasePrice; privateArrayList<Trip>approvedTrips; privateintlevel;// 1,2,3 for low,medium, high repectively; privateintid; privatestaticintnextId=0; privateMinistrymny; protectedStringtripTypes; privateintgetNextId(){ returnnextId++; } publicBus(){ approvedTrips=newArrayList<Trip>(); } publicBus(Stringname,intsize,intbasePrice,intlev,Ministrymny){ approvedTrips=newArrayList<Trip>(); this.name=name; this.size=size; this.basePrice=basePrice; this.level=lev; this.id=getNextId(); this.mny=mny; tripTypes="BASICTRANSPORT"; } publicbooleanavailable(Datedate){ booleanretval=true; for(Tript:approvedTrips) if(t.getDate().getDay()==date.getDay()) retval=false; returnretval; } publicintgetBasePrice(){ returnbasePrice; } publicintgetId(){ returnid; } publicStringgetName(){ returnname; } publicdoublegetSize(){ returnsize; } publicStringtoString(){ returnname; }…import java.util.Scanner; public class StudentScores { public static void main (String [] args) { Scanner scnr = new Scanner(System.in); final int SCORES_SIZE = 4; int[] lowerScores = new int[SCORES_SIZE]; int i; for (i = 0; i < lowerScores.length; ++i) { lowerScores[i] = scnr.nextInt(); } for (i = 0; i < lowerScores.length; ++i) { System.out.print(lowerScores[i] + " "); } System.out.println(); } }
- public class DynamicArray { private int array[]; private int count; private int size; public DynamicArray() { array = new int[1]; count = 0; size = 1; } public void add(int data) { if (count == size) { growSize(); // make array size double } array[count] = data; count++; } public void growSize() { int temp[] = null; if (count == size) { temp = new int[size * 2]; { for (int i = 0; i < size; i++) { temp[i] = array[i]; } } } array = temp; size = size * 2; } public void shrinkSize() { int temp[] = null; if (count > 0) { temp = new int[count]; for (int i = 0; i < count; i++) { temp[i] = array[i]; } size = count; array =…BooksMan import java.util.HashMap; import java.util.ArrayList; class Book{ String title, ISBN; ArrayList authors; public Book (String title, String ISBN, String authors){ this.title = title; this.ISBN = ISBN; this.authors = new ArrayList(); if (authors != null) { String [] authorArray = authors.split(", "); for (int i = 0; i < authorArray.length; i++) { this.authors.add(authorArray[i]); } } } public String getISBN() { return ISBN; } public String getTitle() { return title; } public ArrayList getAuthors() { return authors; } } public class Main { public static HashMap buildMap(Book[] s) { HashMap books = new HashMap(); if (s != null) { // TODO Write the statements here: to manage each book from the parameter array reference to the hashmap } return books; } public static void main(String argv[]) { Book[] bookArray = new Book[4]; for (int i = 0; i < 4; i++) {…import java.util.Scanner; public class Inventory { public static void main (String[] args) { Scanner scnr = new Scanner(System.in); InventoryNode headNode; InventoryNode currNode; InventoryNode lastNode; String item; int numberOfItems; int i; // Front of nodes list headNode = new InventoryNode(); lastNode = headNode; int input = scnr.nextInt(); for(i = 0; i < input; i++ ) { item = scnr.next(); numberOfItems = scnr.nextInt(); currNode = new InventoryNode(item, numberOfItems); currNode.insertAtFront(headNode, currNode); lastNode = currNode; } // Print linked list currNode = headNode.getNext(); while (currNode != null) { currNode.printNodeData(); currNode…