/*
1
    Write a JAVA program which performs the following tasks
   
    A    Create a package named MyPackage which consists of following classes:

              class names Student to store information like roll number, first name,
            middle name, last name, address and age of the student. The class must
            contain appropriate get and set methods.

    B    A class named TestProgram which when executed displays a menu with following operations:
            1    Add a new record
            2    Show all records
            3    Search a record
            4    Remove a record
            5    Exit

            1    For “Add a new record”, take input from the user for the Student member
                variables and store the same details in the pre – configured data file as objects of Student class

*/



package MyPackage;
import java.util.*;
import java.io.*;

class Student
{
    int rollno;
    String firstName;
    String middleName;
    String lastName;
    String address;
    int age;

    Student(int rollno,String firstName,String middleName, String lastName, String address,int age)
    {
        this.rollno=rollno;
        this.firstName=firstName;
        this.middleName=middleName;
        this.lastName=lastName;
        this.address=address;
        this.age=age;
    }
    void display()
    {
        System.out.println();
        System.out.println("Roll No : ->"+rollno);
        System.out.println("First Name : ->"+firstName);
        System.out.println("Middle Name : ->"+middleName);
        System.out.println("Last Name : ->"+lastName);
        System.out.println("Address : ->"+address);
        System.out.println("Age : ->"+age);

    }

}
class TestStudent
{
    public static void main(String args[]) throws Exception
    {
        while(true)
        {
            Scanner s=new Scanner(System.in);
            System.out.println("Main Manu");

            System.out.println("1.Add a new record");
            System.out.println("2.show all record");
            System.out.println("3.serch a record");
            System.out.println("4.Remove a record");
            System.out.println("5.Exit");

            System.out.print("Enter Your choice : -");
            int choice=s.nextInt();

            switch(choice)
            {
                case 1:
                   
                    System.out.print("Enter Roll Number ->");
                    int rollno=s.nextInt();

                    System.out.print("Enter First Name ->");
                    String firstName=s.next();

                    System.out.print("Enter Middle Name ->");
                    String middleName=s.next();

                    System.out.print("Enter Last Name ->");
                    String lastName=s.next();

                    System.out.print("Enter Address ->");
                    String address=s.next();

                    System.out.print("Enter Age ->");
                    int age=s.nextInt();

                    Student stu=new Student(rollno,firstName,middleName,lastName,address,age);
                    stu.display();

                    FileWriter fw=new FileWriter("Student.doc",true);
                    fw.write('\n'+""+rollno+" "+firstName+" "+middleName+" "+lastName+" "+address+" "+age);
                    fw.close();

                    break;
               
                case 2:

                    FileReader fr=new FileReader("Student.doc");
                    BufferdReader br=new BufferdReader(fr);
                    String rc;
                    while((rc=br.readLine())!=null)
                            System.out.print(rc);
                    br.close();
                    fr.close();
               
                    break;
               
                case 3:
               
                    break;
               
                case 4:
               
                    break;
               
                case 5:
                   
                    System.out.println("Goog Buy...!!!");
                    System.exit(0);
                    break;

                default:
                    System.out.println("Please Enter Valid Choice...");
               

            }


        }
    }
}

No comments:

Post a Comment

Unleashing B2B Success: Mastering Event and Conversion Tracking with GA4

Tracking events and conversions is vital for B2B businesses using GA4 (Google Analytics 4) to optimize their marketing efforts. Here is a re...