0% found this document useful (0 votes)
18 views11 pages

VASUNDARA Step Program

The document contains multiple Java programs that perform various calculations, including determining age, calculating average marks, converting distances, calculating profit and loss, distributing items, computing fees with discounts, and converting height measurements. Each program prompts the user for input and outputs the results based on the calculations performed. The examples illustrate basic programming concepts such as user input, arithmetic operations, and control structures.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
18 views11 pages

VASUNDARA Step Program

The document contains multiple Java programs that perform various calculations, including determining age, calculating average marks, converting distances, calculating profit and loss, distributing items, computing fees with discounts, and converting height measurements. Each program prompts the user for input and outputs the results based on the calculations performed. The examples illustrate basic programming concepts such as user input, arithmetic operations, and control structures.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 11

VASUNDARA.

N (RA2412703010023)-NWC

1)Write a program to find the age of Harry if the birth year is 2000. Assume
the Current Year is 2024

import java.util.Scanner;

public class HarryAgeCalculator {

public static void main(String[] args) {

Scanner scanner = new Scanner(System.in);

System.out.print("Enter Harry's birth year: ");

int birthYear = scanner.nextInt();

System.out.print("Enter the current year: ");

int currentYear = scanner.nextInt();

int age = currentYear - birthYear;

System.out.println("Harry's age is: " + age);

scanner.close();

}
Input:

Output: Harry's age in 2024 is

2) Sam’s mark in Maths is 94, Physics is 95 and Chemistry is 96 out of 100. Find the average
percent mark in PCM

import java.util.Scanner;

public class AveragePCM {

public static void main(String[] args) {

Scanner scanner = new Scanner(System.in);

System.out.print("Enter Sam's Maths mark (out of 100): ");

int maths = scanner.nextInt();

System.out.print("Enter Sam's Physics mark (out of 100): ");

int physics = scanner.nextInt();

System.out.print("Enter Sam's Chemistry mark (out of 100): ");

int chemistry = scanner.nextInt();

int totalSubjects = 3;
int maxMarksPerSubject = 100;

int totalMarksObtained = maths + physics + chemistry;

int totalMaxMarks = totalSubjects * maxMarksPerSubject;

double averagePercentage = (totalMarksObtained / (double) totalMaxMarks) * 100;

System.out.println("Sam's average percentage in PCM: " + averagePercentage +


"%");

scanner.close();

Input:

Output: Sam’s average mark in PCM is

3) Create a program to convert the distance of 10.8 kilometers to miles.


Hint: 1 km = 1.6 miles

import java.util.Scanner;

public class KilometerToMilesConverter {

public static void main(String[] args) {

// Create Scanner object for user input


Scanner scanner = new Scanner(System.in);

System.out.print("Enter the distance in kilometers: ");

double kilometers = scanner.nextDouble();

double conversionFactor = 1.6;

double miles = kilometers / conversionFactor;

System.out.println(kilometers + " kilometers is equal to " + miles + " miles.");

scanner.close();

}
}

Input:

Output: The distance km in miles is

4) Create a program to calculate the profit and loss in number and percentage based on the
cost price of INR 129 and the selling price of INR 191.

import java.util.Scanner;

public class ProfitLossCalculator {

public static void main(String[] args) {

Scanner scanner = new Scanner(System.in);

System.out.print("Enter the Cost Price (INR): ");

double costPrice = scanner.nextDouble();

System.out.print("Enter the Selling Price (INR): ");

double sellingPrice = scanner.nextDouble();

double profitOrLoss = sellingPrice - costPrice;

double percentage = (profitOrLoss / costPrice) * 100;


System.out.println(

"\nCost Price: INR " + costPrice +

"\nSelling Price: INR " + sellingPrice +

(profitOrLoss > 0 ?

"\nProfit: INR " + profitOrLoss +

"\nProfit Percentage: " + percentage + "%" :

"\nLoss: INR " + (-profitOrLoss) +

"\nLoss Percentage: " + (-percentage) + "%")

);

scanner.close();

}
}

Input:

Output: The Cost Price is INR and Selling Price is INR


The Profit is INR and the Profit Percentage is

1. 5) Suppose you have to divide 14 pens among 3 students equally. Write a program
to find how many pens each student will get if the pens must be divided equally.
Also, find the remaining non-distributed pens.
import java.util.Scanner;
public class PenDistribution {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
System.out.print("Enter the total number of pens: ");
int totalPens = scanner.nextInt();
System.out.print("Enter the number of students: ");
int students = scanner.nextInt();
int pensPerStudent = totalPens / students;

int remainingPens = totalPens % students;

System.out.println(
"\nTotal Pens: " + totalPens +
"\nTotal Students: " + students +
"\nEach student gets: " + pensPerStudent + " pens" +
"\nRemaining non-distributed pens: " + remainingPens
);

scanner.close();
}
}

Input:

Output: The Pen Per Student is and the remaining pen not distributed is

1. 6) The University is charging the student a fee of INR 125000 for the course. The University
is willing to offer a discount of 10%. Write a program to find the discounted amount and
discounted price the student will pay for the course.

import java.util.Scanner;

public class UniversityFeeCalculator {

public static void main(String[] args) {

Scanner scanner = new Scanner(System.in);

System.out.print("Enter the course fee (INR): ");


double fee = scanner.nextDouble();

System.out.print("Enter the discount percentage: ");

double discountPercent = scanner.nextDouble();

double discount = (fee * discountPercent) / 100;

double finalAmount = fee - discount;

System.out.println(

"\nOriginal Course Fee: INR " + fee +

"\nDiscount Percentage: " + discountPercent + "%" +

"\nDiscount Amount: INR " + discount +

"\nFinal Amount to Pay: INR " + finalAmount

);

scanner.close();

Input:
Output: The discount amount is INR and final discounted fee is INR

1. 7) Write a Program to compute the volume of Earth in km^3 and miles^3

import java.util.Scanner;

public class EarthVolumeCalculator {

public static void main(String[] args) {

Scanner scanner = new Scanner(System.in)

System.out.print("Enter the radius of Earth (in km): ");

double radiusKm = scanner.nextDouble();

double kmToMiles = 0.621371;

double volumeKm3 = (4.0 / 3) * Math.PI * Math.pow(radiusKm, 3);

double radiusMiles = radiusKm * kmToMiles;

double volumeMiles3 = (4.0 / 3) * Math.PI * Math.pow(radiusMiles, 3);

System.out.println(

"\nRadius of Earth: " + radiusKm + " km" +

"\nVolume of Earth in cubic kilometers: " + volumeKm3 + " km³" +

"\nVolume of Earth in cubic miles: " + volumeMiles3 + " mi³"

);

scanner.close();

}
}

Input:

Output: The volume of earth in cubic kilometers is and cubic miles is


1. 8) Create a program to convert distance in kilometers to miles.

import java.util.Scanner;

public class KilometerToMilesConverter {

public static void main(String[] args) {

Scanner input = new Scanner(System.in);

System.out.print("Enter the distance in kilometers: ");

double km = input.nextDouble();

double miles = km / 1.6;

System.out.println(km + " kilometers is equal to " + miles + " miles.");

input.close();

}
}

Input:km

Output: The total miles is mile for the given km

1. 9) Write a new program similar to the program # 6 but take user input for Student Fee and
University Discount

import java.util.Scanner;

public class UniversityFeeCalculator {

public static void main(String[] args) {

Scanner scanner = new Scanner(System.in);

System.out.print("Enter the course fee (INR): ");

double fee = scanner.nextDouble();


System.out.print("Enter the discount percentage: ");

double discountPercent = scanner.nextDouble();

double discount = (fee * discountPercent) / 100;

double finalAmount = fee - discount;

System.out.println(

"\nOriginal Course Fee: INR " + fee +

"\nDiscount Percentage: " + discountPercent + "%" +

"\nDiscount Amount: INR " + discount +

"\nFinal Amount to Pay: INR " + finalAmount

);

scanner.close();

}
}

Input: fee, discountPrecent

Output: The discount amount is INR and final discounted fee is INR

10) Write a program that takes your height in centimeters and converts it into feet and inches

import java.util.Scanner;

public class HeightConverter {

public static void main(String[] args) {

Scanner scanner = new Scanner(System.in);

System.out.print("Enter your height in centimeters: ");


double heightCm = scanner.nextDouble();

double cmPerInch = 2.54;

double inchesPerFoot = 12;

double totalInches = heightCm / cmPerInch;

int feet = (int) (totalInches / inchesPerFoot);

double inches = totalInches % inchesPerFoot;

System.out.println("\nYour height is: " + feet + " feet " + inches + " inches.");

scanner.close();

}
}

Input: height

Output: Your Height in cm is while in feet is and inches is

You might also like