Concept explainers
Modify your printDetai 1 s method to include printing the reference number. However, the method should print the reference number only if it has been set-that is, if the refNumber string has a non-zero length. If it has not been set, then print the string "ZZZ" instead. Hint: Use a conditional statement whose test calls the 1ength method on the refNumber string.
Want to see the full answer?
Check out a sample textbook solutionChapter 2 Solutions
Objects First with Java: A Practical Introduction Using BlueJ (6th Edition)
Additional Engineering Textbook Solutions
Java: An Introduction to Problem Solving and Programming (8th Edition)
Computer Science: An Overview (13th Edition) (What's New in Computer Science)
C++ How to Program (10th Edition)
Web Development and Design Foundations with HTML5 (8th Edition)
Modern Database Management (12th Edition)
Starting Out with Java: From Control Structures through Data Structures (3rd Edition)
- should provide a method to set a large value as string (e.g. .: "862758250540736047343432411236541 ")arrow_forwardProblem: To write the JUnit test cases for our methods, you need to create two test methods: testLeapYear: This method should test if the isLeapYear method returns true for a given leap year. For example, you can choose the year 2020 and verify if the method returns true for it. If it does, the test will pass. If it doesn't, the test will fail. testNotLeapYear: This method should test if the isLeapYear method returns false for a given non-leap year. For example, you can choose the year 1900 and verify if the method returns false for it. If it does, the test will pass. If it doesn't, the test will fail. --------------------------------------------------------------------------------------------------------------------------------------------------------- import static org.junit.jupiter.api.Assertions.assertTrue; import org.junit.jupiter.api.Test; public class LeapYearTest { // Test case to check if a year is a leap year @Test public void testLeapYear() { //create…arrow_forwardFix the error(s) in the following line of code.decRoyalTitle = strRoyalTitle(Text.StringLength)arrow_forward
- Imagine that the String toUpperCase method did not exist and you were asked to write one. You can't use the String toUpperCase method, but you can use methods on Character. Hint: There is a method Character.toUpperCase(char) which converts a char to uppercase. Hint: There is a method Character.toString(char) which converts a char to a String.arrow_forwardIn this assignment you will demonstrate your knowledge of debugging by fixing the errors you find in the program below. Fix the code, and paste it in this document, along with the list of the problems you fixed.This example allows the user to display the string for the day of the week. For example, if the user passed the integer 1, the method will return the string Sunday. If the user passed the integer 2, the method will return Monday. This code has both syntax errors and logic errors. Hint: There are two logic errors to find and fix (in addition to the syntax errors).Inport daysAndDates.DaysOfWeek;public class TestDaysOfWeek {public static void main(String[] args) {System.out.println("Days Of week: ");for (int i = 0;i < 8;i++) {System.out.println("Number: " + i + "\tDay Of Week: " + DaysOfWeek.DayOfWeekStr(i) )}}}package daysAndDatespublic class DaysOfWeek {public static String DayOfWeekStr(int NumberOfDay) {String dayStr = ""switch (NumberOfDay) {case 1:dayStr =…arrow_forwardThis method simulates the playing of one round of “Rock Paper Scissors”. In this strange version of the game, if both players have the same hand gestures, the return value is 1. If they have different hand gestures, the return value is a 0. If at least one player, provides a string argument that is anything other than rock, paper, or scissors, the return value is -1. The method should not be case-sensitive. For example, rock, ROCK, Rock, and RocK are all valid. The output is in the image I addedarrow_forward
- This method simulates the playing of one round of “Rock Paper Scissors”. In this strange version of the game, if both players have the same hand gestures, the return value is 1. If they have different hand gestures, the return value is a 0. If at least one player, provides a string argument that is anything other than rock, paper, or scissors, the return value is -1. The method should not be case-sensitive. For example, rock, ROCK, Rock, and RocK are all valid. Can’t use system.out.println. You return it. The output should be -1 0 1 In c++arrow_forwardDoes any method in the string object change the contents of the string?arrow_forwardYou are responsible for adding the appropriate testing code to your main. a. The getValedictorian method returns the valedictorian of the class, that is the student with the highest grade point average. Implement this new method. b. The getHonorsPercent method returns the percentage of students in the class who are in the honors program. Use 3.75 as the cutoff GPA. Implement this method. Also print the list of students, by using the isHonor method, in the Honors program. c. An alternate implementation for the School class is being considered, in which the students are stored in an ArrayList instead of an array. Show how the declaration of the data field students would look in this alternate design. MAIN CLASS: import java.util.ArrayList; public class Main { public static void main(String[] args) { System.out.println("Unit07Project2 by Your Name"); System.out.println(); int size = 10; School onw = new School(size); /* Add the code…arrow_forward
- note: You can easily replace a portion of text within a String using the String method "replace()". For example: String svar = "raspberry jam"; svar = svar.replace("jam", "pie"); System.out.println(svar); will print out: raspberry pie A photographer is organizing a photo collection about the national parks in the US and would like to annotate the information about each of the photos into a separate set of files. Write a program that reads the name of a text file containing a list of photo file names. The program then reads the photo file names from the text file, replaces the "_photo.jpg" portion of the file names with "_info.txt", and outputs the modified file names. Assume the unchanged portion of the photo file names contains only letters and numbers, and the text file stores one photo file name per line. If the text file is empty, the program produces no output.arrow_forwardCode in task2 () method as below. Using the String format method just once, display the integer values 1, 10, 100, 1000 each on its own line right justified. The values must not be hard-coded. Example of the output as below. 1 10 100 1000 Hints: Inserting the character sequence \n in a String embeds a 'line feed' (new line - similar to pressing ENTER when typing words in Notepad) in the string e.g. " linel\nline2"arrow_forwardPlease provide Handwritten answer. 16. String and StringBuffer will have same set of methods. Select one: True Falsearrow_forward
- EBK JAVA PROGRAMMINGComputer ScienceISBN:9781337671385Author:FARRELLPublisher:CENGAGE LEARNING - CONSIGNMENTMicrosoft Visual C#Computer ScienceISBN:9781337102100Author:Joyce, Farrell.Publisher:Cengage Learning,