Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

need a console program that: 1. Uses a while loop to perform the following steps

ID: 3653884 • Letter: N

Question

need a console program that:
1. Uses a while loop to perform the following steps:
a. Prompt the user to input two integers: firstNum and secondNum where secondNum
is at least 10 greater than firstNum, both numbers are positive integers, and
secondNum is less than 1000.
b.Verify that the user entered acceptable numbers, and if not, provide error feedback
and prompt them again.
c.Output all results to a file in the same directory as the program, placing an appropriate
label between each section of output. Note that your program must be able to run
repeatedly overwriting the file from the previous run.
d.Output all odd numbers between firstNum and secondNum inclusive, one number per
line.
e.Output the sum of all numbers between firstNum 5. and secondNum exclusive.
2.Uses a for loop to perform the following steps:
a. Continue writing to the same file as before.
b. Write a label as before.
c.Output all numbers from secondNum to firstNum in a single line with commas
separating the numbers.

3. Write the date and time as the last line in the file in the format yyyy-mm-dd hh:mm:ss.

Explanation / Answer

please rate - thanks

import java.util.Scanner;
import java.util.Date;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.io.*;
public class FileOut
{
public static void main(String[] args)throws IOException
{String filename;
int firstNum,secondNum,error,i,sum;
Scanner in=new Scanner(System.in);
Date d=new Date();
DateFormat ff = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
do
{System.out.print("Enter firstNum: ");
firstNum=in.nextInt();
if(firstNum<=0)
      System.out.println("Must be positive");
}while(firstNum<=0);

do
{ error=0;
System.out.print("Enter secondNum: ");
secondNum=in.nextInt();
if(secondNum<=0)
      {System.out.println("Must be positive");
        error=1;
        }
    if(secondNum>=1000)
        {System.out.println("Must be <1000");
        error=1;
        }
    if(firstNum+10>secondNum&&error==0)
        {System.out.println("Must be at least 10 more than "+firstNum);
        error=1;
        }

}while(error!=0);
System.out.print("Enter the name of your output file: ");
filename=in.next();
PrintStream f=new PrintStream(new File(filename));
f.println("odd numbers between "+firstNum+" and "+secondNum);
for(i=firstNum;i<=secondNum;i++)
     if(i%2==1)
          f.println(i);
sum=0;
f.println("Sum of numbers between "+firstNum+" and "+secondNum);
for(i=firstNum+1;i<secondNum;i++)
      sum+=i;
f.println(sum);
f.println("The numbers backward between "+firstNum+" and "+secondNum);
for(i=secondNum ;i>firstNum;i--)
     f.print(i+", ");
f.println(firstNum);
f.println(ff.format(d));       
f.close();

}
}