Java Programs for Interest, Tax, and More
Java Programs for Interest, Tax, and More
pow( 1+(rate/number),
interest of a given principle, rate and { number*time);
time. [Link]("Price is double area(float
public class Main 1500.00 Rupees"); x) cinterest = amount - principle; [Link]("Sum of 3x3
{ { [Link]("Compound matrices\n");
public static void main (String args[]) return interest = "+ cinterest);
{ float p, r, t, si; price=0.04*1500.00+1500.00; x*x; [Link]("Total amount =
p = 13000; r = 12; t = 2; } "+ amount); for(i=0;i<m;i++)
si = (p*r*t)/100; double area(float } {
[Link]("Simple Interest is: " x, float y) }
+si); [Link]("After { Write a program to find sum
}} adding sales tax, Price return of two matrices of 3x3.
A car accessories shop assigns code 1 is:"+price); x*y; for(j=0;j<n;j++)
break; import [Link];
to seat covers, 2 to steering wheel } class AddMatrix
covers, 3 to car lighting and 4 to air } {
purifiers. All other items have code 5 or case 4: class Area public static void
more. While selling goods, a sales tax of { main(String args[])
2% to seat covers, 3% to steering wheel public static void { [Link](sum[i][j]+"\t");
covers, 4% to car lighting, 2.5% to air [Link]("Air main(String args[]) int
purifiers and 1.2% to other items is Purifiers"); { m=3,n=3,i,j;
charged. A list containing the product int
code and price is given for making a bill. x,y; [Link]();
Write a java program using switch [Link]("Price is Scanner in=new }
statements to prepare a bill. 2000.00 Rupees"); Scanner([Link]); }
import [Link].*; int }
public class car { x=[Link](args[0]); matrix1[][]=new int[m][n]; Write an interface called
public static void main (String int numbers, with a method int
[] args) price=0.025*2000.00+2000.00;
matrix2[][]=new int[m][n]; Process(int x,int y). Write a
{ int class called Sum, in which
Scanner pc= new y=[Link](args[1]); sum[][]=new int[m][n]; the method Process finds
Scanner([Link]); [Link]("After Overl the sum of two numbers and
[Link]("Enter the adding sales tax, Price oad obj=new returns an int value. Write
product code"); is:"+price); Overload(); another class called
int code= [Link](); break; Average, in which the
default : [Link]("Enter
elements for first 3x3 matrix\ Process method finds the
n"); average of the two numbers
double price; [Link]("Area of and returns an int.
switch(code) { [Link]("Other"); Square is: "+[Link](x)); interface numbers
case 1 : Syste {
for(i=0;i<m;i++) public int
[Link]("Are {
[Link]("Price is a of Rectangle is: Process(int x,int y);
[Link]("Seat 1200.00 Rupees"); "+[Link](x,y)); }
covers"); } } class Sum implements
for(j=0;j<n;j++) numbers
price=0.012*1200.00+1200.00; {
Write a program to display public int
[Link]("Price is powers of 2 i.e. 2, 4, 8, 16
1000.00 Rupees"); Process(int x,int y)
etc. up to 1024 using Shift matrix1[i] {
[Link]("After operator. [j]=[Link](); return
adding sales tax, Price class power } x+y;
price=0.02*1000.00+1000.00; is:"+price); { }
public static void }
} main(String args[]) class Average implements
[Link]("After } { numbers
adding sales tax, Price int [Link]("Enter
elements for second 3x3 {
is:"+price); a=1; public int
Write a program to scan 3 for(int matrix\n");
break; integer values from Process(int x, int y)
i=1;i<=10);i++) {
command line arguments {
case 2: and display the maximum return
using conditional operator. for(i=0;i<m;i++) (x+y)/2;
a=a<<1; { }
public class Max
[Link]("Steering { }
wheel covers"); public static void main (String class Interface
args[]) [Link](a); for(j=0;j<n;j++) {
{ } public static void
int a, b, c, max; } } main(String args[])
[Link]("Price is A bank gives 6.5% per {
500.00 Rupees"); annum interest on deposits int
matrix2[i]
made in that bank. Write a [j]=[Link](); a,b;
a=[Link](args[0]); program to calculate the Sum
b=[Link] }
price=0.02*500.00+500.00; total amount that a person add=new Sum();
(args[1]); will receive after the end of 5
c=[Link] years for a deposit of Rs.
(args[2]); 5000 for compound interest. for(i=0;i<m;i++)
[Link]("After max= (a > b) ? (a {
adding sales tax, Price > c ? a : c) : (b > c ? b : c); public class CI a=[Link](10,20);
is:"+price); {
break; public static void main(String[] args) {
for(j=0;j<n;j++)
[Link](“Maximum double principle = 5000, rate = 6.5,
case 3: is”+max); [Link]("Sum is=\
}} time = 5; t"+a);
int number = 1; sum[i]
Write a program to calculate double amount,cinterest; [j]=matrix1[i][j]+matrix2[i][j];
[Link]("Car the area of square and }
lighting"); amount = principal * Average avg=new
rectangle by overloading
area method. Average();
class Cabbage extends lowercase
Vegetable characters in it.
{
b=[Link](10,20); public String [Link](p); class cmd [Link](args[0]+" is
toString() { not palindrome");
{ public static void
main(String args[])
[Link]("Average [Link](b); {
is=\t"+b); color="Green } char [Link]("\n4. Total
} color"; } c[]=args[0].toCharArray(); number of uppercase and
} return int i; lowercase characters in it");
"Cabbage=>" +color; int
} Create package pack1 within
Declare an abstract class this package create class A upper=0,lower=0;
}
Vehicle with an abstract class Carrot extends which contains one instance
method named numWheels() variable and one instance [Link]("\n1.
Vegetable Display each character on
provide subclasses Car and { method. Create another
Truck that each implements package pack2 within this separate line in reverse for(i=0;i<[Link];i++)
public String order");
this method. Create instance toString() package create class B {
of these subclasses and { where class B is calling the
demonstrate the use of this method and variable of class
method. A. for(i=[Link]-
1;i>=0;i--) if([Link](c[i]))
abstract class Vehicle color="Red color";
return package pack1;
{ public class A
public abstract "Carrot=>" +color;
} {
void numWheels(); public int a=10; [Link](c[i]); upper++;
} }
class Potato extends public void
class Car extends Vehicle printA()
{ Vegetable
{ { else
public void [Link]("\n2. Count
numWheels() public String
toString() total no. of characters and
{ display each character's
{
[Link]("Package position too"); lower++;
pack1, class A and method }
color="Brown printA");
[Link]("Car has 4 }
wheels"); color";
return } [Link]("\nTotal
} number of characters are
} "Potato=>" +color; [Link]("\nNo. of
} package pack2; "+[Link]); uppercase characters=
class Truck extends Vehicle import pack1.*;
{ } "+upper);
public void class Brinjal extends class B
numWheels() Vegetable {
{ { public static void for(i=0;i<[Link];i++)
public String main(String args[])
toString() { [Link]("\nNo. of
{ A lowercase characters=
a1=new A(); "+lower);
[Link]("Truck has [Link](c[i]+" }
6 wheels"); character is at "+i+" position"); }
} color="Purple
} color";
return [Link]("Instance Write a program that takes a
class Demo Variable "+a1.a); string from the user and
{ "Brinjal=>" +color; [Link]("\n3.
} validate it. The string should
public static void Identify the string is be at least 5 characters and
main(String args[]) } palindrome or not");
class Col should contain at least one
{ String digit. Display an appropriate
Car { [Link]("Instance s1=args[0];
public static void method calling"); valid message.
c=new Car();
main(String args[])
{ class Val
StringBuffer {
[Link](); [Link](); buffer=new StringBuffer(s1);
} public static void
Truck main(String args[])
t=new Truck(); Cabbage c=new }
Cabbage(); Write a program that accepts {
[Link](); String
a String from command line String s=args[0];
[Link](); and perform the following s2=[Link](); char
} Carrot ca=new operations: c[]=[Link]();
} Carrot(); o Display each int
The abstract Vegetable class character on flag=0,i;
has four subclasses named separate line in
reverse order [Link]([Link](s
Cabbage, Carrot, Brinjal and Potato p=new 2));
Potato. Declare one instance Potato(); o Count total
number of if([Link]()>=5)
variable of type string that {
indicates the color of characters and
vegetable. Create and Brinjal b=new display each
display instances of these Brinjal(); character’s
object. Override the position too. if([Link](s2))
toString() method of object o Identify that for(i=0;i<[Link]();i++)
to return a string with the whether the
name of the vegetable and string is
[Link](c); palindrome or {
its color. [Link](args[0]+" is
abstract class Vegetable not palindrome");
{ o Count total else
public String color; number of
} [Link](ca); uppercase and
Exception: unit is not valid
if([Link](c[i])) "+s); public class oddeventhread
} {
} [Link]("Number public static void
{ class Convert Format Exception occur"); a[i]=[Link](args[i]); main(String args[])
{ } {
public static void String
main(String args[]) if((a[i] s=args[0];
flag=1; { %2)!=0)
int catch(ArithmeticException e)
no; Runnable r1=new
String {
unit; { oddthread(s);
try
[Link]("\nString is {
valid"); [Link]("Arithemtic Thread t1=new
Exception occur"); count++; Thread(r1);
}
no=[Link](args[0]);
break; Runnable r2=new
throw new eventhread(s);
unit=args[1]; catch(ArrayIndexOutOfBounds OddException(a[i]);
} Exception e)
{ Thread t2=new
} Thread(r2);
} if(([Link]("centimeter")) ||
([Link]("cm"))) [Link]("Array } [Link]();
if(flag==0) Index Out Of Bounds
Exception occur");
{ } [Link]();
catch(ArithmeticException e) try
int {
[Link]("String is catch(Exception
m=no/100; e)
not valid\nIt should contain at { {
least 1 digit."); [Link]();
}
else
[Link]("Equivalent [Link]("Exception [Link]();
of "+args[0]+""+args[1]+" in "+[Link]()); [Link]("Arithemtic }
meters is "+m+" meters"); } Exception occur");
[Link]("String is }
not valid\nIt should be at least }
5 characters."); } } catch(InterruptedException e)
} Write a program that accepts {
} 5 even numbers from
else command line, if any of the catch(Exception
Write an application that if(([Link]("meters")) || numbers is odd then throw e)
converts between meters ([Link]("m"))) custom exception [Link](e);
and feet. Its first command- OddException and count }
line argument is a number such invalid numbers.
and second command line {
argument is either {
“centimetre” or”meter”. If class OddException extends
Exception [Link]("End of
the argument equals { Main Thread: Both threads
“centimetre” displays a int completed");
string reporting the cm=no*100; OddException(int [Link]("Exception:
n) }
equivalent number of { no. should be even"); }
meters. If this argument class oddthread implements
equals “meters”, display a Runnable
string reporting the } {
equivalent number of [Link]("Equivalent } int n;
centimetre. If unit is not of "+args[0]+""+args[1]+"in [Link](n+" is
Odd"); oddthread(String
given properly then generate centimeters is "+cm+" s)
custom exception centimeters"); }
} {
Unitformatexception. If first [Link]("Invalid
argument is not proper class Even
{ numbers= "+count);
format then generate } }
numberformatexception. public static void
main(String args[]) } n=[Link](s);
Generate other exception as
per requirements. (1 { }
meter=100 centimetre) else int Write an application that public void run()
a[]=new int[5]; starts two threads. First {
int thread displays even for(int
class UnitformatException count=0; numbers in the range i=0;i<=n;i++)
extends Exception throw
new UnitformatException(unit); for(int specified from the command {
{ i=0;i<5;i++) line and second thread
}
{ displays odd numbers in the
same range. Each thread try
UnitformatException(String s) waits for 300 milliseconds
{ try before displaying the next
catch(NumberFormatExceptio
n e) numbers. The application {
{ waits for both the thread to
{ finish and then displays the
[Link]("Unitformat message “Both threads
completed”.
if(i
%2==1) [Link](60,10,60,110);
{}
}
{ }
} [Link](10,60,110,60);
[Link](100,350,350,350); [Link](100,120,300,120);
n=[Link](s);
}
public void run() [Link]("Line",175,370);
{ [Link](100,140,300,140);
for(int
i=0;i<=n;i++)
{
[Link](160,200,100,100); [Link](100,160,300,160);
try
[Link]("Filled [Link](100,180,300,180);
{ Circle",160,330);
[Link](10,10,100,100);
catch(InterruptedException e)