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]();
}
}