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

Comp Appl Project

The document contains 6 programs written in Java to solve various math and calculation problems. Each program includes the code, inputs, outputs, and an explanation of the variables and methods used. The programs find the product of the last digits of 3 numbers, calculate simple interest, convert Celsius to Fahrenheit, calculate the area and perimeter of a square, break down time in seconds to hours and minutes, and find the sum of the cube roots of the last digits of 3 numbers.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
22 views

Comp Appl Project

The document contains 6 programs written in Java to solve various math and calculation problems. Each program includes the code, inputs, outputs, and an explanation of the variables and methods used. The programs find the product of the last digits of 3 numbers, calculate simple interest, convert Celsius to Fahrenheit, calculate the area and perimeter of a square, break down time in seconds to hours and minutes, and find the sum of the cube roots of the last digits of 3 numbers.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 18

Don Bosco School,Bandel

Computer
Applications Project
1st term

Swastik Dutta Roy


5/25/2022
INDEX
Program 1
1>write a program to input three integers and find the product of the last digit of the numbers.

Ans> import java.util.Scanner;

class product_of_last_digits

public static void product (String[]args)

Scanner sc=new Scanner(System.in);

int a,b,c,x,y,z,p;//declaring the variables

System.out.println("Enter the three integer numbersconsecutively");

a=sc.nextInt();

b=sc.nextInt(); //value to be assigned by the user

c=sc.nextInt();

x=a%10;

y=b%10; //finding the last digits

z=c%10;

p=x*y*z; //finding the product

System.out.println("The product of the last three digits of the given numbers is:-"+p);

Method name Variable name Data type Uses


sc Scanner Object to accept user
input
a int To accept number
product() from
The user
b int To accept number
from
The user
c Int To accept number
from
the user
x int To store last digits
from given numbers
y int To store last digits
from given numbers
z int To store last digits
from given numbers
p long To store the product
of last digits

Output of program 1

Program 2
2> Write a program to input the principal, rate of interest and time in year. Find out simple
interest and amount.

Ans> import java.util.Scanner;

class simple_interest

public static void simpleinterest(String[]args)

Scanner sc=new Scanner(System.in);


double si,p,r,t;// declaring variables

System.out.println(“Enter the principle”);

p=sc.nextDouble();

System.out.println(“Enter the rate”);

r=sc.nextDouble(); //taking input from the user

System.out.println(“Enter the time”);

t=sc.nextDouble();

si=p*r*t/100.00; finding the simple interest

System.out.println(“The simple interest of the data entered is:-“+si);

Method name Variable name Data type Uses


sc Scanner Object to accept user
input
si double To store the value of
simpleinterest() the simple interest
p double To accept the
principle
r double To accept the rate
t double To accept the time

Output of program 2

Program 3
3> Write a program to accept the temperature in Celsius and convert this temperature into
Fahrenheit.
Ans> import java.util.Scanner;

class temperature_conversion

public static void temperature(String[]args)

Scanner sc=new Scanner(System.in);

double c,f; //declaring variables

System.out.println("Enter the temperature in Celsius");

c=sc.nextDouble(); //calculating the result

f=(c*(9.0/5.0))+32;

System.out.println("The temperature in Fahrenheit is :"+f);

Method name Variable name Data type Use


sc Scanner Object to accept user
input
temperature() c double To accept
temperature in
Celsius from user
f double To store the value
after converting to
fahrenheit
Output of program 3

Program 4
4> Write a program in java to accept side of a square and find out its area and perimeter.

Ans> import java.util.Scanner;

class area_perimeter

public static void mensuration(String[]args)

Scanner sc=new Scanner(System.in);

double l,a,p;

System.out.println("Enter the length of the square");

l=sc.nextDouble();

a=l*l;

p=l*4;

System.out.println("The area of the square is:"+a);

System.out.println("The perimeter of the square is:"+p);


}

Method name Variable name Data type Uses


sc Scanner Object to accept
input from user
l double To accept length
Mensuration() from user
a double To store the area
after calculation
p double Tto store the
perimeter after
calculation

Output of program 4

Program 5
5> Write a program to input time in seconds and display the time broken up as hours,
minutes and
seconds.

Ans> import java.util.Scanner;

class time_conversion

public static void time(String[]args)


{

Scanner sc=new Scanner(System.in);

long seconds,hrs,mins; //declaring variables

System.out.println("Enter the time in seconds");

seconds=sc.nextLong();

hrs=seconds/3600;

mins=seconds/60;

System.out.println("The time in hours:"+hrs);

System.out.println("The time in mins:"+mins);

System.out.println("The time in seconds:"+seconds);

Method name Variable name Data type Uses


sc Scanner Object to accept
input from user
temperature() seconds long To accept time in
seconds from user
hrs long To store the value in
hours after
conversion
mins long To store the value in
minutes after
conversion

Output of program 5
Program 6
6>Write a program to input three integers and find the sum of the cube roots of their last
digits.

Ans> import java.util.Scanner;

class playing_with_numbers

public static void integers(String[]args)

Scanner sc=new Scanner(System.in);

long a,b,c; // declaring the variables

double x,y,z,sum;

System.out.println("Enter the three integers consecutively");

a=sc.nextLong();

b=sc.nextLong(); //taking input from user

c=sc.nextLong();

a=a%10;

b=b%10; //finding the last digit

c=c%10;

x=Math.cbrt(a);

y=Math.cbrt(b); //finding the cube root of last digits

z=Math.cbrt(c);

sum=x+y+z; // finding the sum

System.out.println("The sum of the cube roots of their last digits are:"+sum);

}
Method name Variable Name Data Type Uses
sc Scanner Object to accept
input from user
To accept 1st integer
integers() a long number from user
And also to store last
digit
b long To accept 2nd integer
number from user
And also to store last
digit
c long To accept 3rd integer
number from user
And also to store last
digit
x double To find cube root
from the 1st integer’s
last digit
y double To find cube root
from the 2nd integer’s
last digit
z double To find cube root
from the 3rd integer’s
last digit
sum double To store the sum of x,
y and z

Output of program 6

Program 7
7> Write a program in java to enter three unequal numbers and display the largest among
them.

Ans> import java.util.Scanner;

class numbers

public static void numbers(String[]args)

Scanner sc=new Scanner(System.in);

int a,b,c; //declaring variables

System.out.println("Enter any three unequal numbers");

a=sc.nextInt();

b=sc.nextInt(); //taking input from the user

c=sc.nextInt();

if(a>b&&a>c)

System.out.println("Number "+a+" is the largest");

else if(b>a&&b>c)

{ //finding the largest


numbers

System.out.println("Number "+b+" is the largest");

else

System.out.println("Number "+c+" is the largest");

}
Method Name Variable Name Data Type Uses
sc Scanner Object to accept
numbers() input from user
a int To accept any integer
number from user
b int To accept any integer
number from user
c int To accept any integer
number from user

Output of program 7

Program 8
8> Write a program to accept an integer type number and check whether it is a 3-digit
number as well as divisible by seven or not.

Ans> import java.util.Scanner;

class numbers_part2

public static void numbers(String[]args)

Scanner sc=new Scanner(System.in);

int a,b;//declaring variables

System.out.println("Enter any integer type number");

a=sc.nextInt();
b=a%7;//storing the remainder as 0 if divivsible by 7

if(a>=99&&a<=999&&b==0)

//checking whether divisible 7 and three


{

System.out.println("Given number is a three digit number and divisible by 7");

digit number or not


else if (a>=99&&a<=999)

System.out.println("Given number is a three digit number but not divisible by 7");

else

System.out.println("Given number is not a three digit number");

Method Name Variable Name Data Type Uses


sc Scanner Object to accept
input from user
To accept any 3 digit
a int integer number from
numbers() user
To check whether
b int divisible by 7 or not
by storing the
remainder as zero
Output of program 8

Program 9
9> A travel company wants to give discount to their customer in the following way.
Ticket price % of discount on ticket price
< 3000 5
> =3001 to 10000 8
> =10001 to 25000 10
Above 25000 20
An addition travel tax of 5% of discounted amount will be added and final amount will be
calculated.
Write a program which will accept the ticket price and calculate the final amount.

Ans> import java.util.Scanner;

class ticket_price

public static void ticket_price(String[]args)

Scanner sc=new Scanner(System.in);

double price;

System.out.println("Enter the ticket price");

price=sc.nextDouble();
if(price<=3000)

price=price-((5.0/100.0)*price);

price=price+((5.0/100.0)*price);

System.out.println("Your final amt with additional travel tax of 5% is:"+price);

else if(price>=3001&&price<=10000)

price=price-((8.0/100.0)*price);

price=price+((5.0/100.0)*price);

System.out.println("Your final amt with additional travel tax of 5% is:"+price);

else if(price>=10001&&price<=25000)

price=price-((10.0/100.0)*price);

price=price+((5.0/100.0)*price);

System.out.println("Your final amt with additional travel tax of 5% is:"+price);

else if(price>25000)

price=price-((10.0/100.0)*price);

price=price+((5.0/100.0)*price);

System.out.println("Your final amt with additional travel tax of 5% is:"+price);

Method Name Variable Name Data Type Uses


ticket_price() sc Scanner Object to accept
input from user
price double To accept the ticket
price from the user

Output of program 9

Program 10
10> A library charges a fine for books returned late. Following are the fines:
First five days : 30 paise per day.
Next 5 days : 60 paise per day.
Above ten days: 80 paise per day.
Design a program to calculate the fine assuming that a book is returned N days late.

Ans> import java.util.Scanner;

class library_fine

public static void library_fine(String[]args)

Scanner sc=new Scanner(System.in);

double N;

System.out.println("Enter the days late");

N=sc.nextDouble();

if(N==5)
{

System.out.println("You have to give the fine as 30 paise per day");

if(N>5&&N<=10)

System.out.println("You have to give the fine as 60 paise per day");

if(N>10)

System.out.println("You have to give the fine as 80 paise per day");

Method Name Variable Name Data Type Uses


library_fine() sc Scanner Object to accept
input from user
N double To accept the days
late from the user

You might also like