Professional Documents
Culture Documents
Experiment 3
Experiment 3
Experiment 3
Class OOPs
Type Lab
AIM:
1. Write a program to take input (a number) of a month (1 - 12) and print its equivalent name of the month. ( e.g 1 to Jan,
2 to Feb. 12 to Dec.) Use Scanner class for user input( Hint-use switch case).
4. Write a program that takes students’ info from the user (using Scanner class) and displays output on a black screen.
Use appropriate mutator and accessor. setInfo(),getInfo().
1) Write a program to take input (a number) of a month (1 - 12) and print its
equivalent name of the month. ( e.g 1 to Jan, 2 to Feb. 12 to Dec.) Use
Scanner class for user input( Hint-use switch case).
import java.util.*;
class First4{
public static void main(String [] args){
System.out.println("Name: Muditt Sharmma,Sap ID : 500091725, Roll No.: R2142210506");
switch(i){
case 1:
System.out.println("January");
break;
case 2:
System.out.println("Febuary");
break;
case 3:
System.out.println("March");
break;
case 4:
System.out.println("April");
break;
case 5:
System.out.println("May");
break;
case 6:
System.out.println("June");
break;
case 7:
System.out.println("July");
break;
case 8:
System.out.println("August");
break;
case 9:
System.out.println("September");
break;
case 10:
System.out.println("October");
break;
case 11:
System.out.println("November");
Experiment - 3 1
break;
case 12:
System.out.println("December");
break;
default:
System.out.println("There is an error with the user input");
}
}
}
Algorithm:
1) To use the Scanner class, import the java.util. * module.
2) In the main method, make the scanner object.
3) Using the scanner object, ask the user for inputs and store them in the variable “i”.
4) Use a "i" expression in a switch case statement.
5) Write cases 1 through 12 and statements to print the names of the months that go with them.
class Summision{
public static void main(String args[]){
System.out.println("Name: Muditt Sharmma,Sap ID : 500091725, Roll no. : R2142210506");
Double a=Double.parseDouble(args[0]);
Double b=Double.parseDouble(args[1]);
Double c=a+b;
System.out.println(c);
}
}
Algorithm:
1. Create a summary for your class
Experiment - 3 2
6. Print the output
class Calculator{
public static void main(String args[]){
System.out.println("Name: Muditt Sharmma, Sap ID : 500091725, Roll no. : R2142210506");
Double a,b,Sum,Dif,Prod,Quoet,Rem;
a=Double.parseDouble(args[0]);
b=Double.parseDouble(args[1]);
Sum=a+b;
Dif=a-b;
Prod=a*b;
Quoet=a/b;
Rem=a%b;
}
}
Algorithm:
1. Create a class calculator
5. Assign Sum=a+b
6. Assign Dif=a-b
7. Assign Prod=a*b
8. Assign Quoet=a/b
9. Assign Rem=a%b
Experiment - 3 3
4) Write a program that takes students’ info from the user (using Scanner
class) and displays output on a black screen. Use appropriate mutator and
accessor. setInfo(), getInfo().
import java.util.*;
class StudentRec{
static String Name;
static int Rollno;
static String Branch;
static Scanner input;
Algorithm:
1. Load the java.util.* module.
Experiment - 3 4
7. Create up with the main way
10. Make and use the setinfo() function to get the input.
11. Make the getinfo function and use it to print out the information from the setinfo() function.
Experiment - 3 5