Delete End Page 8 Test the method, by making main!) call Make File). The created
ID: 3908698 • Letter: D
Question
Delete End Page 8 Test the method, by making main!) call Make File). The created file should be opened with nctioning of MakeFile() Notepa Program 8 Create a method named MaxLen! ), which accepts a filename as argument. Maxlent ) opens the file, determines the length of aill strings contained in the file, and returns a value representing the length of the longest string. The method main? ) should call Maxlen( ), however, the methods reside in different classes Program9 Write a method called Compound(), which is supposed to calculate the balance in an Interest-bearing account after a whole number of years. The method should accept three parameters: an integer representing the number of years the account would take to mature, a double representing the interest rate, and a float representing the initial balance in the account. The method should calculate the ending balance of the account, and print it in a dialogbox. Construct the method, which is placed in a class different the one containing maint). The latter method should test Compound(], by requesting all three required values in one input dialog box and calling Compound), sending the three values as arguments Program 10 Write a method called ReadDatal ), which opens a file and reads in the integers stored in it. ReadData should accept the name of the file as an argument. The file should contain exactly 10 values. Using an output dialog, the method then reports the values read in from the file in reverse order, in addition to the sum, average and highest of all those values. (Hint: read the data into an array) Program 11 Create a method named IsPrime(), which accepts a positive integer as parameter. The method returns tru e number. (A prime number is evenly divisble only by 1 and itself, Incorporate this method in a class called MyMathMethods. Create main( ) in a class called MainFile, which will test IsPrime(), by asking the user for a number using an input dialog, and then reporting whether that number is prime or not. Program 12 Construct a method called PrimeTable[), w hich accepts two integer values as arguments. PrimeTable() proceeds to print in a dialogbox all prime numbers in between those two values, by calling on the IsPrime() method constructed earlier. If its first input value is greater than the second, PrimeTable? ) should perform a swap on them to make the table print anyway PrimeTable( ) returns the largest prime number in the range identified by the two parameters Program 13 Make the following changes: 1. modify the Compound() method, such that it returns the ending balance in the account 2. Create a method called ITable( ), in the same class as the one which houses Compound( ). ITable( ) accepts four arguments: the first integer value identifies the maturity period for an account. The second (double) value represents the initial balance in the account. The next two (double) values represent a starting and ending interest rates for a table being built. The table reflects the ending balance in the account from year 1 up to and including the 1st argument, in increments of one year, givern the current interest rate. The current interest rate will run from the 3rd up to and including the 4th argument, in increments of 0.5 percent. ITable( ) should repeatedly call Compound( ) to get the table data. For example suppose that the following4 arguments are provided to ITable):5, 400, 1.5, 3.0, then the resulting table would resemble the following page 87Explanation / Answer
As per Chegg policy, we are supposed to answer first question. Request you to post each of other questions in separate posts.
Given below is the code for the Program 8.
To indent code in eclipse , select code by pressing ctrl+a and then indent using ctrl+i
NOTE: Please make sure you place your input file in the correct folder. If using eclipse, the file should be in the project directly and NOT INSIDE src folder.
Please do rate the answer if it was helpful. Thank you
input file: input.txt
-------
This is some text for a program to check the length of longest word.
Program8.java
---------
import java.io.File;
import java.io.FileNotFoundException;
import java.util.Scanner;
public class Program8 {
//returns the length of longest string the file whosse filename is given
public static int MaxLen(String filename) throws FileNotFoundException
{
Scanner infile = new Scanner(new File(filename));
String s;
int maxLen = 0;
while(infile.hasNext())
{
s = infile.next();
if(s.length() > maxLen)
maxLen = s.length();
}
infile.close();
return maxLen;
}
}
Test.java
----------
import java.io.FileNotFoundException;
import java.util.Scanner;
public class Test {
public static void main(String[] args) {
Scanner keyboard = new Scanner(System.in);
//testing MaxLen() in Program8
try {
String filename;
System.out.println("------ Testing MaxLen() i.e. get length of longest word in a file -------");
System.out.print("Enter input filename containing few words:");
filename = keyboard.next();
int max = Program8.MaxLen(filename);
System.out.println("The longest word length in the file " + filename + " is " + max);
System.out.println("---------------------------");
} catch (FileNotFoundException e) {
System.out.println(e.getMessage());
}
}
}
output
------
------ Testing MaxLen() i.e. get length of longest word in a file -------
Enter input filename containing few words:input.txt
The longest word length in the file input.txt is 7
---------------------------
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.