0% found this document useful (0 votes)
43 views11 pages

Lab Assessment: Code Script-Text Format

The document contains 3 coding questions related to Java programming. Question 1 calculates daily allowance (DA) and housing rent allowance (HRA) for employees based on their basic salary. Question 2 defines a method to find the index of an element in an integer array. Question 3 defines Student and Main classes - Student class contains student details as properties while Main class takes user input for a student object and prints the details.

Uploaded by

AppledogDT
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
43 views11 pages

Lab Assessment: Code Script-Text Format

The document contains 3 coding questions related to Java programming. Question 1 calculates daily allowance (DA) and housing rent allowance (HRA) for employees based on their basic salary. Question 2 defines a method to find the index of an element in an integer array. Question 3 defines Student and Main classes - Student class contains student details as properties while Main class takes user input for a student object and prints the details.

Uploaded by

AppledogDT
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 11

LAB ASSESSMENT

Question 1:
Code script-text format:

import java.util.*;
public class Salary
{
public static void main(String args[])
{
double basicSalary;
double gross;
double da;
double hra;

if(basicSalary<10000)
{
da=basicSalary*0.8;
hra=basicSalary*0.2;
System.out.println("DA is " +da);
System.out.println("HRA is " +hra);
}

else if(basicSalary <= 20000 )


{
da=basicSalary*0.9;
hra=basicSalary*0.25;
System.out.println("DA is " +da);
System.out.println("HRA is " +hra);
}

else if(basicSalary > 20000);


{
da=basicSalary*0.95;
hra=basicSalary*0.3;
System.out.println("DA is " +da);
System.out.println("HRA is " +hra);
}

}
}
Code Screen Shot format:
Output:
Question 2:
Code script-text format:
import java.util.*;

class Arrays
{
public static int get(int[] array, int num)
{
for(int i = 0; i < array.length; i++)
{
if(array[i] == num)
{
return(i);
}
}

return(-1);
}

public static void main(String args[])


{
Scanner abc=new Scanner(System.in);
System.out.println("Enter the size of the array: ");
int size=abc.nextInt();
int num[]=new int[size];

for(int k = 0; k < num.length; k++);


{
System.out.println("Enter array values: ");
int arr[] = new int[size];

for(int i = 0; i < arr.length; i++)


{
arr[i] = abc.nextInt();
}
System.out.println("Enter element to find its position: ");
int element = abc.nextInt();

int index = get(arr,element);


System.out.println(index);

}
}
Code Screen Shot format:
Output:
Question 3:
Code script-text format:

For class Student:

public class Student


{
private int reg_no;
private String name;
private String stream;
private int score;

public Student(int reg_no, String name, String stream, int score)


{
this.reg_no=reg_no;
this.name=name;
this.stream=stream;
this.score=score;
}

public int getReg_no() {


return reg_no;
}
public void setReg_no(int reg_no) {
this.reg_no = reg_no;
}

public String getName() {


return name;
}

public void setName(String name) {


this.name = name;
}

public String getStream() {


return stream;
}

public void setStream(String stream) {


this.stream = stream;
}

public int getScore() {


return score;
}

public void setScore(int score) {


this.score = score;
}

For class Main:


import java.util.*;
public class Main
{
public static void main(String args[])
{
Scanner abc=new Scanner(System.in);
System.out.println("Enter the Registration number: ");
int reg_no=abc.nextInt();

System.out.println("Enter the Student name: ");


String name=abc.next();

System.out.println("Enter the Student Stream: ");


String stream=abc.next();
System.out.println("Enter the S: ");
int score=abc.nextInt();

Student stu=new Student(reg_no,name,stream,score);


System.out.println("Student Registration number is "+stu.getReg_no());
System.out.println("Student Name is "+stu.getName());
System.out.println("Student Stream is "+stu.getStream());
System.out.println("Student Score is "+stu.getScore());

Code Screen Shot format:


For class Student:
For class Main:
Output:

You might also like