Implement A Class Calculator That Models Handheld Calculator. It Should Have (Atleast) The Following Functionality
Implement A Class Calculator That Models Handheld Calculator. It Should Have (Atleast) The Following Functionality
Implement A Class Calculator That Models Handheld Calculator. It Should Have (Atleast) The Following Functionality
Class Calculator
Public void Calculator ( double n1, double n2, char chr )
double result = 0.0;
System.out.println(First Number = “ +n1);
System.out.println(“Second Number = “ =n2);
Switch(chr)
Case ‘+’ : result = n1 + n2;
System.out.println(“Addition of number is = “+result);
break;
Case ‘-‘ : result = n1 - n2 ;
System.out.print (“Subtraction of Number is =” + result) ;
break;
Case ‘*’ : result = n1 * n2 ;
System.out.print(“Multiplicatioin of number is =” =result) ;
break;
Case ‘/’ : result = n1 / n2 ;
System.out.print(“Result of Division is =” +result) ;
break;
Case’%’ : result = n1 % n2 ;
System.out.print(“Result of Modulus Operator is =” +result) ;
break;
default: System.out.print(“Operator Selected is Wrong”);
Class switchCase
Public void main(int num )
Int reverse = 0, remainder ;
While(num > 0 )
remainder = num % 10;
reverse = reverse * 10 + remainder;
num = num / 10 ;
String result = “ “ ;
While(reverse > 0 )
remainder = reverse % 10;
reverse = reverse / 10;
switch(remainder )
case 0 :
result = result + “ Zero “;
break;
case 1 :
result = result + “ One “ ;
break;
case 2:
result = result + “ Two “ ;
break;
case 3 :
result = result + “ Three “ ;
break;
case 4 :
result = result + “ Four “ ;
break;
case 5:
result = result + “ Five “ ;
break;
case 6:
result = result + “ Six “ ;
break;
case 7 :
result = result + “ Seven “ ;
break;
case 8 :
result = result + “ Eight “ ;
break;
case 9:
result = result + “ Nine “ ;
break;
default:
result = “ “ ;
System.out.print(result) ;
3. A cloth showroom has announced the following festival discounts on the purchase items,
based on the total cost of the items purchased :
Total Cost Discount (in percentage)
Less than 2000 5%
2001 to 5000 25%
5001 to 10000 35%
Above 10000 50%
Write a program to input the total cost and display the amount to be paid by the customer
availing the discount.
Answer. Class Amount
Public void main (double cost)
System.out.println(“Amount of purchase : “ +cost);
double discountRate, discountAmt, finalAmt;
discountRate = 2.0;
if (( cost > 2000) && (cost < = 10000))
discountRate = 25.0;
else if ((cost > 5000) && (cost <= 10000))
discountRate = 35.0;
else
discountRate = 50.0;
discountRate = cost * discountRate / 100.0;
finalAmt = cost * discontAmt;
// display the results
System.out.println(“Total cost : “+cost);
System.out.println(“Discount % : “ +discountRate);
System.out.println(“Discount Amt. : “ +discountAmt);
System.out.println(“Final Price : “ +finalAmt);
}
}
5. Write a program which finds whether a given year is a leap year or not.
If (year% 100==0) {
If(year% 400==0) {
else {
Else {
If (year %4==0) {
Else{
6. An electronics shop has announced the following seasonal discounts on the purchase of certain items:
Class laptop PC {
Double p, d, net;
Name= input.readLine();
Address=input.readLine ();
Char choice;
Choice= (char) System.in.read();
Switch (choice) {
D=0;
Net=p-d;
System.out.Println(“Amount to be paid”+net);
d =(5.0/100)*p;
net=p-d;
d = (7.5/100) * p;
net = p-d;
d =(10.0/100) * p;
net = p-d;
Break;
d = (5.0/100) * p;
net = p-d;
}
Else if (p> 25000&& p < = 57000) {
d = (7.5/100) * p;
net = p-d;
Net =p-d;
System.out.println(“Amount to be paid”+net);
d = (15.0/100) * p;
net= p-d;
break;