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

Write a JAVA Program · Problem Rent-A-Lemon, Inc., keeps information on each of

ID: 3769396 • Letter: W

Question

Write a JAVA Program

· Problem Rent-A-Lemon, Inc., keeps information on each of its rental cars in the file cars.dat. Each line of the file consists of the three-symbol serial number for a car and the number of miles that car has been driven to date.

Write a program to read information from cars.dat and produce two output files, under50.dat and 50plus.dat. These files should contain, respectively, the serial numbers of cars that have been driven under 50, 000 miles and cars that have been driven at least 50, 000 miles. Sample files are shown.

cars.dat

A10 51029

A20 14293

A30 4123

B10 61770

B30 82001

C05 9182

C20 90910

C30 100301

Output Files

under50.dat

A20

A30

C05

50plus.dat

A10

B10

B30

C20

Explanation / Answer

import java.util.Scanner;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.PrintWriter;
public class ReadnWriteFile
{
   public static void main(String[] args) throws FileNotFoundException
   {
       Scanner scan = new Scanner(new File("cars.dat"));
       PrintWriter out = new PrintWriter("under50.dat");
       PrintWriter out1 = new PrintWriter("50plus.dat");
       int n;
       scan.useDelimiter(" ");
       while (scan.hasNext())
       {
           String str = scan.next();
           n= scan.nextInt();
           if (n<50000)
           {
               out.println(str);
           }
           else
           {
               out1.println(str);
           }                  
  
       }
       out.close();
       out1.close();
   }
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote