JAVA PROGRAMMING-LMS INTEG.MINDTAP
8th Edition
ISBN: 9781337091503
Author: FARRELL
Publisher: Cengage Learning
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
IntelliJ
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: 3
name: 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 Anni
Write 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 city
Chapter 7 Solutions
JAVA PROGRAMMING-LMS INTEG.MINDTAP
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
- JAVAA7-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_forwardQ2arrow_forwardDefine 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_forward
- Create a function that tracks how many times a phrase appears in a string. An number must be returned by the function. Never presume that a string of words can contain punctuation and only one space between words. Create the method with either a String argument or a StringBuilder object so that it can be used.arrow_forwardWrite an application for Cody’s Car Care Shop that shows a user a list of available services: oil change, tire rotation, battery check, or brake inspection. Allow the user to enter a string that corresponds to one of the options, and display the option and its price as $25, $22, $15, or $5, accordingly. Display Invalid Entry if the user enters an invalid item. import java.util.*; public class CarCareChoice { public static void main (String[] args) { // Write your code here } }arrow_forwardThe String class has several overloaded versions of a method that accepts a value of any primitive data type as its argument and returns a string representation of the value. The name of the method is ___________.a. stringValueb. valueOfc. getStringd. valToStringarrow_forward
- Write an application that reads a five-letter word from the user and produces every possible three-letter string that can be derived from the letters of that word. For example, the three-letter words produced from the word “bathe” include “ate,” “bat,” “bet,” “tab,” “hat,” “the” and “tea.”arrow_forward1. A showChar MethodWrite a method named showChar. The method should accept two arguments: a reference toa String object and an integer. The integer argument is a character position within theString, with the first character being at position 0. When the method executes, it shoulddisplay the character at that character position. The method does not return anything.Here is an example of a call to the method:showChar("New York", 2);In this call, the method will display the character w because it is in position 2. Demonstratethe method in a complete program-- use the class name Method_showChar Javaarrow_forward// Converts a string to lowercase, and // displays the string's length // as well as a count of letters public class DebugSeven4 { publicstaticvoidmain(String[] args) { String aString ="HELP!! I need to get 37 things DONE today!!"; int numLetters =0. int stringLength = aString.Length(); System.out.println("In all lowercase, the sentence is: "); for(int i =0; i < stringLength; i++) { char ch = Character.toTheLowerCase(aString.charAt(i)); System.out.print(ch); if(Character.isLetter(ch)) numLetters--; } System.out.println(); System.out.println ("The number of CHARACTERS in the string is " + stringLength); System.out.println(The number of LETTERS is " + numLetters); } }arrow_forward
- Travel Tickets Company sells tickets for airlines, tours, and other travel-related services. Because ticket agents frequently mistype long ticket numbers, Travel Tickets has asked you to write an application that indicates invalid ticket number entries. The class prompts a ticket agent to enter a six-digit ticket number. Ticket numbers are designed so that if you drop the last digit of the number, then divide the number by 7, the remainder of the division will be identical to the last dropped digit. Accept the ticket number from the agent and verify whether it is a valid number. Test the application with the following ticket numbers: . 123454; the comparison should evaluate to true . 147103; the comparison should evaluate to true . 154123; the comparison should evaluate to false Save the program as TicketNumber.java.arrow_forwardMicrosoft Visual C# 7th edition, programming Exercise 8-2. I need help, please, thanks. Create a program for Smalltown Regional Airport Flights that accepts either an integer flight number or string airport code from the options in Figure 8-33. Pass the user’s entry to one of two overloaded GetFlightInfo() methods, and then display a returned string with all the flight details. For example, if 201 was input, the output would be: Flight #201 AUS Austin Scheduled at: 0710 (note that there should be two spaces between 'Austin' and 'Scheduled'). The method version that accepts an integer looks up the airport code, name, and time of flight; the version that accepts a string description looks up the flight number, airport name, and time. The methods return a message if the flight is not found. For example, if 100 was input, the output should be Flight #100 was not found. If no flights were scheduled for the airport code entered, for example MCO, the message displayed should be Flight to MCO…arrow_forwardName format: You must use String object and not StringBuffer or StringBuilder. Many documents use a specific format for a person's name. Write a program that take one Line as an input. Example: Scanner input = new Scanner(System.in); System.out.println(“Enter firstName middleName lastName separated by at least one blank, It may have more than one blank separating firstName middleName lastName."); Input sample : Pat Silly Doe || Note these are separated by at least one blank. String line = input.nextLine() Ex: If the input is: Pat Silly Doe the output is: Doe, P.S. If the input has the form: firstName lastName the output is: lastName, firstInitial. Ex: If the input is: Julia Clark the output is: Clark, J. Please submit the .java source file and the sample run in a text file. Thanksarrow_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