Introduction to Java Programming and Data Structures, Comprehensive Version (11th Edition)
11th Edition
ISBN: 9780134670942
Author: Y. Daniel Liang
Publisher: PEARSON
expand_more
expand_more
format_list_bulleted
Textbook Question
Chapter 10, Problem 10.3PE
(The MyInteger class) Design a class named MyInteger. The class contains:
- An int data field named value that stores the int value represented by this object.
- A constructor that creates a MyInteger object for the specified int value.
- A getter method that returns the int value.
- The methods isEven(), isOdd(),and isPrime() that return true if the value in this object is even, odd, or prime, respectively.
- The static methods isEven(int), isOdd(int),and isPrime(int) that return true if the specified value is even, odd, or prime, respectively.
- The static methods isEven(MyInteger), isOdd(MyInteger), and isPrime(MyInteger) that return true if the specified value is even, odd, or prime, respectively.
- The methods equals(int) and equals(MyInteger) that return true if the value in this object is equal to the specified value.
- A static method parseInt (char[]) that converts an array of numeric characters to an int value.
- A static method parseInt(String) that converts a string into an int value.
Draw the UML diagram for the class then implement the class. Write a client
Expert Solution & Answer
Want to see the full answer?
Check out a sample textbook solutionStudents have asked these similar questions
(The Time class)
Design a class named Time.
The class contains:
- The data fields hour, minute, and second that represent a time.
- A no-arg constructor that creates a Time object for the current time. (The values of the data fields
will represent the current time.)
-A constructor that constructs a Time object with a specified elapsed time since midnight, January
1, 1970, in milliseconds. (The values of the data fields will represent this time.)
-A constructor that constructs a Time object with the specified hour, minute, and second.
- Three getter methods for the data fields hour, minute, and second, respectively.
-A method named setTime (long elapseTime) that sets a new time for the object using the
elapsed time. For example, if the elapsed time is 555550000 milliseconds, the hour is 10, the
minute is 19, and the second is 10.
Draw the UML diagram for the class and then implement the class.
Write a test program that creates two Time objects (using new Time (), new Time(555550000),…
(Difficulty Level 3)In the game Flick Fleet, players undertake space combat by flicking a six sided die at other ships.
There is an object called SpaceShip, where ships have a type corresponding to: Destroyer, Cruiser, Bomber, or Fighter. This object has a method called:
get_ship_type(): Returns a string that corresponds to the type of ship (e.g. "Destroyer", "Cruiser", "Bomber" or "Fighter")
Each ship has different regions that have a corresponding number between 1 and 5.
Fighter - Hull (1), Engines (2)
Bomber - Hull (1), Engines (2), Shield Generator (3)
Cruiser - Hull (1), Engines (2), Shield Generator (3), Defense Grid (4)
Destroyer - Hull (1), Engines (2), Shield Generator (3), Defense Grid (4), Engineering (5)
Write a function called laser_attack that takes in as its parameters a ship of type Ship, and an integer value between 1 and 6.
This function should return true if the number passed in the second parameter corresponds to a region possessed by the ship…
Ag
1- Random Prime Generator
Add a new method to the Primes class called genRandPrime. It should take as input two
int values: 1owerBound and upperBound. It should return a random prime number in
between TowerBound (inclusive) and upperBound (exclusive) values. Test the functionality
inside the main method.
Implementation steps:
a) Start by adding the method header. Remember to start with public static keywords,
then the return type, method name, formal parameter list in parenthesis, and open brace. The
return type will be int. We will have two formal parameters, so separate those by a comma.
b) Now, add the method body code that generates a random prime number in the specified
range. The simplest way to do this is to just keep trying different random numbers in the range,
until we get one that is a prime. So, generate a random int using:
int randNum = lowerBound + gen.nextInt(upperBound);
Then enter put a while loop that will keep going while randNum is not a prime number - you
can…
Chapter 10 Solutions
Introduction to Java Programming and Data Structures, Comprehensive Version (11th Edition)
Ch. 10.2 - Prob. 10.2.1CPCh. 10.3 - Is the BMI class defined in Listing 10.4...Ch. 10.4 - Prob. 10.4.1CPCh. 10.4 - Prob. 10.4.2CPCh. 10.4 - Prob. 10.4.3CPCh. 10.4 - Prob. 10.4.4CPCh. 10.7 - Prob. 10.7.1CPCh. 10.7 - Prob. 10.7.2CPCh. 10.7 - How do you convert an integer into a string? How...Ch. 10.7 - Show the output of the following code: public...
Ch. 10.7 - Prob. 10.7.5CPCh. 10.8 - What are autoboxing and autounboxing? Are the...Ch. 10.8 - Show the output of the following code. public...Ch. 10.9 - What is the output of the following code? public...Ch. 10.10 - Suppose s1, s2, s3, and s4 are four strings, given...Ch. 10.10 - To create the string Welcome to Java, you may use...Ch. 10.10 - What is the output of the following code? String...Ch. 10.10 - Let s1 be Welcome and s2 be welcome Write the...Ch. 10.10 - Prob. 10.10.5CPCh. 10.10 - Prob. 10.10.6CPCh. 10.10 - Prob. 10.10.7CPCh. 10.10 - Prob. 10.10.8CPCh. 10.10 - What is wrong in the following program? 1public...Ch. 10.10 - Show the output of the following code: public...Ch. 10.10 - Show the output of the following code: public...Ch. 10.11 - Prob. 10.11.1CPCh. 10.11 - Prob. 10.11.2CPCh. 10.11 - Prob. 10.11.3CPCh. 10.11 - Prob. 10.11.4CPCh. 10.11 - Prob. 10.11.5CPCh. 10.11 - Suppose s1 and s2 are given as fot tows:...Ch. 10.11 - Show the output of the following program: public...Ch. 10 - (The Time class) Design a class named Time. The...Ch. 10 - (The BMI class) Add the following new constructor...Ch. 10 - (The MyInteger class) Design a class named...Ch. 10 - Prob. 10.4PECh. 10 - (Display the prime factors) Write a program that...Ch. 10 - (Display the prime numbers) Write a program that...Ch. 10 - Prob. 10.7PECh. 10 - Prob. 10.8PECh. 10 - (The Course class) Revise the Course class as...Ch. 10 - Prob. 10.10PECh. 10 - Prob. 10.11PECh. 10 - (Geometry: the Triangle2D class) Define the...Ch. 10 - (Geometry: the MyRectangle 2D class) Define the...Ch. 10 - (The MyDate class) Design a class named MyDate....Ch. 10 - (Geometry: the bounding rectangle) A bounding...Ch. 10 - (Divisible by 2 or 3) Find the first 10 numbers...Ch. 10 - (Square numbers) Find the first 10 square numbers...Ch. 10 - (Mersenne prime)A prime number is called a...Ch. 10 - (Approximate e) Programming Exercise 5.26...Ch. 10 - (Divisible by 5 or 6) Find the first 10 numbers...Ch. 10 - (Implement the String class) The String class is...Ch. 10 - (Implement the String class) The String class is...Ch. 10 - (Implement the Character class) The Character...Ch. 10 - (New string split method) The split method in the...Ch. 10 - (Implement the StringBuilder class) The...Ch. 10 - (Implement the StringBuilder class) The...
Additional Engineering Textbook Solutions
Find more solutions based on key concepts
Private Sub Handles btnOutput.Click
End Sub
Introduction To Programming Using Visual Basic (11th Edition)
Using the commands SELECT, PROJECT, and JOIN, write a sequence of instructions to answer each of the following ...
Computer Science: An Overview (13th Edition) (What's New in Computer Science)
(Multiples of 2 with an Infinite Loop) Write a program that keeps printing the multiples of the integer 2, name...
C How to Program (8th Edition)
Given the following fragment that purports to convert from degrees Celsius to degrees Fahrenheit, answer the fo...
Problem Solving with C++ (9th Edition)
The decimal number system is a weighted system with ten digits.
Digital Fundamentals (11th Edition)
Write a program to print the value of EOF.
C Programming Language
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
- : A point in the x-y plane is represented by its x-coordinate and y-coordinate. Design a class, pointType, that can store and process a point in the x-y plane. You should then perform operations on the point, such as showing the point, setting the coordinates of the point, printing the coordinates of the point, returning the x-coordinate, and returning the y-coordinate. Also, write a test program to test the various operations on the point.arrow_forward2019 AP® COMPUTER SCIENCE A FREE-RESPONSE QUESTIONS 2. This question involves the implementation of a fitness tracking system that is represented by the StepTracker class. A StepTracker object is created with a parameter that defines the minimum number of steps that must be taken for a day to be considered active. The StepTracker class provides a constructor and the following methods. addDailySteps, which accumulates information about steps, in readings taken once per day activeDays, which returns the number of active days averageSteps, which returns the average number of steps per day, calculated by dividing the total number of steps taken by the number of days tracked The following table contains a sample code execution sequence and the corresponding results. Statements and Expressions Value Returned Comment (blank if no value) StepTracker tr StepTracker(10000); Days with at least 10,000 steps are considered active. Assume that the parameter is positive. new tr.activeDays () ; No…arrow_forwardThis program extends the earlier "Online shopping cart" program. (Consider first saving your earlier program). (1) Extend the ItemToPurchase class to contain a new attribute. item_description (string) - Set to "none" in default constructorImplement the following method for the ItemToPurchase class. print_item_description() - Prints item_description attribute for an ItemToPurchase object. Has an ItemToPurchase parameter. Ex. of print_item_description() output: Bottled Water: Deer Park, 12 oz. (2) Build the ShoppingCart class with the following data attributes and related methods. Note: Some can be method stubs (empty methods) initially, to be completed in later steps. Parameterized constructor which takes the customer name and date as parameters Attributescustomer_name (string) - Initialized in default constructor to "none"current_date (string) - Initialized in default constructor to "January 1, 2016"cart_items (list)Methodsadd_item()Adds an item to cart_items list. Has a parameter of…arrow_forward
- This program extends the earlier "Online shopping cart" program. (Consider first saving your earlier program). (1) Extend the ItemToPurchase class to contain a new attribute. item_description (string) - Set to "none" in default constructorImplement the following method for the ItemToPurchase class. print_item_description() - Prints item_description attribute for an ItemToPurchase object. Has an ItemToPurchase parameter. Ex. of print_item_description() output: Bottled Water: Deer Park, 12 oz. (2) Build the ShoppingCart class with the following data attributes and related methods. Note: Some can be method stubs (empty methods) initially, to be completed in later steps. Parameterized constructor which takes the customer name and date as parameters Attributescustomer_name (string) - Initialized in default constructor to "none"current_date (string) - Initialized in default constructor to "January 1, 2016"cart_items (list)Methodsadd_item()Adds an item to cart_items list. Has a parameter of…arrow_forwardPlease help me solve it today I posted it yesterday and got rejected I don't know why:( Please help me solve this with Java Game class instructions:• Game class has three attributes: points (which represent the number of points awarded when winning the game), status (false if the game has not been played and true if the game has been played), and description (which is a text description of the game). Note that description attribute is a read-only variable. • In the constructor, initialize points to zero, status to false, and description to the given parameter.• isPlayed method returns true if the game has been played, and false otherwise.• getPoints is a getter method for points attribute.• play method is an abstract method.• Override toString method to return the game description.• Override equals method so that two games are the same if their descriptions are the same. :instructions class ) HangMan• HangMan is a game in which a player tries to guess a word based on a given hint.…arrow_forward(The Triangle class) Design a class named Triangle that extends GeomericObject. The class contains: Three double data fields named side1, side2, and side with default values 1.0 to denote three sides of the triangle. A no-arg constructor that creates a default triangle. A constructor that creates a triangle with the specific side1, side2, and side3. The accessor method for the three data fields. A method named getArea() that returns the area of this triangle. A method named getPerimeter() that returns the perimeter of this triangle. A method named toString() that returns a string description for the triangle. Note:- Please write a java code and also need an output for this program. (Also, let me know with what name file should be saved to get output)arrow_forward
- #pyhton programing topic: Introduction to Method and Designing class Method overloading & Constructor overloading ------------------ please find the attached imagearrow_forwardClasses and Objects) Hand-write a complete Java class that can be used to create a Car object as described below. a. A Vehicle has-a: i. Registration number ii. Owner name iii. Price iv. Year manufactured b. Add all instance variables C. The class must have getters and setters for all instance variables d. The class must have two constructors, a no-args and a constructor that receives input parameters for each instance variable.arrow_forwarduse java to answerand Thank youarrow_forward
- (The MyPoint class) Design a class named MyPoint to represent a point with x- and y-coordinates. The class contains: 1 The data fields x and y that represent the coordinates with getter methods. 1 A no-arg constructor that creates a point (0, 0). I A constructor that constructs a point with specified coordinates. I A method named distance that returns the distance from this point to a specified point of the MyPoint type. I A method named distance that returns the distance from this point to another point with specified x- and y-coordinates. Draw the UML diagram for the class and then implement the class. Write a test program that creates the two points (0, 0) and (10, 30.5) and displays the distance between them.arrow_forwardPlease see attached:)arrow_forwardPlease in pyth coding with correct indentation 4a) Given that you have a Liquid class that can be initialized with any amount of gallons, liters, ounces, etc, write the first line of the method that will allow you to add together two Liquid objects using operator overloading. Again, write ONLY the first line (method definition) – you do NOT have to write the entire method. 4b) Given that you have L1 and L2 which are instances of the Liquid class, write a line of code that uses operator overloading to add them together and assign the result to L3.arrow_forward
arrow_back_ios
SEE MORE QUESTIONS
arrow_forward_ios
Recommended textbooks for you
- 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
Database System Concepts
Computer Science
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:McGraw-Hill Education
Starting Out with Python (4th Edition)
Computer Science
ISBN:9780134444321
Author:Tony Gaddis
Publisher:PEARSON
Digital Fundamentals (11th Edition)
Computer Science
ISBN:9780132737968
Author:Thomas L. Floyd
Publisher:PEARSON
C How to Program (8th Edition)
Computer Science
ISBN:9780133976892
Author:Paul J. Deitel, Harvey Deitel
Publisher:PEARSON
Database Systems: Design, Implementation, & Manag...
Computer Science
ISBN:9781337627900
Author:Carlos Coronel, Steven Morris
Publisher:Cengage Learning
Programmable Logic Controllers
Computer Science
ISBN:9780073373843
Author:Frank D. Petruzella
Publisher:McGraw-Hill Education
Call By Value & Call By Reference in C; Author: Neso Academy;https://www.youtube.com/watch?v=HEiPxjVR8CU;License: Standard YouTube License, CC-BY