0% found this document useful (0 votes)
5 views6 pages

Java Prac File

The document outlines two Java programs: the first takes command line arguments for user information (name, university roll number, course, and semester) and displays them, while the second is a menu-driven program that calculates the maturity amount of bank deposits based on user-selected options for term or recurring deposits. The maturity amounts are calculated using specific formulas, and appropriate error messages are displayed for invalid inputs. Both programs utilize the Scanner class for user input.

Uploaded by

divya3338g
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)
5 views6 pages

Java Prac File

The document outlines two Java programs: the first takes command line arguments for user information (name, university roll number, course, and semester) and displays them, while the second is a menu-driven program that calculates the maturity amount of bank deposits based on user-selected options for term or recurring deposits. The maturity amounts are calculated using specific formulas, and appropriate error messages are displayed for invalid inputs. Both programs utilize the Scanner class for user input.

Uploaded by

divya3338g
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

PROGRAM OBJECTIVE : Write a java program to take

input as a command line argument. Your name, course,


university roll no. and semester. Display the
information.
Name:
UniversityRollNo:
Course:
Semester:

PROGRAM CODE:
public class DisplayInfo {
public static void main(String[] args) {
if ([Link] != 4) {
[Link]("Usage: java DisplayInfo <Name>
<UniversityRollNo> <Course> <Semester>");
return;
}
String name = args[0];
String universityRollNo = args[1];
String course = args[2];
String semester = args[3];
[Link]("Name: " + name);
[Link]("UniversityRollNo: " + universityRollNo);
[Link]("Course: " + course);
[Link]("Semester: " + semester);
}
}
PROGRAM OBJECTIVE : Using the switch statement,
write a menu-driven program to calculate the maturity
amount of a bank deposit.
The user is
(i) Term Deposit
(ii) Recurring Deposit
For option (i) accept Principal (p), rate of interest (r)
and time period in years (n). Calculate and output the
maturity amount (a) receivable using the formula a =
p[1 + r / 100]n.
For option (ii) accept monthly installment (p), rate of
interest (r) and time period in months (n). Calculate
and
output the maturity amount (a) receivable using the
formula a = p * n + p * n(n + 1) / 2 * r / 100 * 1 / 12.
For an incorrect option, an appropriate error message
should be displayed.
[ Use Scanner Class to take input]
PROGRAM CODE: Import [Link];
public class BankDepositCalculator {

public static void main(String[] args) {

Scanner scanner = new Scanner([Link]);

[Link]("Select an option:");
[Link]("(i) Term Deposit");
[Link]("(ii) Recurring Deposit");
[Link]("Enter your choice (i/ii): ");
String choice = [Link]();

switch (choice) {
case "i":
[Link]("Enter Principal (P): ");
double principal = [Link]();

[Link]("Enter Rate of Interest (R in %):


");
double rateOfInterest = [Link]();

[Link]("Enter Time Period (N in years):


");
int timeInYears = [Link]();
double termMaturityAmount = principal *
[Link](1 + rateOfInterest / 100, timeInYears);
[Link]("Maturity Amount (A): %.2f%n",
termMaturityAmount);
break;
case "ii":
[Link]("Enter Monthly Installment (P): ");
double installment = [Link]();
[Link]("Enter Rate of Interest (R in %): ");
double recurringRate = [Link]();
[Link]("Enter Time Period (N in months): ");
int timeInMonths = [Link]();
double recurringMaturityAmount = installment *
timeInMonths + installment * timeInMonths *
(timeInMonths + 1) / 2 * recurringRate / 100 * 1 / 12;
[Link]("Maturity Amount (A): %.2f
%n", recurringMaturityAmount);
break;
default:
[Link]("Invalid option! Please select
either (i) or (ii).");
}
[Link]();
}
}

You might also like