Answer to Question #266593 in Java | JSP | JSF for Shan

Question #266593

Create a class “StudentName” with a main function. Take a variable of integer data type from user and store its value into variable name “rollno”. Print the name of specific student using switch statements.


Hint: Use 4 different cases and one default. The value of cases should be


Case 10


Case 11


Case 12


Case 13

1
Expert's answer
2021-11-15T17:21:56-0500


SOLUTION TO THE ABOVE QUESTION


SOLUTION CODE


package com.company;

import java.util.Scanner;

class StudentName{
    private int rollno;

    StudentName(int rollno)
    {
        this.rollno = rollno;
    }

    public void student_name_given_rollno()
    {
        switch(rollno) {
            case 10:
                System.out.println("Student name is Sylencer");
                break;
            case 11:
                System.out.println("Student name is Daniel");
                break;
            case 12:
                System.out.println("Student name is Nyamai");

                break;
            case 13:
                System.out.println("Student name is kelly");
                break;
            default:
                System.out.println("You have entered an invalid roll number");
        }
    }
}
//now this is our main class
class Main {
    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);
        System.out.print("Enter the roll number of the student: ");
        int rollno = sc.nextInt();
        //create an object of the studentName class
        StudentName my_student = new StudentName(rollno);
        //call the function to tell the name of the student
        my_student.student_name_given_rollno();

    }
}


SAMPLE PROGRAM OUTPUT






Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS