Java: An Introduction to Problem Solving and Programming (7th Edition)
7th Edition
ISBN: 9780133766264
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
Blackjack is a card game where the goal is to reach a score of 21. Create a java version of this game with the following requirements. Extend the JPanel class and create an array of 52 cards. Add four sets of numbers from 1 to 10. Use J for Jack, Q for queen, K for king, and A for ace. Jack through king will have a value of 10, and the ace will have a value of 11. Deal two cards to the user and two cards to the computer. Do not show the value of the computer's first two cards to the user. Add buttons Hit, Stay, and Reset. If the user selects the "Hit" button, randomly select one of the cards from the array, and give it to the user. (After selecting a card, do not reuse this index during the rest of the game.) If the dealer has less than 21, "hit" the dealer, too. When the user selects the "Stay" button, add up the card values. The winner is the person who is closest to 21 without going over. Name the class Blackjack.java.
Movie.
Java Code
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).
Chapter 12 Solutions
Java: An Introduction to Problem Solving and Programming (7th 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 - 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
- For the code in java below it shows a deck of 52 cards and asks the name of the two human players and makes both players draw five cards from the deck. What I want to added into the code is for Player A to manually pick a card from his/her 5 cards and have Player B pick two cards that equal the value of Player A's card if possible. Main class code and Player class code shown below: Main class code: import java.util.ArrayList; import java.util.Scanner; import java.util.List; import java.util.Random; class Main { publicstaticvoid main(String[] args) { // card game, two players, take turns. String[] suits = {"Hearts", "Clubs", "Spades", "Diamonds"}; String[] numbers = {"A", "2", "3", "4", "5", "6", "7", "8", "9", "10", "J", "Q", "K"}; for(String oneSuit : suits){ for(String num : numbers){ System.out.println(oneSuit + " " + num); } } List<Player> listOfPlayers = new ArrayList<>(); Scanner sc = new Scanner(System.in); System.out.println("Name of Player 1");…arrow_forwardThis 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…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_forward
- public 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_forwardWhat 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_forwardUsing Java You will write the code to perform the following operations using the ArrayList class: Implement a Shoe class, encapsulating the concept of a shoe A shoe has a color, size, and brand. Implement a ShoeStore class, encapsulating the concept of a shoe store. Use the ArrrayList of Shoe objects. Fill the ArrayList object with Shoe objects. Implement a ShoeSearchEnginge class Print Shoe objects in the ArrayList. color: white size: 11 brand: Anne Klein color: yellow size: 13 brand: Calvin Klein color: black size: 9 brand: COACH color: blue size: 5 brand: CLARK color: black size: 7 brand: Cole Han color: blue size: 15 brand: FitFlo color: red size: 9 brand: CLARK Find all Shoe objects with CLARK as a brand in the ArrayList. Find the largest size of a Shoe object in the ArrayList.arrow_forward
- Write code that creates an ArrayList that can hold String objects. Add the names of three cars to the ArrayList, and then display the contents of the ArrayList.arrow_forwardCan someone help me write a class in Java. The class will read a file of people: their name, year of birth, and year of death. The class must have at least one ArrayList. The class's constructor will read the file specified by its parameter. Each line looks like the samplebelow:FirstName LastName YearOfBirth YearOfDeathThe items on each line are separated by tabs. The class will also have these methods: -preBoom() : This method will return the number of people born before 1945, the start ofthe Baby Boom - minAge() : This method will return the age of the youngest person in the list - maxAge() : This method will return the age of the oldest person in the list - aveAge() : This method will return the average age of the people in the list. Theaverage value returned will be an integer. - seniors() : This method will return the number of people aged 65 or overarrow_forwardJava: Abstraction using Interfacearrow_forward
- Magic 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_forwardUsing 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_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