Objects First with Java: A Practical Introduction Using BlueJ (6th Edition)
6th Edition
ISBN: 9780134477367
Author: David J. Barnes, Michael Kolling
Publisher: PEARSON
expand_more
expand_more
format_list_bulleted
Question
Chapter 4, Problem 54E
Program Plan Intro
To define a method in the Club class.
Write a program in BlueJ to define a method in the Club class named:
public int (joinedlnMonthfint month)
Expert Solution & Answer
Want to see the full answer?
Check out a sample textbook solutionStudents have asked these similar questions
//Todo write test cases for SimpleCalculator Class
// No need to implement the actual Calculator class just write Test cases as per TDD.
// you need to just write test cases no mocking // test should cover all methods from calculator and all scenarios, so a minimum of 5 test
// 1 for add, 1 for subtract, 1 for multiply, 2 for divide (1 for normal division, 1 for division by 0)
// make sure all these test cases fail
public class CalculatorTest {
//Declare variable here
private Calculator calculator;
//Add before each here
//write test cases here
}
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…
ToNearestPenny (amount)-a private static method that returns
the given amount rounded to the nearest penny. For example, if the
amount is 1023.659, the method will return 1023.66.
2. Consider a class Time that represents a time of day. It has attributes for the
hour and minute. The hour value ranges from 0 to 23, where the range 0 to
11 represents a time before noon. The minute value ranges from 0 to 59.
a. Write a default constructor that initializes the time to 0 hours, O minutes.
b. Write a private method isValid (hour, minute) that returns true if the
given hour and minute values are in the appropriate range.
C. Write a method setTime (hour, minute) that sets the time if the given
values are valid.
d. Write another method setTime (hour, minute, iSAM) that sets the time
if the given values are valid. The given hour should be in the range I to 12.
The parameter isAm is true if the time is an a.m. time and false otherwise.
3. Write a default constructor and a second constructor for…
Chapter 4 Solutions
Objects First with Java: A Practical Introduction Using BlueJ (6th Edition)
Ch. 4 - Prob. 1ECh. 4 - What happens if you create a new MusicOrganizer...Ch. 4 - Prob. 3ECh. 4 - Prob. 4ECh. 4 - Write a declaration of a local variable called...Ch. 4 - Prob. 6ECh. 4 - Write assignments to the library, cs101. and track...Ch. 4 - If a collection stores 10 objects, what value...Ch. 4 - Write a method call using get to return the fifth...Ch. 4 - Prob. 10E
Ch. 4 - Write a method call to add the object held in the...Ch. 4 - Write a method call to remove the third object...Ch. 4 - Suppose that an object is stored at index 6 in a...Ch. 4 - Add a method called checklndex to the...Ch. 4 - Write an alternative version of checkIndex called...Ch. 4 - Rewrite both the 1istFi1e and removeFi1e methods...Ch. 4 - Prob. 17ECh. 4 - Prob. 18ECh. 4 - We know that the first file name is stored at...Ch. 4 - Prob. 20ECh. 4 - Create a MusicOrganizer and store a few file names...Ch. 4 - Create an ArrayList<String> in the Code Pad by...Ch. 4 - If you wish, you could use the debugger to help...Ch. 4 - Challenge exercise The for-each loop does not use...Ch. 4 - Prob. 25ECh. 4 - Prob. 26ECh. 4 - Prob. 27ECh. 4 - Write out the header of a for-each loop to process...Ch. 4 - Suppose we express the first version of the key...Ch. 4 - Write a while loop (for example, in a method...Ch. 4 - Write a while loop to add up the values 1 to 10...Ch. 4 - Write a method called sum with a while loop that...Ch. 4 - Challenge exercise Write a method isPrime (int n)...Ch. 4 - In the findFirst method, the loop's condition...Ch. 4 - Prob. 35ECh. 4 - Have the MusicOrganizer increment the play count...Ch. 4 - Prob. 37ECh. 4 - Prob. 38ECh. 4 - Prob. 39ECh. 4 - Prob. 40ECh. 4 - Complete the numberOfMembers method to return the...Ch. 4 - Prob. 42ECh. 4 - Prob. 43ECh. 4 - Prob. 44ECh. 4 - Challenge exercise Write a method to play every...Ch. 4 - Prob. 46ECh. 4 - Prob. 47ECh. 4 - Add a close method to the Auction class. This...Ch. 4 - Add a getUnsold method to the Auction class with...Ch. 4 - Suppose the Auction class includes a method that...Ch. 4 - Rewrite getLot so that it does not rely on a lot...Ch. 4 - Prob. 52ECh. 4 - Prob. 53ECh. 4 - Prob. 54ECh. 4 - Prob. 55ECh. 4 - Open the products project and complete the...Ch. 4 - Implement the findProduct method. This should look...Ch. 4 - Implement the numberInStock method. This should...Ch. 4 - Prob. 59ECh. 4 - Challenge exercise Implement a method in...Ch. 4 - Java provides another type of loop: the do-while...Ch. 4 - Prob. 85ECh. 4 - Prob. 86ECh. 4 - Find out about Java's switch-case statement. What...
Knowledge Booster
Similar questions
- Write an equals method for the Car class given here. Two Cars are equal if their Vehicle Identification Numbers (VIN) are the same. HINT: The String class has an equals method that can be called from the Car class equals method.arrow_forwardModify the Car class example and add the following: A default constructor that initializes strings to “N/A” and numbers to zero. An overloaded constructor that takes in initial values to set your fields (6 parameters). accel() method: a void method that takes a double variable as a parameter and increases the speed of the car by that amount. brake() method: a void method that sets the speed to zero. To test your class, you will need to instantiate at least two different Car objects in the main method in the CarDemo class. Each of your objects should use a different constructor. For the object that uses the default constructor, you will need to invoke the mutator methods to assign values to your fields. Invoke the displayFeatures() method for both objects and display the variables. Demonstrate the use of the accessor method getColor() by accessing the color of each car and printing it to the console. Use the method accel to increase the speed of the first car by 65 mph. Use…arrow_forwardJava Programming: Write a static method named urgentAndIncomplete. Write the method as if it is in Main.java (not part of the ToDoItem class). The method should: Accept three ToDoItem references as parameters, and Return an int. Count how many of the ToDoItems meet two criteria: A priority greater than 3 Not completed The method should return how many of the parameters meet these criteria. That will be either 0, 1, 2, or 3.arrow_forward
- Create a deck of cards class. Internally, the deck of cards should use another class, a card class. Your requirements are: The Deck class should have a deal method to deal a single card from the deck After a card is dealt, it is removed from the deck. There should be a shuffle method which makes sure the deck of cards has all 52 cards and then rearranges them randomly. The Card class should have a suit (Hearts, Diamonds, Clubs, Spades) and a value (A,2,3,4,5,6,7,8,9,10,J,Q,K)arrow_forwardNote:This is a Java program question. Q#6: Create a class for invoice item having attributes invoice id (it’ll be unique for every invoice item), item description (name of product and details), quantity (number of items), and price (sail price). There is behavior to set all values. There is a display method that will show invoice id, item description, quantity, price of single item and total amount of the invoice item. Create objects to show following details. ID Name Quantity Price Total Amount 1. Chips 50 mg small pack 12 10 120 2. Chocolate Biscuit small pack 15 5 75arrow_forwardGive source code and output alsoarrow_forward
- Write in python language thank youarrow_forwardFibonacci A fibonacci sequence is a series of numbers in which each number is the sum of the two preceding numbers. For example: 0, 1, 1, 2, 3, 5, 8, 13, 21, 34, and so on… For this, you will implement a class that takes a positive integer (n) and returns the number in the nth position in the sequence. Examples When n is 1, the returned value will be 0. When n is 4, the returned value will be 2. When n is 9, the returned value will be 21. come up with the formula and base cases Implementation Create a class Fibonacci with a public static method getValue. Create a Main class to test and run your Fibonacci class.arrow_forwardDie Write a Die class to model a die (like you play Yahtzee or Monopoly with). Fields faces The number of sides on the die. value The last rolled value (generated by the roll() method). Methods __init__(self, faces=6) Constructor. faces defaults to 6 and value defaults to 0. roll(self) returns a random number between 1 and numSides (inclusive) __str__(self) returns the string version of a die; Example: "[d6] 3" where 6 is the number of sides and 3 is the value. Code needs to be pythonarrow_forward
arrow_back_ios
SEE MORE QUESTIONS
arrow_forward_ios
Recommended textbooks for you
- C++ Programming: From Problem Analysis to Program...Computer ScienceISBN:9781337102087Author:D. S. MalikPublisher:Cengage LearningProgramming Logic & Design ComprehensiveComputer ScienceISBN:9781337669405Author:FARRELLPublisher:CengageMicrosoft Visual C#Computer ScienceISBN:9781337102100Author:Joyce, Farrell.Publisher:Cengage Learning,
C++ Programming: From Problem Analysis to Program...
Computer Science
ISBN:9781337102087
Author:D. S. Malik
Publisher:Cengage Learning
Programming Logic & Design Comprehensive
Computer Science
ISBN:9781337669405
Author:FARRELL
Publisher:Cengage
Microsoft Visual C#
Computer Science
ISBN:9781337102100
Author:Joyce, Farrell.
Publisher:Cengage Learning,