Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

This program determines the name and type of a file when given its string. For example, the file README.txt has the name README and the

image text in transcribedimage text in transcribedimage text in transcribed

This program determines the name and type of a file when given its string. For example, the file README.txt has the name README and the type is txt. (1) Develop the getFileName and getFileType methods. a) Copy the following method stubs into your FileNameAndType class. * Returns of the name of the file. Hint: look up indexof and substring in the String Class * @param file The complete file String * @return The name of the file */ public static String getFileName (String file) { // TODO: FILL IN BODY * Returns the type of the file as a lower case string. Hint: look up indexOf and substring in the String Class * @param file The complete file String * @return The type of the file public static String getFileType(String file) { //TODO: FILL IN BODY b) Before implementing the getFileName and getFileType methods, think about examples of values (test cases) that might be passed in to file. Copy the following methods into your FileNameAndType class and replace the / *FIX ME*/ with 3 different calls to the getFileName and getFileType methods. Each call should test a different example input to the method. You should have a minimum of 3 tests, but you may have more. * Runs tests on the testGetFileName method. public static void testGetFileName() { System.out.println(/*FIX ME*/); System.out.println(/*FIX ME*/); System.out.println(/*FIX ME*/); * Runs tests on the testGet FileType method. public static void testGet FileType() { System.out.println(/*FIX ME*/); System.out.println(/*FIX ME*/); System.out.println(/*FIX ME*/); c) Implement the getFileName and getFileType methods and use the testGetFileName and testGetFileType methods to test them before submitting, respectively. However, be sure to remove or comment out your test method calls before submitting. (2) Using the following comments, complete the main method. You should create an instance of a Scanner class (Scanner object) with the argument of System.in. Then, for the next three file strings in your Scanner instance, print out (each on their own line) the strings generated by calling getFileName and getFileType. Given the following input: Homework.txt Resume. PDF HelloWorld.java The output should be: Name: Homework, Type: txt Name: Resume, Type: pdf Name: HelloWorld, Type: java import java.util.Scanner; Soovou A WNA public class FileNameAndType { public static void main(String[] args) { //FILL IN BODY

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Machine Learning And Knowledge Discovery In Databases European Conference Ecml Pkdd 2010 Barcelona Spain September 2010 Proceedings Part 1 Lnai 6321

Authors: Jose L. Balcazar ,Francesco Bonchi ,Aristides Gionis ,Michele Sebag

2010th Edition

364215879X, 978-3642158797

More Books

Students also viewed these Databases questions