Java: An Introduction to Problem Solving and Programming (8th Edition)
8th Edition
ISBN: 9780134462035
Author: Walter Savitch
Publisher: PEARSON
expand_more
expand_more
format_list_bulleted
Concept explainers
Question
Chapter 12.1, Problem 9STQ
Program Plan Intro
“get” method in “ArrayList” class: This method is used to returns the elements at the position specified by index.
Example:
The example for “get” method is given below:
Consider, “nameList” is an object of class “ArrayList<String>”. Suppose if the “nameList” contains the four strings "Rose", "Merry", "Joe", and "Jansi".
User can returns all strings in the “nameList” by using method “get” is given below:
for(int index = 0; index < aList.size(); index++)
System.out.println(nameList.get(index));
Expert Solution & Answer
Want to see the full answer?
Check out a sample textbook solutionStudents have asked these similar questions
Computer Science
You are required to develop a small chatting application where two or more friends can communicate each other through messages.
Create a class Message which has Date d, and message (string). Provide getters/setters, constructors, toString.
Create a class Friend having String name, String contact, email and ArrayList of Messages provide getters/setters, constructors, toString addMessage(Message m) method which will add new message to the list.
Provide following options to the user using JFrame.
Login which will help user login to the application.
View Friends (Display List of All Friends)
View Messages ( This should display all message of a Friend)
Send message (This should ask for friend name and message match the friend name and write that message to the array list).
Java (ArrayList) - Plant Information
This program should be written in Java:
Hamburger Joint:
Hamburger ClassWrite a Hamburger class with the following six attributes: • bun - the type of bun the burger will be on • patties - the number of patties on the burger • cheese - whether or not the burger will have cheese • price - the price of the burger • toppings - an array of five toppings; it will need to start empty
Write getters/setters for all attributes except the toppings array.
Your constructor should create a single on white with no cheese and no toppings with a price of $2.99.
Your class should include the following methods in this order, please: addCheese - this method has no parameters that adds cheese to the burger and increases the price by 75 cents
superSizeIt - this method has no parameters and adds a patty to the burger and increases the price by 1.50
addToppings - this method would present the user with at least five toppings (your choice) stored in an array of String objects. If the user indicates the wants…
Chapter 12 Solutions
Java: An Introduction to Problem Solving and Programming (8th Edition)
Ch. 12.1 - Suppose aList is an object of the class...Ch. 12.1 - Prob. 2STQCh. 12.1 - Prob. 3STQCh. 12.1 - Prob. 4STQCh. 12.1 - Can you use the method add to insert an element at...Ch. 12.1 - Prob. 6STQCh. 12.1 - Prob. 7STQCh. 12.1 - If you create a list using the statement...Ch. 12.1 - Prob. 9STQCh. 12.1 - Prob. 11STQ
Ch. 12.1 - Prob. 12STQCh. 12.2 - Prob. 13STQCh. 12.2 - Prob. 14STQCh. 12.2 - Prob. 15STQCh. 12.2 - Prob. 16STQCh. 12.3 - Prob. 17STQCh. 12.3 - Prob. 18STQCh. 12.3 - Prob. 19STQCh. 12.3 - Write a definition of a method isEmpty for the...Ch. 12.3 - Prob. 21STQCh. 12.3 - Prob. 22STQCh. 12.3 - Prob. 23STQCh. 12.3 - Prob. 24STQCh. 12.3 - Redefine the method getDataAtCurrent in...Ch. 12.3 - Repeat Question 25 for the method...Ch. 12.3 - Repeat Question 25 for the method...Ch. 12.3 - Repeat Question 25 for the method...Ch. 12.4 - Revise the definition of the class ListNode in...Ch. 12.4 - Prob. 30STQCh. 12.5 - What is the purpose of the FXML file?Ch. 12.5 - Prob. 32STQCh. 12 - Repeat Exercise 2 in Chapter 7, but use an...Ch. 12 - Prob. 2ECh. 12 - Prob. 3ECh. 12 - Repeat Exercises 6 and 7 in Chapter 7, but use an...Ch. 12 - Write a static method removeDuplicates...Ch. 12 - Write a static method...Ch. 12 - Write a program that will read sentences from a...Ch. 12 - Repeat Exercise 12 in Chapter 7, but use an...Ch. 12 - Write a program that will read a text file that...Ch. 12 - Revise the class StringLinkedList in Listing 12.5...Ch. 12 - Prob. 12ECh. 12 - Write some code that will use an iterator to...Ch. 12 - Prob. 14ECh. 12 - Write some code that will use an iterator to...Ch. 12 - Prob. 17ECh. 12 - Revise the method selectionSort within the class...Ch. 12 - Repeat the previous practice program, but instead...Ch. 12 - Repeat Practice Program 1, but instead write a...Ch. 12 - Write a program that allows the user to enter an...Ch. 12 - Write a program that uses a HashMap to compute a...Ch. 12 - Write a program that creates Pet objects from data...Ch. 12 - Repeat the previous programming project, but sort...Ch. 12 - Repeat the previous programming project, but read...Ch. 12 - Prob. 9PPCh. 12 - Prob. 10PPCh. 12 - Prob. 11PPCh. 12 - Prob. 12PPCh. 12 - Prob. 13PPCh. 12 - Prob. 14PPCh. 12 - Prob. 15PP
Knowledge Booster
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.Similar questions
- Data structure & Algrothium java program Create the three following classes: 1. class containing two strings attributes first name and last name.2. class containing the name object and an ArrayList of string to store the list gifts. This class would extend the attached NicePersonInterface.java3. class containing one ArrayList of Names to store the naughty names. Another ArrayList of NicePerson to store the nice names and gifts. Add atleast 4 names in each list and display all information.arrow_forwardJAVAclass: Main.java, Quadratic.java, TestQuadratic.java Create a class called Quadratic for representing a one-variable quadratic expression of the form: ax2 + bx + c a,b and c here are the coefficients. The class should contain the following methods: * A constructor that accepts values for a, b, and c. * public double getA() * public double getB() * public double getC() * public double evaluate (int x) * will return the value of the expression at point x * public double discriminant() - that will return (b2 - 4ac) * public boolean isImaginaryRoots() - roots are imaginary if (b2 - 4ac) < 0 * public boolean isRealRoots() - roots are real if (b2 - 4ac) >= 0 // these methods can only be invoked if the roots are not imaginary * public float firstRoot() * public float secondRoot() * public boolean isPerfectSquare(); // If the first and second roots are equal * Try to override the toString methods * Write a sample main program that will work as shown below. Example output:…arrow_forwardpublic class Product { private String name; private double cost; public Product(String n, double c) { name=n; cost=c; } public String getName() { return name; On the left is code for a class called Product. Fill in the blanks in the code on the right in order to create three appropriate Product instances and add them to the cart ArrayList. Use the output of the code, shown below the code, to guide you. } public double getCost() { return cost; } public String toString() { return (name + "$" + cost); } public static void addProducts (ArrayList c) { add(new Product("Shampoo", 13.89)); add(new Product("Bread",4.99)); add(new Product("Cereal", 7.49)); } public static void main(String[] args) { ArrayList cart = new ArrayList(); ddProducts (cart); for (Product p : cart) { System.out.println(p); } } Output: Shampoo $13.89 Bread $4.99 Cereal $7.49arrow_forward
- What is the purpose of a constructor? It creates an array of data values associated with an object. It prints all of the information about our object. It returns all data members from an object back to the main method. It allows us to set our own default values when we create an object. in javaarrow_forwardJava: Abstraction using Interfacearrow_forwardMagic Squares One interesting application of two-dimensional arrays is magic squares. A magic square is a square matrix in which the sum of every row, every column, and both diagonals is the same. Magic squares have been studied for many years, and there are some particularly famous magic squares. In this exercise you will write code to determine whether a square is magic. File Square.java contains the shell for a class that represents a square matrix. It contains headers for a constructor that gives the size of the square and methods to read values into the square, print the square, find the sum of a given row, find the sum of a given column, find the sum of the main (or other) diagonal, and determine whether the square is magic. The read method is given for you; you will need to write the others. Note that the read method takes a Scanner object as a parameter. File SquareTest.java contains the shell for a program that reads input for squares from a file named magicData and tells…arrow_forward
- Using java Hamburger ClassWrite a Hamburger class with the following six attributes:• bun - the type of bun the burger will be on• patties - the number of patties on the burger• cheese - whether or not the burger will have cheese• price - the price of the burger• toppings - an array of five toppings; it will need to start empty Write getters/setters for all attributesexcept the toppings array.Your constructor should create a single on white with no cheese and no toppings with a price of $2.99.Your class should include the following methods in this order, please: addCheese - this method has noparameters that adds cheese to the burger and increases the price by 75 centssuperSizeIt - this method has no parameters and adds a patty to the burger and increases the price by 1.50addToppings - this method would present the user with at least five toppings (your choice) stored in an array of Stringobjects. If the user indicates the wants the item, store the String in the toppings array. There…arrow_forwardIn javaarrow_forwardHow do I change the code so if numMinutes is zero then the number cast members is also zero? Code: import java.util.*; import java.util.Arrays; public class Movie { private String movieName; private int numMinutes; private boolean isKidFriendly; private int numCastMembers; private String[] castMembers; // default constructor public Movie() { this.movieName = "Flick"; this.numMinutes = 0; this.isKidFriendly = false; this.numCastMembers = 0; this.castMembers = new String[10]; } // overloaded parameterized constructor public Movie(String movieName, int numMinutes, boolean isKidFriendly, String[] castMembers) { this.movieName = movieName; this.numMinutes = numMinutes; this.isKidFriendly = isKidFriendly; this.numCastMembers = castMembers.length; this.castMembers = new String[numCastMembers]; for (int i = 0; i < castMembers.length; i++) { this.castMembers[i] = castMembers[i]; } } // set the number of minutes public void setNumMinutes(int numMinutes) { this.numMinutes = numMinutes; } //…arrow_forward
- Java Programming: ConWay World Conway’s game of life is a simple simulation of life forms in a two dimensional grid. The ConwayCell implements the standard behavior of a call in Conway’s Game of Life. You only need to implement and test two new classes. You will create two different cells, derived from AbstractCell. 1. Alternating Cell The first class that you should create is a class named AlternatingCell. This is a cell that should alternate between being alive and dead with each generation. Add one or more of your AlternatingCells to your ConwayWorld. You can see how to add a cell in line 15 - 20 of Main.java. Give your AlternatingCell a unique display character when it is alive so that you can see it in your conway world. 2. Your own cell For the second cell you should feel free to implement any behavior that you want. If you are having trouble thinking of ideas then post up a question. You can add your custom cell in just a few places in the world, or you might choose to replace…arrow_forward1)The program should be written in JAVA. Create a "Car" class that keeps car ids and prices. And create a "Galleries" class that holds the car list for a particular gallery. In this class there should be methods for get / set and print for car name, car number and car list. Adding / Removing Cars to the List in This Class should have methods. And create another method to find and print the IDs of Cars with Car Segment equal to X. (print_id(X)). Car Prices are as follows according to the segments. 0$-19999$ -> Z20000$-29999$ -> Y30000$-44999$ -> T45000$-100000$ -> P Apply the Car list using "Singly Linked List"(Node, newNode, head).arrow_forwardJavaDriver Program Write a driver program that contains a main method and two other methods. Create an Array of Objects In the main method, create an array of Food that holds at least two foods and at least two vegetables. You can decide what data to use. Method: Print Write a method that prints the text representation of the foods in the array in reverse order (meaning from the end of the array to the beginning). Invoke this method from main. Method: Highest Sugar Food Write a method that takes an array of Food objects and finds the Food that has the most sugar. Note that the method is finding the Food, not the grams of sugar. Hint: in looping to find the food, keep track of both the current highest index and value. Invoke this method from main.arrow_forward
arrow_back_ios
SEE MORE QUESTIONS
arrow_forward_ios
Recommended textbooks for you
- EBK JAVA PROGRAMMINGComputer ScienceISBN:9781337671385Author:FARRELLPublisher:CENGAGE LEARNING - CONSIGNMENT
EBK JAVA PROGRAMMING
Computer Science
ISBN:9781337671385
Author:FARRELL
Publisher:CENGAGE LEARNING - CONSIGNMENT