Concept explainers
Define a class named CheckedArray. The objects of this class are like regular arrays but have range checking. If a is an object of the class CheckedArray and i is an illegal index, then use of a[i] will cause your
Want to see the full answer?
Check out a sample textbook solutionChapter 16 Solutions
Problem Solving with C++ (10th Edition)
Additional Engineering Textbook Solutions
Java: An Introduction to Problem Solving and Programming (8th Edition)
Starting Out with C++: Early Objects (9th Edition)
Electric Circuits. (11th Edition)
Mechanics of Materials (10th Edition)
Thinking Like an Engineer: An Active Learning Approach (4th Edition)
INTERNATIONAL EDITION---Engineering Mechanics: Statics, 14th edition (SI unit)
- 1Declare an array to store objects of the class defined by the UML above. Use a method from the JOptionPane class to request the length of the array from the user. and Use a method from the JOptionPane class to request values from the user to initialize the instance variables of Election objects and assign these objects to the array. The array must be filled using this UMlarrow_forwardpublic class Test { public static void main (String [] args) { Object circlel = new Circle (); Object circle2 = new Circle (); System.out.println(circlel.equals (circle2)); class Circle { double radius; class Circle { double radius; public boolean equals (Circle circle) { public boolean equals (Object o) { return this.radius = ( (Circle)o).radius; return this.radius = circle.radius;arrow_forwardyou created a Card class that represents a standard playing card. Use this to design and implement a class called DeckOfCards that stores 52 objects of the Card class using an array. Include methods to shuffle the deck, deal a card, return the number of cards left in the deck, and a toString to show the contents of the deck. The shuffle methods should assume a full deck.Create a separate driver class that first outputs the populated deck to prove it is complete, shuffles the deck, and then deals each card from a shuffled deck, displaying each card as it is dealt along with the number of cards left in the deck. This is my Card class: mport java.util.Random; /*Card.java Richard Mino * This is a program demonstrating the use of random and predetermined objects and values in the form * of a playing card using getter/setter methods and two constructors and printing them out as a string * using the toString method */public class Card { //Set up variables for card rank and…arrow_forward
- In this version, you are to reimplement the functionality of version 1, but this time using the classes you coded in Lab 3. The basic output is identical to that of version 1, but now: The three parallel arrays are gone — replaced with a single array of type PhonebookEntry. You should be reading in the entries using the read method of your PhonebookEntry class (which in turn uses the read methods of the Name and PhoneNumber classes). Use the equals methods of the Name and PhoneNumber classes in your lookup and reverseLookup methods. Use the toString methods to print out information. Make 100 the capacity of your Phonebook array Throw an exception (of class Exception) if the capacity of the Phonebook array is exceeded. Place a try/catch around your entire main and catch both FileNotFoundExceptions and Exceptions (remember, the order of appearance of the exception types in the catch blocks can make a difference). Do not use BufferedReader while(true) breaks The name of your application…arrow_forwardCreate a new class, called ConstantList that stores a "constant" list of integers (ints). Once created the list is fixed (none of the items can be changed, no items can be added or removed, the order is fixed). Use an array to store your list. Your class will have a single constructor that takes an array of ints as input that will be used to specify the constant list. You must provide appropriate methods to give the user of your class access to the list elements. A user should be able to access individual elements (by position) and the entire list of numbers. Your class must use encapsulation. Explain how your solutions solves the problem. That is, explain why your ConstantList really is a constant list of numbers.arrow_forwardWrite a Program to define a Mobile class, with member variables String brand; double price String OS (make it Final). Float memory Make a default constructor, Make a parameterized constructor. Overload the above Constructor. Provide getters and setters for data members. Inside main, create an array of mobiles. Take data from user and set the values for the mobiles in array (check for array out of bound exception). At the end Print data of array using Loop.arrow_forward
- Write a method in your ArrayUtilities class that meets the following requirements: - It should be named "counts".] - It should declare a parameter for an int array. You may assume that the array will contain only non-negative values. - It should return an int array where the value at each index is the count of how many times the index appears in the original array . For example, if the original array contained the value 10 3 times, then the value at index 10 in the count array should be 3. - Hint: the size of the array is determined by the maximum value in the original array. If the original array is empty, the count array should also be empty. A more detailed example: Given the int array [1, 2, 3, 4, 4, 1, 1, 2, 0, 6], your function would return the array [1, 3, 2, 1, 2, 0, 1]. The value at each index indicates how many times the index appears in the original array. The value at index 0 is 1 because 0 appears 1 time in the original array. The value at index 1 is 3 because 1 appears 3…arrow_forwardThe following is the specification for the constructor of a EmailFolder class: /*** Creates a new EmailFolder with the given label** @precondition label != null AND !label.isEmpty()* @postcondition getLabel()==label*/public EmailFolder(String label) Assume the variable folders is an array list of EmailFolder objects. Write code to add a new EmailFolder to the list.arrow_forwardWrite code for a test class with the following details:1. Create an object of each class mentioned in Question 3, assuming the values for the data members of each class. Create an array that takes the objects of ALL the classes as its elements. Write an enhanced for loop to display the object details. 2. the dealer in Question 4 decides to offer 2% percent discount on the commission at runtime. Write codewith explanation. 3. Add code to the test class that writes the invoice details of Question 6 to a txt document Syntax of the q3 code is given below: import java.util.*; class Car{ //class car String[] name; int reg_number,eng_number, chassis_num,status; String[] city, model, color, date_reg,date_arr,type; float price; float abstract calculate (float price); } class Dealer extends Car{ //inherits from Car String[] deal_name, deal_id, deal_add, deal_pno; float dealer_com ; float abstract calculate (float price) { dealer_com= 0.01*price +…arrow_forward
- Create an object called GSSArray. (It stands for growable self-sorting array)This object will manage an array of type int. Create a private variable for an array of type int. In the constructor for this object, take in an int value which will determine the starting size of the array. The constructor should also instantiate the array.Create a public method called insert, which will take in an int and find the location in the array where it belongs and insert it there. If the array is full, then before inserting the value, method insert should call private method increaseSize, which will create a new array which is double the size of the current array. Then it will copy the values from the original array into the new array and set the private variable to this new array.The array should keep track of how many of its indexes are filled. Create a private variable called lastindex which will be equal to the last index of the array that has a value.Create a public method delete, which will…arrow_forwardCreate a new class, called ConstantList that stores a "constant" list of integers (ints).Dnce created the list is fixed (none of the items can be changed, no items can be added or removed, the order is fixed). Use an array to store your list. Your class will have a single constructor that takes an array of ints as input that will be used to specify the constant list. You must provide appropriate methods to give the user of your class access to the list elements. A user should be able to access individual elements (by position) and the entire list of numbers. Your class must use encapsulation. Explain how your solutions solves the problem. That is, explain why your ConstantList really is a constant list of numbers.arrow_forwardBlackjack 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.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