COMPUTER PROJECT
COMPUTER PROJECT
Topic –
1. Ch – 8 (CONDITIONAL CONSTRUCTS IN JAVA –
DECISION MAKING STATEMENTS)
Programs 9 – 22
QUESTION 9
public class GreatestInteger
{
public static void main(String[] args)
{
int x = 5;
int y = 10;
if(x > y)
{
System.out.println(x + " is greatest integer.");
}
if(y > x)
{
System.out.println(y + " is greatest integer.");
}
else
{
System.out.println("Both integers are equal.");
}
}
}
QUESTION 10
import java.util.*;
public class CharConversion
{
public static void main(String[] args)
{
Scanner in = new Scanner(System.in);
System.out.print("Enter a character: ");
char ch = in.next().charAt(0);
char newCh = ch;
if (ch >= 'A' && ch <= 'Z')
{
newCh+=32;
}
else if (ch >= 'a' && ch <= 'z')
{
newCh-=32;
}
System.out.println("Original character: " + ch);
System.out.println("New character: " + newCh);
}
}
QUESTION 11
import java.util.*;
public class FestivalDiscount
{
void Discount (double tCost)
{
double d = 0.0;
if(tCost <= 2000)
{
d = 5.0;
}
else if(tCost > 2000 && tCost <= 5000)
{
d = 25.0;
}
else if (tCost > 5000 && tCost <= 10000)
{
d = 35.0;
}
else
{
d = 50.0;
}
double discount = (d/100.0) * tCost;
double dAmt = tCost - discount;
System.out.println("Total cost before discount: " + tCost);
System.out.println("Amount to be paid after availing discount: " + dAmt);
}
public static void main(String args[])
{
FestivalDiscount dis = new FestivalDiscount();
Scanner in = new Scanner(System.in);
System.out.println("Enter the total cost: ");
double tCost = in.nextDouble();
dis.Discount(tCost);
}
}
QUESTION 12
import java.util.*;
public class Streams {
void Eligibility(int marks) {
System.out.println("Total marks obtained: " + marks);
System.out.print("Stream allotted: ");
if (marks >= 300) {
System.out.print("Science");
} else if (marks >= 200 && marks < 300) {
System.out.print("Commerce");
} else if (marks >= 75 && marks < 200) {
System.out.print("Arts");
} else {
System.out.print("Admission is not granted, you have to appear in a
qualifying examination.");
}
}
public static void main(String[] args) {
Streams s = new Streams();
Scanner in = new Scanner(System.in);
System.out.print("Enter your marks: ");
int marks = in.nextInt();
s.Eligibility(marks);
}
}
QUESTION 13
import java.util.*;
return tb / 100.0;
}
QUESTION 14
import java.util.*;
public class Amount1
{
double Amount(double P, double n)
{
double r = 0.0, a = 0.0;
if(n < 1)
{
r = 9.0;
}
else if (n >= 1 && n < 2)
{
r = 10.0;
}
else if(n >= 2 && n <= 3)
{
r = 11.0;
}
else
{
r = 12.0;
}
a = P * Math.pow((1 + r/100.0), n);
return a;
}
public static void main(String[] args)
{
Amount1 amt = new Amount1();
Scanner in = new Scanner(System.in);
System.out.println("Enter the principal amount deposited(P): ");
double P = in.nextDouble();
System.out.println("Enter the number of years(n): ");
double n = in.nextDouble();
double newA = amt.Amount(P, n);
System.out.println("Acquired amount by the investors: " + newA);
}
}
QUESTION 15
import java.util.*;
switch (c) {
case 'F':
case 'f':
System.out.println("Enter the age: ");
a = in.nextInt();
if (a > 60 && a <= 65) {
amt = 45;
System.out.println("Weekly pension: " + amt + " rupees");
} else if (a > 65) {
amt = 45 + 25;
System.out.println("Weekly pension: " + amt + " rupees");
} else {
System.out.println("The person is below the pensionable age and thus
cannot be granted pension.");
}
break;
case 'M':
case 'm':
System.out.println("Enter the age: ");
a = in.nextInt();
default:
System.out.println("Invalid sex entered.");
break;
}
}
public static void main(String[] args) {
Pension pension = new Pension();
pension.calculatePension();
}
}
QUESTION 16
import java.util.*;
QUESTION 17
int y;
y = (y >= 150)? y * 15 : y - 15;
QUESTION 18
int ch, m;
if(m > 300)
{
ch = (m/10) * 2;
}
else
{
ch = (m/20) - 2;
}
QUESTION 19
char res; int mark;
res = (mark > 300)? 'P' : 'F';
QUESTION 20
int n = 0;
switch(ch)
{
case 1:
n = n + 2;
break;
case 2:
n = n + 4;
break;
case 3:
n = n + 6;
break;
default:
System.out.println("OOPs ! try again");
}
QUESTION 21
int v;
if(v == 1)
{
System.out.println("First");
}
else if(v == 0)
{
System.out.println("Zero");
}
else if(v == -3)
{
System.out.println("Minus Three");
}
QUESTION 22
int v;
if(v == 1)
{
System.out.println("First");
}
else if(v == 0)
{
System.out.println("Zero");
}
else if(v == -3)
{
System.out.println("Minus Three");
}
QUESTION 18
import java.util.*;
public class Cubes {
void print()
{
int s = 0, cb = 0;
for(int i = 1; i <= 10; i++ )
{
cb = i * i * i;
System.out.print(cb + " ");
s+= i * i * i;
}
System.out.println();
System.out.println("The sum of the cubes of numbers 1 to 10 are " + s);
}
QUESTION 19
import java.util.*;
QUESTION 20
import java.util.*;
public class Even_Sum {
void Even() {
int i = 2, s = 0;
while(i < 40) {
if(i % 2 == 0) {
s+= i;
}
i++;
}
System.out.print("The sum of all the even numbers between 1 and 40 is " + s);
}
public static void main(String[] args) {
Even_Sum evenSum = new Even_Sum();
Scanner in = new Scanner(System.in);
evenSum.Even();
}
}
QUESTION 21
import java.util.*;
public class OddSum {
void Odd() {
int i = 2, s = 0;
while (i < 40) {
if (i % 2!= 0) {
s += i;
}
i++;
}
System.out.print("The sum of all the odd numbers between 1 and 40 is " + s);
}
public static void main(String[] args) {
OddSum oddSum = new OddSum();
oddSum.Odd();
}
}
QUESTION 22
import java.util.*;
public class Factorial1 {
void Factorial(int n) {
int f = 1;
for (int i = 1; i <= n; i++) {
f *= i;
if (i == n) {
System.out.print(i);
break;
}
System.out.print(i + "X");
}
System.out.print(" or ");
for (int i = n; i >= 1; i--) {
if (i == 1) {
System.out.print(i);
break;
}
System.out.print(i + "X");
}
System.out.print(" = " + f);
}
QUESTION 23
public class Capital_letters
{
public static void main(String[] args)
{
char i;
System.out.println("All capital letters from A to Z are: ");
for(i = 'A'; i <= 'Z'; i++)
{
System.out.print(i + " ");
}
}
}
QUESTION 24
import java.util.*;
public class Prime {
void findPrime(int N) {
if (N == 1) {
System.out.println(N + " is not a prime number.");
return;
}
int c = 0;
for (int i = 2; i < N; i++) {
if (N % i == 0) {
c++;
}
}
if (c == 0) {
System.out.println(N + " is a prime number.");
} else {
System.out.println(N + " is not a prime number.");
}
}
QUESTION 25
import java.util.*;
public class Perfect {
void findPerfect(int N) {
int s = 0;
System.out.print("Factors of " + N + " excluding itself are: ");
boolean firstFactor = true;
for (int i = 1; i < N; i++) {
if (N % i == 0) {
if (!firstFactor) {
System.out.print(" + ");
}
System.out.print(i);
s += i;
firstFactor = false;
}
}
QUESTION 26
import java.util.*;
public class SumOfSeries {
void Sum(int x, int n) {
int s = 0;
System.out.println("The sum of the series is as follows: ");
for(int i = 0; i <= n; i+=2) {
if(i == n) {
System.out.print(x + "^" + i);
s+= (int) Math.pow(x, i);
break;
}
System.out.print(x + "^" + i + " + ");
s+= (int) Math.pow(x, i);
}
System.out.println(" = " + s);
}
public static void main(String[] args) {
SumOfSeries sumOfSeries = new SumOfSeries();
Scanner in = new Scanner(System.in);
System.out.println("Enter the value of x: ");
int x = in.nextInt();
System.out.println("Enter the value of n: ");
int n = in.nextInt();
sumOfSeries.Sum(x, n);
}
}
QUESTION 27
import java.util.*;
public class Series12 {
void Sum1() {
int series;
System.out.println("The required series upto 12 terms is as follows: ");
for(int i = 1; i <= 12; i++) {
series = (i * i) - 1;
if(i == 12) {
System.out.print(series);
break;
}
System.out.print(series + ", ");
}
}
public static void main(String[] args) {
Series12 s = new Series12();
Scanner in = new Scanner(System.in);
s.Sum1();
}
}
***********