Hi Experts,

Appreciate your help or advise as I am stuck.

The user will input all of the objects (like name, gender, age) into the system. Once, user input it will write to a file.
The program should only handle file handling. is my program correct? Thank you in advance

import java.util.*;
import java.text.*;
import java.io.*;
 import java.util.Scanner;

public class Sample {

    public static void main(String[] args) {
        //if (args.length < 1) {
         //   System.out.println("Please provide output file");
        //    System.exit(0);
      //  }

       // String outputFile = args[0];

        DateFormat dateFormat = new SimpleDateFormat("MM-dd-yyyy");

        try (
            BufferedWriter groceryFile = new BufferedWriter(new FileWriter("grocery.txt", true))) {
            Scanner input = new Scanner(System.in);

            Set<Student> listStudent = new HashSet<>();
            Student student = new Student();
            System.out.println("Student name");
            Student.setName(input.nextLine());

            listStudent.add(
                new Student("Mike", dateFormat.parse("01-15-1998"), false, 40, 80.5f));



            for (Student student : listStudent) {
                groceryFile.write(student.getName());
            }

        } catch (IOException | ParseException ex) {
            ex.printStackTrace();
        }
    }

Does it do what you expected it to do as well as get a passing grade by the instructor? If so, then yes.

Be sure to remove extraneous commented out code to not upset the reviewer.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.20 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.