Professional Documents
Culture Documents
Project
2021-22
Name: Rishabh Sanghai
Grade: X - D
Roll No: xx
1
Rishabh Sanghai
ACKNOWLEDGEMENT
2
Rishabh Sanghai
INDEX
S.No. Programs Pg.No.
1. For Loop Pattern Program using switch-case 1-4
2. For Loop Series program 4-9
3. Number Programs (Special Number & Harshad 9 - 13
Number )
4. Function (FruitJuice – using Instance variable) 13 - 17
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
3
Rishabh Sanghai
Question 1:
1 A A A A A
2 3 C C C C
4 5 6 E E E
7 8 9 10 G G
Program 1:
import java.util.Scanner;
Rishabh Sanghai 1
int ch;
ch = sc.nextInt();
switch(ch)
case 1:
System.out.println();
break;
case 2:
Rishabh Sanghai 2
{
alph += 2;
System.out.println();
break;
default:
Output:
Rishabh Sanghai 3
Question 2:
Rishabh Sanghai 4
Program2:
import java.util.Scanner;
void series_1()
int a, n, num;
int facto = 2;
System.out.println("SAMPLE INPUT:");
a = sc.nextInt();
n = sc.nextInt();
num = 1;
double sum = 0;
System.out.println("SAMPLE OUTPUT:");
Rishabh Sanghai 5
if(i % 2 == 0)
else
num += 3;
facto += 2;
int fact = 1;
fact *= input;
return fact;
void fibonacciSeries()
Rishabh Sanghai 6
{
num1 = 0;
num2 = 1;
sum = 0;
num3 = 0;
n = 0;
System.out.println("SAMPLE INPUT:");
n = sc.nextInt();
System.out.println("SAMPLE OUTPUT:");
sum += num1;
num1 = num2;
num2 = num3;
Rishabh Sanghai 7
program2 obj = new program2();
obj.series_1();
obj.fibonacciSeries();
Output:
Rishabh Sanghai 8
Question 3:
Write a menu driven program to accept a number from the user and
check whether it is a Special number or a Harshad number.
Rishabh Sanghai 9
Eg.171
Sum of digits = 1 + 7 + 1 =9
171 is divisible by 9
Program3:
import java.util.Scanner;
public class program3
{
void specialNumber()
{
int n, num, digit, sum = 0;
Scanner sc = new Scanner(System.in);
System.out.println("SAMPLE INPUT");
System.out.print("Enter a number: ");
num = sc.nextInt();
n = num;
System.out.println("SAMPLE OUTPUT");
while (num > 0)
{
digit = num % 10;
int fact = 1;
for(int i = 1; i <= digit; i++)
{
fact=fact * i;
}
sum = sum + fact;
Rishabh Sanghai 10
num = num / 10;
}
if(n == sum)
{
System.out.println(n+" is a special number.");
}
else
{
System.out.println(n+" is not a special number.");
}
}
void harshadNumber()
{
int n,num,digit,sum = 0;
Scanner sc = new Scanner(System.in);
System.out.println("SAMPLE INPUT");
System.out.print("Enter a number: ");
n = sc.nextInt();
num = n;
System.out.println("SAMPLE OUTPUT");
while(n > 0)
{
digit = n % 10;
sum = sum + digit;
n = n/10;
}
if(num % sum == 0)
{
System.out.println(num+ " is a harshad number");
Rishabh Sanghai 11
}
else
{
System.out.println(num+ " is not a harshad number");
}
}
public static void main(String[]args)
{
program3 obj1 = new program3();
obj1.specialNumber();
obj1.harshadNumber();
}
}
Output:
Rishabh Sanghai 12
Question 4:
String flavour: stores the flavour of the juice (e.g. orange, apple, etc.).
Rishabh Sanghai 13
String packType: stores the type of packaging (e.g. tetra-pack, PET
bottle, etc.).
Member functions:
(i) void input(): to input and store the productCode, flavour, packType,
packSize and productPrice.
Write a main method to create an object of the class and call the
above member methods.
Program4:
import java.util.Scanner;
public class FruitJuice
{
int productCode,packSize,productPrice;
String flavour,packType;
void input()
{
Scanner sc = new Scanner(System.in);
System.out.println("SAMPLE INPUT");
System.out.print("Enter the product code: ");
productCode = sc.nextInt();
Rishabh Sanghai 14
System.out.print("Enter the flavour: ");
flavour = sc.next();
System.out.print("Enter the packType: ");
packType = sc.next();
System.out.print("Enter the packSize: ");
packSize = sc.nextInt();
System.out.print("Enter the product price: ");
productPrice = sc.nextInt();
System.out.println("SAMPLE OUTPUT");
}
void discount()
{
productPrice = productPrice - productPrice * 10/100;
}
void display()
{
Rishabh Sanghai 15
}
}
Output:
Rishabh Sanghai 16
Rishabh Sanghai 17