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

AtharvNayak_9A_ComputerProject

The document outlines a computer project focused on programming in Java, detailing various programs that perform mathematical calculations, input/output operations, and user interactions. Each program includes a question, code implementation, variable descriptions, and expected outputs. The project covers topics such as arithmetic operations, simple interest calculation, triangle area computation, and a discount calculator for a mall.

Uploaded by

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

AtharvNayak_9A_ComputerProject

The document outlines a computer project focused on programming in Java, detailing various programs that perform mathematical calculations, input/output operations, and user interactions. Each program includes a question, code implementation, variable descriptions, and expected outputs. The project covers topics such as arithmetic operations, simple interest calculation, triangle area computation, and a discount calculator for a mall.

Uploaded by

Miles Morales
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 25

Computer Project

Programming in Java

Arya Nanjayan
INDEX

PROGRAM.NO NAME PAGE NO

Program-01 Program to find the sum and product of the fractional numbers 2, 3

Program-02 Program to print the quotient and remainder of integer 4

Program to solve the equation and print result 5, 6


Program-03
S=(a+b+c)/2 and V=(a2+b2)/c3

Program-04 Program to calculate and print the Simple Interest. 7

Program to Swap values using third variable by parameterized 8, 9


Program-05
method

Program to find the sum and product of first and last digits of a 10, 11
Program-06
three-digit number of a long integer type

Program to calculate and print the marks obtained in all the 12 - 14


Program-07
subjects, total marks and percentage.

Program to input three sides of a triangle (Scanner method) and 15, 16


Program-08
print the area of the triangle using Hero’s formula.

Program to create a calculator. 17-19


Program-09

Slab based program. 20-23


Program-10

1
PROGRAM-01

Question-

Write a program to initialise fractional numbers 7.6,3.2,6.4. Print the sum and product of the numbers

Answer-

public class Program1

public static void main(String args[])

double x = 7.6, y = 3.2, z = 6.4, sum, product; //initializing variables

sum = x+y+z;

product = x*y*z;

System.out.println("Sum is- "+sum);

System.out.println("Product is- "+product);

}//main

}//class

Variable description table-

Variable name Type Description

x double For storing value of 1st number

y double For storing value of 2nd number

z double For storing value of 3rd number

sum double For storing value of sum of


numbers

product double For storing value of product of


numbers

2
Output-

3
PROGRAM-02

Question-

Write a program to print the quotient and remainder of integer 187 by integer 13.

Answer-

public class Program2

public static void main(String args[])

double quotient = 187/13;

double remainder = 187%13;

System.out.println("Quoteint is- "+quotient);

System.out.println("Remainder is- "+remainder);

}//main

}//class

Variable description table-

Variable name Type Description

quotient double For storing value of quotient of


numbers

remainder double For storing remainder of


numbers

Output-

4
PROGRAM-03

Question-

Write a program to assign integers a, b, c with values 3,6,9. Perform, the operations and print the
results of the operations: S=(a+b+c)/2 and V=(a2+b2)/c3

Answer-

public class Program3

public static void main(String args[])

int a = 3, b = 6, c = 9;

double S = (a+b+c)/2; //equation for S

double V = ((a*a)+(b*b))/(c*c*c); //equation for V

System.out.println("Value of S- "+S);

System.out.println("Value of V- "+V);

Variable description table-

Variable name Type Description

a int For storing value of 1st number

b int For storing value of 2nd number

c int For storing value of 3rd number

S double For storing value of 1st equation

V double For storing value of 2nd equation

5
Output-

6
PROGRAM-04

Question-

Write a program to accept Principal amount(P), rate of interest (R) and Time (T) through
parameterized method. Calculate and print the Simple Interest.

Answer-

public class Program4

public static void main(double p, double r, double t)

double si = (p*t*r)/100; //formula for simple interest

System.out.println("Simple Interest is- "+si);

}//main

}//class

Variable description table-

Variable name Type Description

p double For storing value of principle

t double For storing value of time

r double For storing value of rate

si double For storing value of simple


interest

Output-

7
PROGRAM-05

Question-

Write a program to accept values for variables a and b through parameterized method. Swap their
values using third variable. Display the values after swapping.

Answer-

public class Program5

public static void main(int a, int b)

System.out.println("Before swapping- ");

System.out.println("a is "+a);

System.out.println("b is "+b);

System.out.println("-----------");

//swapping

int temp = a;

a = b;

b = temp;

System.out.println("After swapping- ");

System.out.println("a is "+a);

System.out.println("b is "+b);

}//main

}//class

8
Variable description table-

Variable name Type Description

a int For storing value of a

b int For storing value of a

temp int For temporarily storing value of


a

Output-

9
PROGRAM-06

Question-

8,9Write a program to initialize a three-digit number of a long integer type. Print the sum and product
of first and last digits of that number.

Answer-

import java.util.*;

public class Program6

public static void main(String args[])

Scanner sc = new Scanner(System.in);

System.out.print("Input a three digit long integer- ");

long a = sc.nextLong();

long n1 = a/100;

long n3 = ((a%100)%10);

System.out.println("Sum of first and last digit is- " + (n1+n3) + "\nProduct of first and last digit is-
" + (n1*n3));

}//main

}//class

Variable description table-

Variable name Type Description

a long For storing 3 digit number

n1 long For storing value 1st digit

n2 long For storing value 2nd digit

10
temp int For temporarily storing value of
a

Output-

11
PROGRAM-07

Question-

Create a class Student_Info to input (Scanner method) marks in English, Maths, Physics, Chemistry,
Biology, Computer Applications. Print the marks obtained in all the subjects, total marks and
percentage. (Assume that the maximum mark in each subject is 100)

Answer-

import java.util.*;

public class Student_Info

public static void main(String args[])

Scanner sc = new Scanner(System.in);

//taking input of marks from user

System.out.print("Enter English marks- ");

int eng = sc.nextInt();

System.out.print("Enter Maths marks- ");

int math = sc.nextInt();

System.out.print("Enter Physics marks- ");

int phy = sc.nextInt();

System.out.print("Enter Chemistry marks-

"); int chem = sc.nextInt();

System.out.print("Enter Biology marks- ");

int bio = sc.nextInt();

System.out.print("Enter Computer Applications marks- ");

int comp = sc.nextInt();

12
System.out.println("--------------");

double totalMarks = eng+math+phy+chem+bio+comp; //calculating total

marks double percent = (totalMarks/600)*100; //calculating

percentage earned

//output

System.out.println("English- "+eng+" marks");

System.out.println("Maths- "+math+" marks");

System.out.println("Physics- "+phy+" marks");

System.out.println("Chemistry- "+chem+" marks");

System.out.println("Biology- "+bio+" marks");

System.out.println("Computer Applications- "+comp+"

marks"); System.out.println("Total- "+totalMarks+" marks");

System.out.println("Percentage- "+percent);

}//main

}//class

Variable description table-

Variable name Type Description

eng int For storing marks obtained in


english

Math int For storing marks obtained in


maths

phy int For storing marks obtained in


physics

chem int For storing marks obtained in

13
chemistry

14
bio int For storing marks obtained in
biology

comp
int For storing marks obtained in
computer application

totalMarks
double For storing total marks obtained

percent double For storing percentage obtained

Output-

15
PROGRAM-08

Question-

Write a program to input three sides of a triangle (Scanner method). Print the area of the triangle
using the given formula. The class name is Triangle. (Area=√𝑠(𝑠−𝑎)(𝑠−𝑏)(𝑠−𝑐)

Answer-

import java.util.*;

public class Triangle

public static void main(String args[])

Scanner sc = new Scanner(System.in);

System.out.print("Enter length of 1st side- ");

double a = sc.nextDouble();

System.out.print("Enter length of 2nd side- ");

double b = sc.nextDouble();

System.out.print("Enter length of 3rd side- ");

double c = sc.nextDouble();

double s = (a+b+c)/2; //equation for semi-periemter

double area = Math.sqrt(s*(s-a)*(s-b)*(s-c)); //equation to find area of triangle using


semi- perimeter

System.out.print("Area of triangle is- "+area);

}//main

}//class

16
Variable description table-

Variable name Type Description

a double For storing length of 1st side

b double For storing length of 2nd side

c double For storing length of 3rd side

s double For storing value of semi-


perimeter

area double For storing value of Area

Output-

17
PROGRAM-09

Question-

Write a program to which inputs two integers num1, num2 and operator, that contains an arithmetic
operator (‘+’, ‘--‘, ‘/’ or ‘*’) only. Perform and print the corresponding operation on n1 and n2 on the
basis of the operator using the switch--case or user’s choice statement. For example if n1=6,n2=3
and operator=’*’, then result will be n1*n2=6*3=18 similarly for other operations.

Answer-

import java.util.*;

public class Program9

public static void main(String args[])

Scanner sc = new Scanner(System.in);

double ans=0;

System.out.print("Enter 1st number-");

double n1 = sc.nextDouble();

System.out.print("Enter 2st number-");

double n2 = sc.nextDouble();

System.out.print("Enter arithmetic operation ('+' or '-' or '/' or '*')- ");

char ch = sc.next().charAt(0);

switch (ch)

case '+':

ans = n1+n2;

18
break;

case '-':

ans = n1-n2;

break;

case '*':

ans = n1*n2;

break;

case '/':

ans = n1/n2;

break;

default:

System.out.println("Invalid choice");

}//switch-case

System.out.println("Result is- "+ans);

}//main

}//class

Variable description table-

Variable name Type Description

n1 double For storing value of 1st number

n2 double For storing value of 2nd number

n3 double For storing value of 3rd number

ch char For storing type of operation

ans double For storing final value

19
Output-

20
PROGRAM-10

Question-

An XYZ mall has announced the festive discounts on the purchase of items based on the total cost of
items as per the given criteria.

Total Cost Home Appliances Furniture

Less than 25000 5% 7%

25001-30000 7% 10%

30001-45000 10% 13%

45001 and above 14% 16%

Write a program to input the name of the customer, total cost of purchase, type of the purchase (H for
Home Appliances and F for Furniture) using Scanner class. Compute and display the amount to be
paid by the customer after availing the discount

Answer-

import java.util.*;

public class Program10

public static void main(String args[])

Scanner sc = new Scanner(System.in);

double disc=0, amt;

System.out.print("Enter name- ");

String name = sc.next();

System.out.print("Enter total cost of items- ");

double cost = sc.nextDouble();

System.out.print("Enter type of purchase(H for home appliances and F for furniture)- ");

char ch = sc.next().charAt(0);
21
switch (ch)

case 'H':

if (cost <=25000)

disc = cost * (0.05);

else if (cost <=30000)

disc = cost * (0.07);

else if (cost <=45000)

disc = cost * (0.1);

else if (cost > 45000)

disc = cost * (0.14);

break;

case 'F':

if (cost <=25000)

disc = cost * (0.07);

else if (cost <=30000)

disc = cost * (0.1);

else if (cost <=45000)

disc = cost * (0.13);

else if (cost > 45000)

disc = cost * (0.16);

break;

default:

System.out.println("Invalid choice!");

22
}//switch-case

amt = cost - disc;

System.out.println("Name- "+name);

System.out.println("Cost of purchase- "+cost);

System.out.println("Discount (in Rs)- "+disc);

System.out.println("Total Amount (in Rs)- "+amt);

}//main

}//class

Variable description table-

Variable name Type Description

name string For storing name of customer

cost double For storing cost of items

ch char For storing type of purchase

disc double For storing discount

amt double For storing final amount

Output-

23
24

You might also like