Concept explainers
Write a method that tests whether a file name should come before or after another. File names are first sorted by their extension (the string after the last period) and then by the name part (the string that remains after removing the extension). For example, before("report.doc", "notes.txt") should return true and before("report.txt", "notes.txt") should return false. Provide helper methods that return the extension and name part of a file name.
Want to see the full answer?
Check out a sample textbook solutionChapter 5 Solutions
Big Java Late Objects
Additional Engineering Textbook Solutions
Programming in C
Database Concepts (7th Edition)
Starting Out with Java: From Control Structures through Data Structures (3rd Edition)
Starting Out with C++ from Control Structures to Objects (9th Edition)
Experiencing MIS
Introduction To Programming Using Visual Basic (11th Edition)
- A for construct is a loop that goes over a list of objects. Consequently, it runs indefinitely if there are items to process. What do you think about this?arrow_forwardIn java Start with the file AList.java and add the following methods: Add the method public int getLastIndex(T item) which returns the index of the last entry which is equal to item. If item is not found, it returns -1. Add the method public int removeEvery(T item) that removes all occurrences of item and returns the number of removed items. Add the method public boolean equals(Object other) that returns true when the contents of 2 AList objects are the same. Note that 2 AList objects are the same if they have the same number of items and each item in one object is equal to the item in its corresponding location in the other objectarrow_forwardWrite a method that asks for input for any number of student records. Student records include student first and last name, letter grade received, and year the course was taken. Write this information to a file called students.dat. Hint: Many students want to label the data they put into a file. If it is a data file (a file to store data that is not intended to be human-readable) the data does not need labels, you can just format it in a way that makes sense to the program to read it back in. Alternatively, you can add labels, but when reading the file, you may end up needing to ignore those labels in the program that reads the data. ****JAVA ONLY**** *p.s haven't learned the try method yet.arrow_forward
- Add a method called multiplesOfFive to the Exercise class. The method must have a void return type and take a single int parameter called limit. In the body of the method, write a while loop that prints out all multiples of 5 between 10 and limit (inclusive) on a single line. For instance, if the value of limit were 15 then the method will print: 10 15 You can use the printEvenNumbers method that is already in the Exercise class as an example to help you work out how to complete this method. In the main method of the Main class, add a call on the Exercise object to your multiplesOfFive method that prints the multiples of 5 between 10 and 25. Add a method called sum to the Exercise class. The method must have a void return type and take no parameters. In the body of the method, write a while loop to sum the values 1 to 10 and print the sum once the loop has finished. In the main method of the Main class, add a call on the Exercise object to your sum method. Check that it prints: 55 Add…arrow_forwardThe file Parameters.java contains a program to test the variable-length method average.1. Read the code. Fill in the code to compute mean1 and mean2. Notice that you are calling the same method, but with a different number of parameters. 2. Add a call to find the average of a single integer, say 8. Print the result of the call. Is the result what you expected?3. Add a call with an empty parameter list and print the result. Is the result what you expected?4. Add a method called minimum to return the minimum value of the parameter list. Invoke this method in the main() and test it with different input numbers. //*******************************************************// Parameters.java//// Illustrates the concept of a variable parameter list.//*******************************************************import java.util.Scanner;public class Parameters{ //----------------------------------------------- // Calls the average and minimum methods with // different numbers of parameters.…arrow_forwardWrite a method that takes an animal name as a parameter and returns the largest count for that animal in a single Sighting record.arrow_forward
- Write a test class that has a method to test how long it takes to count from 1 to 10000 in a loop. You can use the method currentTimeMillis from class System to help with the time measurement.arrow_forwardDescription is " A MathVector object will be passed to your method. Return its contents as a String. If you look in the file MathVector.java you'll see there is a way to output the contents of a MathVector object as a String. This makes it useful for displaying to the user. You might have noticed that there's an @override term there. That's because many objects already have a "toString()" method associated with them... because Java was designed to include them by default. Here, the override tells Java "I know, I know. You already have a toString() that you'd assign here. But it's not good enough. Here's a better one for this particular kind of object." It's a little bit like saying "Most humans have two legs. So, by default, I'll give everyone two legs. But sometimes we override that and give no legs, or just one leg to a person. And sometimes we give them four so that they can be a centaur!" To use this in a println() method, just name your object. The toString()…arrow_forwardMake a class that represents a file. This class will have the ability to calculate the number of lines in that file and the ability to search through the file. The getNumMatchingWords method will take a bit of text and determine how many lines contain that text. Make the comparison not care about case. Example: if the user is searching for hello and a line contains the text hello hello hello then this counts as one. Use the contains method defined on Strings to help with this. Fields - filename : String Methods + FileStats(filename : String) + getNumMatchingWords(key : String) : int + getNumLines() : int Use test case 1 as resultarrow_forward
- Write a method lastNameFirst that takes a string containing a name such as "Harry Smith" or "Mary Jane Lee", and that returns the string with the last name first, such as "Smith, Harry" or "Lee, Mary Jane".arrow_forwardComplete the convert() method that casts the parameter from a double to an integer and return Note that the main() method prints out the returned value of the convert() method. Ex: If the double value is 19.9, then the output is: 19 Ex: If the double value is 3.1, then the output is: 3 512334.3517088.qx3zqy7 LAB ACTIVITY 1 public class LabProgram { 2 NM & in 3 public static int convert(double d) { /* Type your code here */ 4 5 6 7 } 25.20.1: LAB: Write convert() method to cast double to int 8 public static void main(String[] args) { System.out.println(convert (19.9)); System.out.println(convert(3.1)); 00 00 9 10 11 } 12 } LabProgram.javaarrow_forwardIn intellij Create a method which takes two int parameters and swaps them. Print the values before and after swapping. (Example: ‘before swap: x = 5, y = 10; after swap: x=10, y=5). arrow_forward
- 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