1.

A class SwapSort has been defined to perform string related operations on a word input. Some of the members of the class are as follows: Class name: SwapSort Data members/instance variables: wrd: to store a word len: integer to store the length of the word swapwrd: to store the swapped word sortwrd: to store the sorted word Member functions/methods: SwapSort(): default constructor to initialize data members with legal initial values void readword(): to accept a word in UPPER CASE void swapchar(): to interchange/swap the first and last characters of the word in ‘wrd’ and stores the new word in ‘swapwrd’ void sortword(): sorts the characters of the original word in alphabetical order and stores it in ‘sortwrd’ void display(): displays the original word, swapped word and the sorted word Specify the class SwapSort, giving the details of the constructor(), void readword(), void swapchar(), void sortword() and void display(). Define the main() function to create an object and call the functions accordingly to enable the task.

Answer»

import java.io.*; 

class Product 

String name; 

int code; 

double amount; 

Product(String n, int c, double p) { 

name = n; 

code = c; 

amount = p; 

void show() { 

System.out.println("Name is :"+ name); 

System.out.println("Code is :" + code); 

System.out.println("Total Sale Amount:" + amount); 

class Sales extends Product { 

int day; 

double tax; 

double totamt; 

double fine = 0.0; 

Sales(String n, int c, double p, int d) { 

super(n, c, p); 

day = d; 

void compute() 

if(day < 30){ tax = 12.4 * amount /100; totamt = amount + tax; 

if(day > 30) { 

tax= 12.4 * amount /100; 

fine = 2.5 * amount /100; 

totamt = amount + tax + fine; 

} void show () { 

show(); 

System.out.println("Total amount to be paid::"+ totamt); 

}



Discussion

No Comment Found

Related InterviewSolutions