0% found this document useful (0 votes)
16 views

Lab Assessment 01

The document contains code and explanations for 3 Java programming questions. The first question involves calculating library late fees based on number of days overdue. The second question involves creating an array of numbers from user input and printing odd and even numbers in specific positions. The third question involves reading student registration numbers and counting the number from a specific program and branch.

Uploaded by

Bindu
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
16 views

Lab Assessment 01

The document contains code and explanations for 3 Java programming questions. The first question involves calculating library late fees based on number of days overdue. The second question involves creating an array of numbers from user input and printing odd and even numbers in specific positions. The third question involves reading student registration numbers and counting the number from a specific program and branch.

Uploaded by

Bindu
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 7

Question 1:

Java Basics
Our university library charges a fine for every book returned late. For first
5 days the fine is Rs 2 per day, for 6-10 days fine is three rupees per day
and above 10 days fine is 5 rupees per day. If you return the book after 30
days, it is 50% cost of the book. Write a Java program to accept the
number of days the member is late to return the book and display the fine
appropriate message.

Code:
import java.util.*;
public class ques1 {
public static void main(String[] args) {
int fine;
Scanner s = new Scanner(System.in);
int days;
System.out.print("Enter the number of days: ");
days = s.nextInt();
System.out.print("Enter the cost of the book: ");
int cost = s.nextInt();
if(days<=5)
{
fine=2*days;
System.out.println("The fine is: "+ fine);
}
else if(days>=6 && days<=10)
{
fine=3*days;
System.out.println("The fine is: "+ fine);
}
else if(days>=10 && days<30)
{
fine=5*days;
System.out.println("The fine is: "+ fine);
}
else
{
fine=cost/2;
System.out.println("The fine is: "+ fine);
}
}
}
Input and Output:

Question 2:
Java Arrays
Write a Java Program to create an array of positive numbers from user. The
program should print odd numbers in even position and even number in
odd position. Also total count of odd and even numbers.

Code:
import java.util.Scanner;
public class ques2 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
double t;
int mat[] = new int[4];
int tutors[][]=new int[4][20];
for(int i = 0; i < mat.length; i++) {


System.out.print("Enter the number of students in


the batch "+ (i+1) + ": ");
mat[i]= sc.nextInt();
System.out.println("Enter marks of students in
batch " +(i+1));
int slowlearner = 0;
for (int j=0; j<mat[i]; j++){
int temp = sc.nextInt();
if (temp <25){
slowlearner=slowlearner+1;
}
}
mat[i]=slowlearner;
}
int four=0;
int x;
for (int i=0;i<4;i++) {
x=mat[i]/4;
four += x;
}
System.out.println("Number of batches where all
tutors have 4 students: " +four);
System.out.println("The 2D Array");
for (int i=0;i<4;i++) {
int y = mat[i]/4;
int z = mat[i]%4;
for (int j=0; j<y; j++) {
tutors[i][j] = 4;
System.out.print(tutors[i][j]);
System.out.print(" ");
}
if (z != 0){
tutors[i][y]=z;
}
System.out.println(tutors[i][y]);
}
}
}

Input and Output:


Question 3:
Java Strings
Read 5 registration numbers of VIT Students as input and count the
number of Students from BCE branch in the input given.
Note: Register Number format for example: 17BCE2100.
First two characters specifies admitted year and next three characters
indicates the branch admitted. BCE – BTech CSE.
Also display the students count belongs to programme category as
mentioned below:
BCE, BCB ,BEE - Programme Starts with first letter 'B' indicates BTech
MIS, MIC, MID -Programme Starts with 'MI' indicates MTech Integrated
Code:
import java.util.regex.*;
import java.util.*;
public class ques3 {
public static void main(String[] args) {
String s="BCE";
int count_bce=0;
int count_b=0;
int count_m=0;
Scanner sc=new Scanner(System.in);
for(int i=0;i<5;i++) {
System.out.println("Enter the "+i+1+"
registration number.");
String string =sc.nextLine();
if(Pattern.matches("..B......",string)) {
System.out.println("The student is pursuing
BTech.");
count_b=count_b+1;
}
else if(Pattern.matches("..MI.....",string)) {
System.out.println("The student is pursuing
MTech Integrated.");
count_m=count_m+1;
}
if(Pattern.matches("..BCE....",string)) {
count_bce=count_bce+1;
}
}
System.out.println("The number of Students from
Btech is: " +count_b);
System.out.println("The number of Students from
MTech is: " +count_m);
System.out.println("The number of Students from
BCE branch is: " +count_bce);
}
}

Input and Output:

You might also like