Java Program of Contact Details of Hosteller

Question:

SNMR College of Engineering and Technology wants to create an application to store their students details as well as the details of hostellers.

In case of any changes to be made to the attributes,  admin can update the details like room number and phone number of the hosteler.

Develop a program to implement this scenario.

Create a public class Student with  protected attributes :

int studentId

String name

int departmentId

String gender

String phone

Create a public class Hosteller with private attributes

String hostelName

int roomNumber

Make this class inherit the Student class, as it holds all the properties of Student. 

Use appropriate public getters and setters for both the classes.

Write a class Main with the main function.

In Main class get the input of the hosteller using the method :

public static Hosteller getHostellerDetails().

Invoke this method from the main method and then modify the room number and phone number, if needed.

Sample Input 1:

Enter the Details:
Student Id
1
Student Name
John
Department Id
101
Gender
Male
Phone Number
9876543210
Hostel Name
YMCA
Room Number
10
Modify Room Number(Y/N)
Y
New Room Number
11
Modify Phone Number(Y/N)
Y
New Phone Number
9876543121

Sample Output 1:

The Student Details
1 John 101 Male 9876543121 YMCA 11

Sample Input 2:
Enter the Details:
Student Id
2
Student Name
John Paul
Department Id
112
Gender
Male
Phone Number
9885526536
Hostel Name
YMBA
Room Number
5
Modify Room Number(Y/N)
N
Modify Phone Number(Y/N)
N


Sample Output 2:
The Student Details:
2 John Paul 112 Male 9885526536 YMBA 5

Code:

Main.java

import java.util.Scanner;
public class Main{
    public static Hosteller getHostellerDetails()
    {
        Hosteller h1=new Hosteller();
        Scanner sc=new Scanner(System.in);
        System.out.println("Enter the Details:");
        System.out.println("Student Id");
        int a1=sc.nextInt();
        System.out.println("Student Name");
        sc.nextLine();
        String b1=sc.nextLine();
        System.out.println("Department Id");
        int c1=sc.nextInt();
        System.out.println("Gender");
        sc.nextLine();
        String d1=sc.nextLine();
        System.out.println("Phone Number");
        String e1=sc.nextLine();
        System.out.println("Hostel Name");
        String f1=sc.nextLine();
        System.out.println("Room Number");
        int g1=sc.nextInt();
        h1.setStudentId(a1);
        h1.setName(b1);
        h1.setDepartmentId(c1);
        h1.setGender(d1);
        h1.setPhone(e1);
        h1.setHostelName(f1);
        h1.setRoomNumber(g1);
        System.out.println("Modify Room Number(Y/N)");
        char i=sc.next().charAt(0);
        if(i=='Y')
        {
            System.out.println("New Room Number");
            int x1=sc.nextInt();
            h1.setRoomNumber(x1);
        }
        System.out.println("Modify Phone Number(Y/N)");
        char j=sc.next().charAt(0);
        if(j=='Y')
        {
            System.out.println("New Room Number");
            sc.nextLine();
            String y1=sc.nextLine();
            h1.setPhone(y1);
        }
        return h1;
    }
    public static void main(String args[])
    {
        Hosteller h2=new Hosteller();
        h2=getHostellerDetails();
        System.out.println("The Student Details");
        System.out.println(h2.getStudentId()+" "+h2.getName()+" "+h2.getDepartmentId()+" "+h2.getGender()+
        " "+h2.getPhone()+" "+h2.getHostelName()+" "+h2.getRoomNumber());
        
    }
}

Student.java

public class Student
{
    protected int studentId;
    protected String name;
    protected int departmentId;
    protected String gender;
    protected String phone;
    public void setStudentId(int a)
    {
        studentId=1;
    }
    public void setName(String b)
    {
        name=b;
        
    }
    public void setDepartmentId(int c)
    {
        departmentId=c;
    }
    public void setGender(String e)
    {
        gender=e;
    }
    public void setPhone(String f)
    {
        phone=f;
    }
    public int getStudentId()
    {
        return studentId;
    }
    public int getDepartmentId()
    {
        return departmentId;
    }
    public String getName()
    {
        return name;
    }
    public String getGender()
    {
        return gender;
    }
    public String getPhone()
    {
        return phone;
    }
}

Hosteller.java

class Hosteller extends Student
{
    private String hostelName;
    private int roomNumber;
    public Hosteller()
    {
        hostelName=" ";
        roomNumber=0;
    }
    public void setHostelName(String x)
    {
        hostelName=x;
    }
    public void setRoomNumber(int y)
    {
        roomNumber=y;
    }
    public String getHostelName()
    {
        return hostelName;
    }
    public int getRoomNumber()
    {
        return roomNumber;
    }
}

Recommended:

  1. Interest Calculator – Interface Concept
  2. Bank – Abstract concept
  3. Inheritance – Account
  4. Contact Details of Hosteller
  5. PF and Salary Calculation
  6. Check for Existence of Customer – equals method
  7. Account Manipulation – Abstract class
  8. Employee Loan Eligibility – Polymorphism

15 thoughts on “Java Program of Contact Details of Hosteller”

  1. Hello, my name’s Eric and I just ran across your website at quizforexam.com…

    I found it after a quick search, so your SEO’s working out…

    Content looks pretty good…

    One thing’s missing though…

    A QUICK, EASY way to connect with you NOW.

    Because studies show that a web lead like me will only hang out a few seconds – 7 out of 10 disappear almost instantly, Surf Surf Surf… then gone forever.

    I have the solution:

    Talk With Web Visitor is a software widget that’s works on your site, ready to capture any visitor’s Name, Email address and Phone Number. You’ll know immediately they’re interested and you can call them directly to TALK with them – literally while they’re still on the web looking at your site.

    Plus, now that you’ve got that phone number, with our new SMS Text With Lead feature, you can automatically start a text (SMS) conversation pronto… which is so powerful, because connecting with someone within the first 5 minutes is 100 times more effective than waiting 30 minutes or more later.

    The new text messaging feature lets you follow up regularly with new offers, content links, even just follow up notes to build a relationship.

    Everything I’ve just described is extremely simple to implement, cost-effective, and profitable.

    Eric
    PS: Talk With Web Visitor offers a FREE 14 days trial – and it even includes International Long Distance Calling.
    You have customers waiting to talk with you right now… don’t keep them waiting.

  2. cbd vape winterized

    Good Morning everybody ! we are looking for reviewers who would like to taste and write about our CBD range such as CBD GELS. If interested, please get in touch via

  3. Hey, my name’s Eric and for just a second, imagine this…

    – Someone does a search and winds up at quizforexam.com.

    – They hang out for a minute to check it out. “I’m interested… but… maybe…”

    – And then they hit the back button and check out the other search results instead.

    – Bottom line – you got an eyeball, but nothing else to show for it.

    – There they go.

    This isn’t really your fault – it happens a LOT – studies show 7 out of 10 visitors to any site disappear without leaving a trace.

    But you CAN fix that.

    Talk With Web Visitor is a software widget that’s works on your site, ready to capture any visitor’s Name, Email address and Phone Number. It lets you know right then and there – enabling you to call that lead while they’re literally looking over your site.

    to try out a Live Demo with Talk With Web Visitor now to see exactly how it works.

    Time is money when it comes to connecting with leads – the difference between contacting someone within 5 minutes versus 30 minutes later can be huge – like 100 times better!

    Plus, now that you have their phone number, with our new SMS Text With Lead feature you can automatically start a text (SMS) conversation… so even if you don’t close a deal then, you can follow up with text messages for new offers, content links, even just “how you doing?” notes to build a relationship.

    Strong stuff.

    to discover what Talk With Web Visitor can do for your business.

    You could be converting up to 100X more leads today!

    Eric
    PS: Talk With Web Visitor offers a FREE 14 days trial – and it even includes International Long Distance Calling.
    You have customers waiting to talk with you right now… don’t keep them waiting.
    to try Talk With Web Visitor now.

    If you’d like to unsubscribe

  4. Hi,

    I hope you find this email in good health. I have got an easy 3 step process offer for publishing a guest post on your website;

    1. I will send you 3 interesting topic ideas for a guest post
    2. You will choose one topic out of those
    3. I will then send you a high- quality, plagiarism-free article on that chosen topic

    In return, I would just need you to give me a do-follow backlink within the main article. Please let me know if we shall begin with step 1?

    Best,

    Lindsay Johnson

  5. Hi,

    I hope you are doing well.

    I want to contribute a guest post article to your website that may interest your readers.

    It would be of high quality and free of cost. You can choose the topic of the article from the topic ideas that I’ll send you in my next email once you approve this offer.

    Please note that I will need you to give me a backlink within the guest post article.

    Please let me know if I shall send over some amazing topic ideas?

    Regards,

    Bella Roy

  6. Hi,

    I hope you are doing well.

    I want to contribute a guest post article to your website that may interest your readers.

    It would be of high quality and free of cost. You can choose the topic of the article from the topic ideas that I’ll send you in my next email once you approve this offer.

    Please note that I will need you to give me a backlink within the guest post article.

    Please let me know if I shall send over some amazing topic ideas?

    Regards,

    Lindsay Johnson

  7. Hi,

    I hope you are doing well.

    I want to contribute a guest post article to your website that may interest your readers.

    It would be of high quality and free of cost. You can choose the topic of the article from the topic ideas that I’ll send you in my next email once you approve this offer.

    Please note that I will need you to give me a backlink within the guest post article.

    Please let me know if I shall send over some amazing topic ideas?

    Regards,

    Amber Roy

  8. Hi,

    I hope you are doing well. I want to contribute a guest post article to your website which will help you increase website traffic.

    It will be a simple 3 step process.
    1. I will send you 3 topic ideas for a guest post
    2. You will choose one out of those
    3. I will then send you a high- quality, plagiarism-free article on that chosen topic.

    In return, I would just need one do-follow backlink within the main article. Let me know if we shall start with step 1?

    Best,

    Lindsay Johnson

Leave a Comment

Your email address will not be published. Required fields are marked *

x