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
Textbook Question
Chapter 12, Problem 5E
Write a static method removeDuplicates (ArrayList<Character> data) that will remove any duplicates of characters in the object data. Always keep the first copy of a character and remove subsequent ones.
Expert Solution & Answer
Want to see the full answer?
Check out a sample textbook solutionStudents have asked these similar questions
Define a class called Book. This class should store attributes such as the title, ISBN number, author, edition, publisher, and year of publication. Provide get/set methods in this class to access these attributes. Define a class called Bookshelf, which contains the main method. This class should create a few book objects with distinct names and store them in an ArrayList. This class should then list the names of all books in the ArrayList. Enhance the program by providing a sort function, which will sort the books in ascending order of their year of publication. Create a few more Bookobjects with the same names but with different edition numbers, ISBNs, and years of publication. Add these new Book objects to the ArrayList, and display the book list sorted by book name; for duplicate books of the same name, sort the list by year of publication. (Hint: You will need to define a comparator class that takes two Book objects as parameters of the compareTo This method should do a two-step…
Design a generic method 'sum' that accepts an array of any type such as int, double or float and this method will return the sum of all elements in the array. Create a test class and call 'sum twice by passing arrays of different types.
Complete the Course class by implementing the courseSize() method, which returns the total number of students in the course.
Given classes:
Class LabProgram contains the main method for testing the program.
Class Course represents a course, which contains an ArrayList of Student objects as a course roster. (Type your code in here.)
Class Student represents a classroom student, which has three fields: first name, last name, and GPA.
Ex. For the following students:
Henry Bendel 3.6 Johnny Min 2.9
the output is:
Course size: 2
public class LabProgram { public static void main (String [] args) { Course course = new Course(); // Example students for testing course.addStudent(new Student("Henry", "Bendel", 3.6)); course.addStudent(new Student("Johnny", "Min", 2.9)); System.out.println("Course size: " + course.courseSize()); } }
public class Student {
private String first; // first name private String last; // last name private…
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
Additional Engineering Textbook Solutions
Find more solutions based on key concepts
Using examples, illustrate the different types of adaptor needed to support sequential composition, hierarchica...
Software Engineering (10th Edition)
What is the difference between an array and an aggregate type?
Computer Science: An Overview (12th Edition)
How would the following strings be converted by the CDec function? a. "22.9000" b. "1xfc47uvy" c. "19.99" d. "0...
Starting Out With Visual Basic (7th Edition)
Demonstrate each of the anomaly types with an example.
Modern Database Management (12th Edition)
Suppose you are using a multiuser operating system that allows you to view the names of the files belonging to ...
Computer Science: An Overview (13th Edition) (What's New in Computer Science)
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
- Javaarrow_forwardjavaarrow_forwardThis program is going to maintain a list of customers’ names and bank account balances. 1. Create a class called CustomerList with a main method that instantiates an ArrayList of String objects called customerName. Invoke the add method to add the following names into the ArrayList: Cathy Ben Jorge Wanda Freddie 1. Print each name in the ArrayList using a for a loop. 2. Create another ArrayList object called customerBalance, to save users’ balance. What is the type of this ArrayList? double or Double? You just need to declare this ArrayList and leave it empty for now. 3. For each customer, print the name and ask the user to enter the initial balance for this customer. Save the initial balance into ArrayList customerBalance. Use a loop to get this done for all 5 customers. The program should print out this for the first customer: Example: Please enter the account balance for Cathy: (waiting for user’s input …) Code: for(int i=0; i<5;i++) { Print(“Please enter the account balance…arrow_forward
- Rename the show method to people Override the show method in student and in the other class you created (this will be the polymorphic method) In main program, create an array of 3 objects of class people Instantiate each array position with a different object (people, student, other) With a loop, display all the objects in the array.arrow_forwardGiven a base Plant class and a derived Flower class, complete main() to create an ArrayList called myGarden. The ArrayList should be able to store objects that belong to the Plant class or the Flower class. Create a method called printArrayList(), that uses the printInfo() methods defined in the respective classes and prints each element in myGarden. The program should read plants or flowers from input (ending with -1), add each Plant or Flower to the myGarden ArrayList, and output each element in myGarden using the printInfo() method. Ex. If the input is: plant Spirea 10 flower Hydrangea 30 false lilac flower Rose 6 false white plant Mint 4 -1 the output is: Plant 1 Information: Plant name: Spirea Cost: 10 Plant 2 Information: Plant name: Hydrangea Cost: 30 Annual: false Color of flowers: lilac Plant 3 Information: Plant name: Rose Cost: 6 Annual: false Color of flowers: white Plant 4 Information: Plant name: Mint Cost: 4 import java.util.Scanner;import java.util.ArrayList;import…arrow_forwardTake the following list of methods: Student () { // Creates a student object with all fields blank Student (String name) { // Creates a student object with a set name } Student (String name, Array []) { } power (int x) { // returns x^2 } power (int x, int y) { // returns x^y } greet (String name). { // returns "Hello, + name + " !"; } "1 a) What are your options if you want to find the value of a number squared? Which would you choose if you wanted the method to say something to the user? b) What 'Student' would you call if you want to create a student when you don't have any input? c) What 'Student' would you call if you had a whole array of data to input into the student object? d) Why do you think this is a capability that Java has? What uses can you imagine for it?arrow_forward
- In java Write a class with a main() method. The main() method should declare and initialize four different ArrayLists, each containing at least four int values. The class should also contain a method named fiveEight. Given an ArrayList of ints, the fiveEight should return the int 30 if every element of the given ArrayList is either a 5 or a 8; otherwise, it should return -9. There should be four calls to the allfiveEight method in the main() method.arrow_forwardImage one is my file or you can create ur own file as long as it's similar to mine. image 2 is my program I want to write a 4th method(method 4) and the spec is: A method to count the occurrences of each value in an array takes one parameter, an array of integers returns an array containing the number of times each value occurs in the parameter array. Also should call method 3 from method 4Hint: The general idea of this method is using an array with length maxVal+1(maxVal should get from method 3 already) to save the occurrences of each number. For example, if number 44 occurs 3 times in the file, your array should have a value 3 stored at index 44.arrow_forwardQ8. Write a declaration of a private field named department that can hold an ArrayList. The elements of the ArrayList are of type Student. Write an assignment to the department variable to create an appropriate ArrayList object. Q9. (A) If a collection stores 20 objects, what value would be returned from a call to its size method? (B) Write a method call using get to return the fifth object stored in a collection called department. Q10. Write a method call to add the object held in the variable student1 to a collection department files.arrow_forward
- Using 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_forwardJava - Encapsulation Create a class Point with attributes x and y which are both integers. Create getters and setters for these attributes and implement the following methods: 1. calculateDistance() - calculates the distance from the origin to the point. Returns a double, formula is sqrt(x^2 + y^2) 2. printCoordinates() - prints "(x,y)" Ask for user inputs for x and y. Use the methods printCoordinates() and calculateDistance() respectively. Inputs 1. X 2. Y Sample Output Enter x: 20 Enter y: 15 (20,15) 25.00arrow_forwardThis lab was designed to reinforce programming concepts from this lab, you will practice: Declaring and initializing ArrayList. Add elements to the Arraylist. Display the content of the ArrayList. Write a class name PhoneBookEntry that has fields for a person’s name and phone number. The class should have a constructor and the appropriate accessor and mutator methods. Then write a program that creates at least 5 PhoneBookEntry objects and stores them in an ArrayList. Use a loop to display the contents of each object in the ArrayList.arrow_forward
arrow_back_ios
SEE MORE QUESTIONS
arrow_forward_ios
Recommended textbooks for you
- Programming Logic & Design ComprehensiveComputer ScienceISBN:9781337669405Author:FARRELLPublisher:Cengage
Programming Logic & Design Comprehensive
Computer Science
ISBN:9781337669405
Author:FARRELL
Publisher:Cengage
Definition of Array; Author: Neso Academy;https://www.youtube.com/watch?v=55l-aZ7_F24;License: Standard Youtube License