Java Programming
9th Edition
ISBN: 9780357616635
Author: Joyce Farrell
Publisher: CENGAGE L
expand_more
expand_more
format_list_bulleted
Concept explainers
Expert Solution & Answer
Chapter 7, Problem 9RQ
<PROGRAM-DESCRIPTION-ANSWER>
The expression name1.compareTo(name2) contains the value “-1”.
Hence, the correct option is “C”.
</PROGRAM-DESCRIPTION-ANSWER>
Explanation of Solution
Given:
String name1 = new String ("Jordan");
String name2 = new String ("Jore");
To find:
name1.compareTo (name2)
Explanation:
- Here, “name1” is the string variable and assign with a string value “Jordan”.
- The “name2” is the string variable and assign with a string value “Jore”...
Expert Solution & Answer
Want to see the full answer?
Check out a sample textbook solutionStudents have asked these similar questions
The __str__ method of the Bank class (in bank.py) returns a string containing the accounts in random order. Design and implement a change that causes the accounts to be placed in the string in ascending order of name.
Implement the __str__ method of the bank class so that it sorts the account values before printing them to the console.
In order to sort the account values you will need to define the __eq__ and __lt__ methods in the SavingsAccount class (in savingsaccount.py).
The __eq__ method should return True if the account names are equal during a comparison, False otherwise.
The __lt__ method should return True if the name of one account is less than the name of another, False otherwise.
The program should output in the following format:
Test for createBank: Name: Jack PIN: 1001 Balance: 653.0 Name: Mark PIN: 1000 Balance: 377.0 ... ... ... Name: Name7 PIN: 1006 Balance: 100.0
bank.py
"""
File: bank.py
Project 9.3
The str for Bank returns a string of accounts sorted by name.…
The __str__ method of the Bank class (in bank.py) returns a string containing the accounts in random order. Design and implement a change that causes the accounts to be placed in the string in ascending order of name.
Implement the __str__ method of the bank class so that it sorts the account values before printing them to the console.
In order to sort the account values you will need to define the __eq__ and __lt__ methods in the SavingsAccount class (in savingsaccount.py).
The __eq__ method should return True if the account names are equal during a comparison, False otherwise.
The __lt__ method should return True if the name of one account is less than the name of another, False otherwise.
When you want to work with an object, you use a variable that holds a special value known as a(n) __________ to link the variable to the object. a. union b. reference c. object linker d. data coupling
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
- write an application that reads English-Language phrase and encodes it into morse code. also write an application that reads a phrase in morse code and converts it into the English-Language equivalent . Use one blank between each Morse-code letter and three blanks between each Morse-coded word.arrow_forwardIntelliJ 1. Create a String constant ‘SPACE’, which holds a space ( “ “ ). final String SPACE = " "; /*‘final’ keyword creates a constant in Java. Once a ‘final’ variable is initialized, it values cannot be changed*/2. Get the name of your ( or a fictional ) pet and save it to a String variable. 3. Get the age of your (or a fictional ) pet and save it to an int variable.4. Print out the name and age of your pet, use your constant in the println wherever space character is needed. Sample output: Enter name: Yoyo Enter age: 3 My pet's name:Yoyo My pet's age: 3arrow_forwardname: string - ownerName: String Cat numberOfTeeth int lengthofTail : int + Cat (name: String, ownerName: String, numberOfTeeth: int, lengthofTail:int) i. ii. + Pet (name:String, ownerName: String) + getName(): String + getownerName (): String + getNumberOfTeeth (): int + getLengthofTail(): int Pet iii. Budgie colourOfFeathers: String + Budgie (name: String, 1. Convert the UML class diagram above into a java code with the following conditions The methods in the Pet class are abstract. ownerName: String, colourofFeathers:String) + getColourOfFeathers (): String Create a class called test. The main() method in the test class should create three Cat objects and two Budgie objects. The main() method should also create indirectly an object of the Pet class. Demonstrate polymorphism in your test class. 2. Write a Java Code for a simple GUI program that creates a frame and changes the background to green. Examiner's Name: George Kodjo Anniarrow_forward
- class Point: """ A point in a two-dimensional coordinate plane """ def __init__(self, x, y): """ Create a point with an x and y coordinate """ self.x = x self.y = y def __str__(self): """ Generate a string representation of a point """ return("(" + str(self.x) + "," + str(self.y) + ")") # Part 1 - Rectangle Classclass Rectangle: """ A rectangle in a two-dimensional coordinate plane """ def __init__(self, bottom_left_x, bottom_left_y, top_right_x, top_right_y): """ Create a rectangle defined by its bottom left and top right corner coordinates """ self.bottom_left = Point(bottom_left_x, bottom_left_y) self.top_right = Point(top_right_x, top_right_y) self.bottom_right = Point(top_right_x, bottom_left_y) self.top_left = Point(bottom_left_x, top_right_y) def __str__(self): """ Generate a string…arrow_forwardWrite a program in the StringManipulator class that creates a String variable that references a String object holding the name of your favorite city. The program should display the following: • The number of characters in the city name• The name of the city in all uppercase letters • The name of the city in all lowercase letters • The first character in the name of the cityarrow_forwardclass Point: """ A point in a two-dimensional coordinate plane """ def __init__(self, x, y): """ Create a point with an x and y coordinate """ self.x = x self.y = y def __str__(self): """ Generate a string representation of a point """ return "(" + str(self.x) + "," + str(self.y) + ")" ############################# Part 1 - Rectangle Class############################class Rectangle: """ A rectangle in a two-dimensional coordinate plane """ def __init__(self, bottom_left_x, bottom_left_y, top_right_x, top_right_y): """ Create a rectangle defined by its bottom left and top right corner coordinates """ self.bottom_left = Point(bottom_left_x, bottom_left_y) self.top_right = Point(top_right_x, top_right_y) def __str__(self): """ Generate a string representation of a rectangle """ return ("Rectangle with…arrow_forward
- class Keyboard: """A Keyboard takes in a list of buttons, and has a dictionary of positions as keys, and Buttons as values. >>> b1 = Button("button1", "H") >>> b2 = Button("button2", "I") >>> k = Keyboard ([b1, b2]) >>> "button1" in k.buttons.keys () # Make sure to add the button to dictionary True >>> k.buttons ["button1"].letter 'H' >>> k.buttons ["button1"].name 'button1' >>> k. press ("button1") 'H' >>> k.press ("button100") >>> b1.pressed 1 >>>b2.pressed 0 >>> k. typing ( ["button1", "button2"]) 'HI' >>> k. typing ( ["button2", "button1"]) 'IH' >>> b1.pressed # make sure typing calls press! 3 >>>b2.pressed 2 definit__(self, buttons): self.buttons = {} "*** YOUR CODE HERE ***" def press (self, name): """Takes in a name of the button pressed, and returns that button's letter. Return an empty string if the button does not exist. You can access the keys of a dictionary d with d. keys (). "*** YOUR CODE HERE ***" def typing (self, typing_input): ""Takes in a list of names of buttons to…arrow_forwardProgramming in C#: Write a console-based application that displays every perfect number from 1 through 10000. A number is perfect if it equals the sum of all the smaller positive integers that divide evenly into it. For example, 6 is perfect because 1, 2, and 3 divide evenly into it and their sum is 6. Use format strings(field size 8, right alignment) to show all perfect numbers. Display the results as seen below. 6 28 496 8128arrow_forwardJAVAA7-Write a class with a constructor that accepts a String object as its argument. The class should have a method that returns the number of vowels in the string, and another method that returns the number of consonants in the string. Demonstrate the class in a program by invoking the methods that return the number of vowels and consonants. Print the counts returned.arrow_forward
- Define a class called StringFormatter. The purpose of an object of this class is to store a string variable (you may use the C++ string type or a char array). An object of this class can be created by calling a constructor that accepts one string argument. The string to be passed as argument will be a long line of text, such as “The world is indeed full of peril and in it there are many dark places. But still there is much that is fair. And though in all lands, love is now mingled with grief, it still grows, perhaps, the greater.” The object will also have a function called printRightAligned() which accepts one integer argument n. The value of the argument represents the maximum number of characters that can be displayed on a line. This function displays the string stored in the object’s attribute on the screen, right aligned and with no more than n characters per line. Similarly, there should be a function called printLeftAlgigned() which displays the text left aligned, again, with no…arrow_forwardCreate an application with a method that accepts a string as an argument and returns a copy of the string with the first character of each sentence capitalized. For instance, if the argument is "hello. my name is Joe. what is your name?" the method should return the string "Hello. My name is Joe. What is your name?" The application should let the user enter a string and then pass it to the method. The modified string should be displayed.arrow_forwardA namespace is container that holds __________. a. methods b. names c. spaces d. classesarrow_forward
arrow_back_ios
SEE MORE QUESTIONS
arrow_forward_ios
Recommended textbooks for you
- EBK JAVA PROGRAMMINGComputer ScienceISBN:9781337671385Author:FARRELLPublisher:CENGAGE LEARNING - CONSIGNMENTProgramming Logic & Design ComprehensiveComputer ScienceISBN:9781337669405Author:FARRELLPublisher:Cengage
EBK JAVA PROGRAMMING
Computer Science
ISBN:9781337671385
Author:FARRELL
Publisher:CENGAGE LEARNING - CONSIGNMENT
Programming Logic & Design Comprehensive
Computer Science
ISBN:9781337669405
Author:FARRELL
Publisher:Cengage