Concept explainers
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 = currNode.getNext();
}
}
}
Trending nowThis is a popular solution!
Step by stepSolved in 4 steps with 3 images
- This is a subclass and doesn't has a main method yet. class Vector{Object items[];int length;int size; void Grow(){// Duplicate sizesize = size * 2; // Allocate new itemsObject new_items[] = new Object[size]; // Copy old itemsfor (int i = 0; i < length; i++)new_items[i] = items[i]; // Discard old itemsitems = new_items; // MessageSystem.out.println("Growing capacity to " + size + " elements");} public Vector(){size = 2;items = new Object[2];} public void Print(){// MessageSystem.out.println("Content:"); // Traversefor (int i = 0; i < length; i++)System.out.println(items[i]);} public void Insert(int index, Object item){// Check indexif (index < 0 || index > length){System.out.println("Invalid index");return;} // Grow if necessaryif (length == size)Grow(); // Shiftfor (int i = length - 1; i >= index; i--)items[i + 1] = items[i]; // Insertitems[index] = item; // One more itemlength++; // MessageSystem.out.println("Inserted " + item);} public void Add(Object…arrow_forwardimport java.util.Scanner; public class StateInfo { /* Your code goes here */ public static void main(String[] args) { Scanner scnr = new Scanner(System.in); String stateCode; String stateName; stateCode = scnr.next(); stateName = scnr.next(); printStateInfo(stateCode, stateName); }}arrow_forwardimport java.util.Objects;class CovidVariant { String Name; String Unique_code; CovidVariant left, right; public CovidVariant(String name, String code) { this.Name = name; this.Unique_code = code; left = right = null; }}class VariantCollection { private boolean compare_code(String code, String code_2) { int year = Integer.parseInt(code.substring(0, 2)); int month = Integer.parseInt(code.substring(2, 4)); int date = Integer.parseInt(code.substring(4, 6)); int year_2 = Integer.parseInt(code_2.substring(0, 2)); int month_2 = Integer.parseInt(code_2.substring(2, 4)); int date_2 = Integer.parseInt(code_2.substring(4, 6)); if (year == year_2) { if (month == month_2) { if (date > date_2) { return true; } else { return false; } } else if (month > month_2) { return true; }…arrow_forward
- import java.util.Scanner; public class CharMatch { public static void main(String[] args) { Scanner scnr = new Scanner(System.in); String userString; char charToFind; int strIndex; userString = scnr.nextLine(); charToFind = scnr.next().charAt(0); strIndex = scnr.nextInt(); /* Your code goes here */ }}arrow_forward*JAVA* complete method Delete the largest valueremoveMax(); Delete the smallest valueremoveMin(); class BinarHeap<T> { int root; static int[] arr; static int size; public BinarHeap() { arr = new int[50]; size = 0; } public void insert(int val) { arr[++size] = val; bubbleUP(size); } public void bubbleUP(int i) { int parent = (i) / 2; while (i > 1 && arr[parent] > arr[i]) { int temp = arr[parent]; arr[parent] = arr[i]; arr[i] = temp; i = parent; } } public int retMin() { return arr[1]; } public void removeMin() { } public void removeMax() { } public void print() { for (int i = 0; i <= size; i++) { System.out.print( arr[i] + " "); } }} public class BinarH { public static void main(String[] args) { BinarHeap Heap1 = new BinarHeap();…arrow_forwardimport java.util.Scanner; public class LabProgram { // Recursive method to draw the triangle public static void drawTriangle(int baseLength, int currentLength) { if (currentLength <= 0) { return; // Base case: stop when currentLength is 0 or negative } // Calculate the number of spaces needed for formatting int spaces = (baseLength - currentLength) / 2; if (currentLength == baseLength) { // If it's the first line, don't output spaces before the first '*' System.out.println("*".repeat(currentLength) + " "); } else { // Output spaces and asterisks System.out.println(" ".repeat(spaces) + "*".repeat(currentLength) + " "); } // Recursively call drawTriangle with the reduced currentLength drawTriangle(baseLength, currentLength - 2); } public static void drawTriangle(int baseLength) { drawTriangle(baseLength, baseLength); } public static…arrow_forward
- A dynamic array is exactly as it sounds.arrow_forwardThis is method signature class below: package greedy; import java.util.ArrayList; public class Knapsack { static class Item { String name; int value; int weight; double costPerPound; //keeping track of this for sorting purposes; Item(String name,int value,int weight) { this.name = name; this.value = value; this.weight = weight; costPerPound = (double)value/weight; } public String toString() { return name +", value: "+value + ", weight: " + weight; } } static ArrayList<Double> fractionalKnapsack(ArrayList<Item> items,double maxWeight){ } }arrow_forwardI wrote my codes like this: public class OrderApp { public void main(String[] args) { FoodOrder foodOrder; } } public class Customer { private String name; public void chageCrditCard() { } } public class FoodOrder { Customer customer; private long orderNumber; public void addItem (MenuItem i) { } public double getTotalCost() { return 0.00; } } public class MenuItem { public String name; protected double price; public double getPrice() { return price; } } public class ComboMeal extends MenuItem { private double discount; public double getPrice() { return price; } public void addItem (MenuItem i) { } } I'm not sure If I did the relationship between classes and implement each one right. Also, how do I express multiplicities and specifiers in the codes? And finally, please review the whole thing. Subject: Java Programmingarrow_forward
- Javaarrow_forwardimport 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…arrow_forwardimport java.util.Scanner; public class FridayData { public static void main(String[] args) { Scanner scnr = new Scanner(System.in); Friday weather = new Friday(); String inputWeather; double inputHumidity; inputWeather = scnr.next(); inputHumidity = scnr.nextDouble(); weather.setWeather(inputWeather); weather.setHumidity(inputHumidity); weather.print(); }}arrow_forward
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education