0% found this document useful (0 votes)
22 views34 pages

Shaurya

Uploaded by

shubharora101
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
22 views34 pages

Shaurya

Uploaded by

shubharora101
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 34

COMPUTER PROJECT

Name : Shaurya Gupta


Class : X-B
Roll Number : 37
School : St. Lawrence School
Session : 2024-2025
Submi ed to : Sir Noor Islam Khan
Submi ed on : 21/10/2024
TABLE OF CONTENTS

Sr. No. Programs Page No.


1. Superspy Number. 05

2. Duck Number. 06

3. Menu Driven Program. 07-08

4. Special Armstrong Numbers between 500 -2000. 09

5. Func on Overloading (Series). 10

6. Func on Overloading (String). 11-12

7. Menu Driven Program (Pa ern). 13-14

8. To input a sentence and display the word with 15


maximum characters.
9. To accept a string and display the new converted 16
string.
10. To find and print the frequency of a given word in a 17
sentence.
11. To display the words of a given string which begins and 18
ends with the same character.
12. Sor ng (Ascending order) of a one -dimensional array 19
(Bubble Sort Technique).
13. Sor ng (Descending order) of a one -dimensional array 20-21
(Selec on Sort Technique).
14. To search for an integer value in a sorted array list 22-23
(Binary Search Technique).
15. To find and display the sum of each row in a 4x4 array. 24
16. To search for a name in a declared array (Linear Search 25-26
Technique).
17. Special Array. 27

18. To display the largest and the smallest value in a 4x4 28-29
array.
19. To define a class Stock along with some specifica ons. 30-31

20. To define a class SmartShop along with some 32-33


specifica ons.
ACKNOWLEDGEMENT

~ I would like to take this opportunity to express my hear elt apprecia on to


everyone who contributed to the successful comple on of my computer
project. This project has been a significant learning experience for me, and I
am grateful for the support and guidance I have received along the way.
~ First and foremost, I want to extend my sincere thanks to my Computer
Teacher, Mr. Noor Islam Khan. Your exper se, encouragement, and willingness
to answer my ques ons have been invaluable throughout this project. Your
dedica on to teaching and your passion for the subject have inspired me to
delve deeper into the world of computer science.
~ I would also like to acknowledge the role of our school principal, Fr. Olwin
J.Moras. Your leadership and vision have created an educa onal environment
that encourages students to pursue their interests and excel in their chosen
fields. Your support for our endeavours has been a driving force behind our
success.
~ While this project was an individual effort, the collec ve support of my
teacher and principal, along with the encouragement from my loved ones, has
made it possible. I am grateful to each and every one of you for being a part of
my journey and for helping me achieve this milestone.

Thank you.
[SHAURYA GUPTA]
COMPUTER PROGRAMS

Ques on 1: Define a class to accept a number and check whether it is a


SUPERSPY number or not.
(A number is called SUPERSPY if the sum of the digits equals the number of the digits.)

import java.u l.*; public class Superspy{


public sta c void main(String args[]){
Scanner sc=new Scanner(System.in);
System.out.println("Enter a number");
int n=sc.nextInt();
int c=n,s=0,r,a=0;
while(n>0)
{
n=n/10;
a++;
}
while(c>0)
{
r=c%10;
s=s+r;
c=c/10; }
//While ends
if(s==a)
System.out.println("SUPERSPY Number"+" "+"[Sum of the digits="+s+", Number of
digits="+a+"]");
else
System.out.println("Not an SUPERSPY Number"+" "+"[Sum of the digits="+s+", Number
of digits="+a+"]"); } //Main ends
} //Class ends

Variable Descrip ons


int n To store the number entered by the user
int c to store the copy of n
int s to find and store the sum
int r To extract and store the digit from the number
entered
int a to count and store the number of digits
Ques on 2: Define a class to accept a 3-digit number and check whether it is a
Duck Number or not.
Note: A number is a Duck number if it has zero in it.

import java.u l.*;


public class DuckNmber
{
public sta c void main(String args[])
{
Scanner sc=new Scanner(System.in);
System.out.println("Enter a 3 digit
Number"); int n=sc.nextInt(); int r=0;
if(n>=100&&n<=999)
{
while(n>0)
{
r=n%10;
if(r==0)
break;
n=n/10; }
//While ends
if(r==0)
System.out.println("Duck number");
else
System.out.println("Not a Duck number");
} //If ends
else
System.out.println("Invalid");
} //Main ends
}//Class ends

Variable Descrip ons


int n To store the number entered by the user
int r To extract the last digit from the number
entered
Ques on 3: Write a menu driven class (using switch case) to perform the
following:
(i) Input a Binary number (base 2) and convert it into its Decimal equivalent (base 10)
(ii) Input a Decimal number (base 10) and convert it into its Binary equivalent (base 2)

import java.u l.Scanner;


public class Conversion
{
public sta c void main(String args[])
{
Scanner sc=new Scanner(System.in);
System.out.println("Enter 1 for Binary to Decimal Conversion");
System.out.println("Enter 2 for Decimal to Binary Conversion");
int ch=sc.nextInt();
switch(ch)
{
case 1:
{
System.out.println("Enter the number");
int n1=sc.nextInt();
int p=0,c=0,r;
while(n1>0)
{
r=n1%10;
c=c+r*(int)Math.pow(2,p);
p++;
n1=n1/10;
}
System.out.println("The Converted number is: "+c);
}
break;
case 2:
{
System.out.println("Enter the number");
int n2=sc.nextInt();
int p;
String s=" ";
while(n2>0)
{
p=n2%2;
s=String.valueOf(p)+s;
n2=n2/2;
}
System.out.println("The Converted number is: "+s);
}
break;
default:
System.out.println("Invalid choice");
}//Switch ends
}//Main ends
}//Class ends

Variable Descrip ons


int ch To store the choice entered by the user
int n1 To store the number entered by the user
int p It is the power
int c To convert the number in the asked form and store it
int d To extract and store the last digit from the number
int n2 To store the number entered by the user
int p To calculate and store the remainder of the number ,divided by 2
int s To convert the number in the asked form and store it
Ques on 4: Write a program to generate and print all the Special Armstrong
numbers from 500 and 2000.
Note: A number is said to be special Armstrong number if sum of its digits raised to the
power of length of the number is equal to the number.

public class Spl_Armstrong


{
public sta c void main(String args[])
{
for(int i=500;i<=2000;i++)
{
int c=i,d=i,s=0,a=0,r,;
while(n>0)
{
d=d/10;
a++;
}
while(c>0)
{
r=c%10;
s=s+(int)Math.pow(r,a);
c=c/10;
}
if(s==i)
System.out.println(i);
}//For ends
}Main ends
}//Class ends

Variable Descrip ons


int i To work out the loop
int c To store the copy of the number
int d To store another copy of the number
int s To calculate and find the sum
int a To count the number of digits
int r To extract the last digit from the number
Ques on 5: Design a class to overload a func on sumseries() as follows:
(1) void sumseries(int n , double x) - with one integer argument and one double
argument to find and display the sum of the series given below:
S𝑢𝑚=1/𝑥2 − 4/𝑥5 + 7/𝑥8− 10/𝑥11+ ⋯𝑛/𝑥n
(2) void sumseries(int start, int end)- to calculate the sum of all prime numbers in the
range between start and end.

public class overload


{
void sumseries(int n,double x)
{
double sum=0.0;int s=1;
for(int
i=1,a=2;i<=n;i=i+3,a=a+3)
{
sum=sum+i/Math.pow(x,a)*s;
s=s*(-1);
}
System.out.println(sum);
}
void sumseries (int start,int end)
{
int s=0;
for(int i=start;i<=end;i++)
{
int c=0;
for(int j=1;j<i;j++)
{
if(i%j==0)
c++;
}
if(c==1)
{
s=s+i;
System.out.println(s);
}
}
}
}//Class ends
Variable Descrip ons
double sum To calculate and store the sum of the series
int s To change the sign
int s To calculate and store the sum
int c Used as a check mark
int i To workout the loop
Ques on 6: Design a class to overload a func on joystring() as follows:

(1) void joystring(String s)- with one string argument in lowercase, change the first
le er of every word to uppercase. Display the new string.
Sample Input: cloud compu ng means internet based compu ng
Output: Cloud Compu ng Means Internet Based Compu ng

(2) void joystring(String str, int p)- with one string argument and one integer argument.
It displays all the uppercase character if p is 1(one) otherwise it displays all the lowercase
characters.

public class JoyString


{
public void joystring(String s)
{
String r="";
boolean cond=true;
for(int i=0;i<s.length();i++)
{
char c=s.charAt(i);
if (c==' ')
{
r+=c;
cond=true;
}
else if(cond)
{
r+=Character.toUpperCase(c);
cond=false;
}
else
{
r+=c;
}
}
System.out.println(r);
}
public void joystring(String str,int p)
{
String r="";
if(p==1)
{
for(int i=0;i<str.length();i++)
{
char c=str.charAt(i);
if(Character.isUpperCase(c))
{
r+=c;
}
}
}
else
{
for(int i=0;i<str.length();i++)
{
char c=str.charAt(i);
if(Character.isLowerCase(c))
{
r+=c;
}
}
}
System.out.println(r);
}//Main ends
}//Class ends

Variable Descrip ons


String r To store a string
boolean cond To check if the condi on is true or false
int i To workout the loop
char c To store and check the character from the string entered
String r To store a string
char c To store and check the character from the string entered
int i To workout the another loop
char c To store and check the character from the string entered
Ques on 7: Write a menu driven program to print the given pa ern according
to the user’s choice.

(i) 1 (ii) A B C D E
* * ABCD
23 ABC
* ** AB
456 A

import java.u l.*;


public class my_program
{
public sta c void main(String args[])
{
Scanner sc=new Scanner(System.in);
System.out.println("Enter 1 for Numerical Pa ern");
System.out.println("Enter 2 for Alphabe cal Pa ern");
System.out.println("Enter your choice");
int ch=sc.nextInt();
switch(ch)
{
case 1:
{ int
k=1;
for(int i=1;i<=5;i++)
{
if(i%2==1)
{
for(int j=1;j<=(i+1)/2;j++)
{
System.out.print(k+"");
k++;
}
}
else
{
for(int j=1;j<=(i+2)/2;j++)
{
System.out.print("*"+ "");
}
}
System.out.println();
}
}
break;
case 2:
{
for(int i=69;i>=65;i--)
{
for(int j=65;j<=i;j++)
{
System.out.print((char)j+"");
}
System.out.println();
}
}
break;
default:
System.out.println("Invalid choice");
}//Switch ends
}//Main ends
}//Class ends

Variable Descrip ons


int ch To ask the choice from the user
int i To workout the outer loop
int j To workout the inner loop
int k To print the pa ern
int i To workout the outer loop
int j To workout the inner loop
Ques on 8: Write a program to input a sentence and display the word in the
sentence that contains the maximum number of characters.
Input: Enter the sentence: Best of Luck for your Examina on
Output: The word with the maximum characters is: Examina on

import java.u l.Scanner;


public class Mnc
{
public sta c void main(String args[])
{
Scanner sc=new Scanner(System.in);
System.out.println("Enter the Sentence:");
String s=sc.nextLine();
String[]w=s.split(" ");
String l=" ";
int f=0;
for(int i=0;i<w.length;i++)
{
if(w[i].length()>f)
{
f=w[i].length();
l=w[i];
}
}
System.out.println("The word that contains the maximum number of characters is: " +l);
}//Main ends
}//Class ends

Variable Descrip ons


String s To store the string entered by the user
String[ ]w To split the whole string and store the par cular string
String l To store the final resulted string
int f To check and store the length of the string
int i To workout the loop
Ques on 9: Define a class to accept a string and convert the same to
uppercase, create and display the new string by replacing each vowel by
immediate next character and every consonant by the previous character. The
other characters remain the same.
Input: Enter the sentence: $EXAMINATION_2025
Output: $FWBLJMBSPM_2025

import java.u l.Scanner;


public class acc
{
public sta c void main(String args[])
{
Scanner sc=new Scanner(System.in);
System.out.print("Enter a String(Sentence): ");
String str=sc.nextLine();
String con="";
for(int i=0;i<str.length();i++)
{
char c=Character.toUpperCase(str.charAt(i));
if(c=='A'||c=='E'||c=='I'||c=='O'||c=='U')
{
con+=(char)(c+1);
}
else if(Character.isLe er(c))
{
con+=(char)(c-1);
}
else
{
con+=c;
}
} System.out.println("The Transformed String is: " +con);
}//Main ends }//Class ends
Variable
Descrip ons
String str To store the string entered by the user
String con To store the final resul ng string
char c To store and check the character of the string
int i To workout the loop
Ques on 10: Write a program in Java to accept a sentence and a word
separately. Find and print the frequency of the given word in the sentence:
Input: Taj Mahal is one of the seven wonders of the words.
Frequency of the word to be searched: the
Output: The frequency of the word the is: 2

import java.u l.Scanner;


public class frequency
{
public sta c void main(String args[])
{
Scanner sc=new Scanner(System.in);
System.out.print("Enter a sentence:");
String str=sc.nextLine();
System.out.print("Enter the word whose frequency is to be searched:");
String w=sc.nextLine();
String word[]=str.split(" ");
int f=0;
for(int i=0;i<word.length;i++)
{
if(word[i].equals(w))
{
f++;
}
}
System.out.println("The frequency of the word "+w+" is: "+f);
}//Main ends
}//Class ends

Variable Descrip ons


String str To store the string entered by the user
String w To store the word entered by the user whose frequency is to be searched
String word To store the main string and store its cons tuent words
int f To store the frequency
int i To workout the loop
Ques on 11: Write a program to input a sentence in uppercase. Display the
words which begin and ends with a same character.
Sample Input: Enter the sentence: Stars shine bright at night some mes
Output: Stars, some mes

import java.u l.Scanner;


public class SameCharacterWords
{
public sta c void main(String[] args)
{
Scanner sc=new Scanner(System.in);
System.out.println("Enter a sentence:");
String s=sc.nextLine();
s=s+" ";
s=s.toUpperCase();
String w=""; int
l=s.length(); char c;
for(int i=0;i<l;i++)
{
c=s.charAt(i);
if(c!=' ')
{
w+=c;
}
else
{
if(w.charAt(0)==w.charAt(w.length()-1))
{
System.out.print(w+ " ");
}
w=""; } }
}//Main ends
}//Class ends

Variable Descrip ons


String s To store the string entered by the user
String w To store the final resul ng string
int l To store the length of the string
char c To store the character of the string
int i To workout the loop
Ques on 12: Define a class to accept the names of 20 students in a one-
dimensional array. Sort the names in ascending order using the Bubble sort
technique, and display the students' names in sorted order.
import java.u l.Scanner;
public class Sort
{
public sta c void main(String[] args) {
Scanner sc=new Scanner(System.in);
String names[]=new String[20];
System.out.println("Enter the names of 20 students:");
for (int i=0;i<20;i++)
{
names[i]=sc.nextLine();
}
for(int i=0;i<names.length-1;i++)
{
for(int j=0;j<names.length-1- i;j++)
{
if(names[j].compareTo(names[j + 1])>0)
{
String sort=names[j];
names[j]=names[j+1];
names[j+1]=sort;
}
}
}
System.out.println("Names of students in ascending order:");
for (int i=0;i<names.length;i++)
{
System.out.println(names[i]);
}
}//Main ends
}//Class ends

Variable Descrip ons


String To declare an array of size 20
names[]
String sort To swap the values(student names) and arrange them in ascending order
int i To ask the user to input values in the array
int i To workout the outer loop
int j To workout the inner loop
int i To print the names in ascending order
Ques on 13: Define a class to accept the marks secured in “Computer
Applica ons” by 20 students of a class in a single dimensional array. Sort the
marks obtained in descending order using Selec on sort technique, and
display the marks of students in sorted order.
import java.u l.Scanner;
public class Marks_comp_app
{
public sta c void main(String args[])
{
Scanner sc=new Scanner(System.in);
int m[]=new int[20];
System.out.println("Enter the marks of 20 students in Computer Applica ons:");
for(int i=0;i<20;i++)
{
m[i]=sc.nextInt(); }
for(int i=0;i<m.length-1;i++)
{
int des=i;
for(int j=i+1;j<m.length;j++)
{
if(m[j]>m[des])
{
des=j;
}
}
int sort=m[des];
m[des]=m[i];
m[i]=sort;
}
System.out.println("Marks of students in descending order:");
for(int i=0;i<m.length;i++)
{
System.out.println(m[i]);
}
}//Main ends
}//Class ends

Variable Descrip ons


int m[] To declare an array of size 20
int i To ask the user to input values(marks of students) in the array
int i To workout the outer loop
int des To store the value of i and then compare it with with j
int j To workout the inner loop
int sort To swap the values(student names) and arrange them in descending order
Ques on 14: Write a program to search for an integer value input by the user
in the sorted list given below using Binary search technique. If found display
“Search successful” and the element, otherwise display “Search Unsuccessful”
{31, 36, 45, 48, 50, 51, 67, 78, 89, 90}

import java.u l.Scanner;


public class BinarySearch
{
public sta c int binarySearch(int arr[],int x)
{
int low=0; int
high=arr.length-1;
while(low<=high)
{
int mid=(low+high)/2;
if(arr[mid]==x)
{
return mid;
}
else if(arr[mid]<x)
{
low=mid + 1;
}
else
{
high=mid-1;
}
}
return -1;
}
public sta c void main(String[] args)
{
int arr[]={31,36,45,48,50,51,67,78,89,90};
Scanner sc=new Scanner(System.in);
System.out.print("Enter the integer value to search:
"); int x=sc.nextInt(); sc.close();
int result=binarySearch(arr,x);
if(result!=-1)
System.out.println("Search Successfull Element found at index: " + result + ".");
else
System.out.println("Search Unsuccessful.");
}//Main ends
}//Class
ends
Variable Descrip ons
int arr To ini alize an array of 10 terms
int x To store the integer value i.e. to be searched
int low It stores the first term of the array and then goes on increasing its value one by
one un l the desired term is found
int high It stores the last term of the array and then goes on decreasing its value one by
one un l the desired term is found
int mid To find and store the middle term of the array
Ques on 15: Define a class to accept values into 4×4 array and find and display
the sum of each row.
1 2 3 4 The Sum of row 1 :10

5 6 7 8 The Sum of row 2 :26

9 10 11 12 The Sum of row 3: 42

13 14 15 16 The Sum of row 4: 85

import java.u l.*;


public class array_4x4
{
public sta c void main(String args[])
{
Scanner sc = new Scanner(System.in);
int a[][]=new int[4][4];
System.out.println("Enter the values into the 4x4 array:");
for(int i=0;i<4;i++)
{
for(int j=0;j<4;j++)
{
a[i][j]=sc.nextInt();
}
}
for (int i = 0; i < 4; i++)
{
int sum = 0;
for (int j = 0; j < 4; j++)
{
sum += a[i][j];
}
System.out.println("The Sum of row " + (i + 1) + " :" + sum);
}
}//Main ends
}//Class ends

Variable Descrip ons


int a[][] To declare a two dimensional array of size 4x4
int i To workout the external loop to give values in the array
int j To workout the internal loop to give values in the array
int i To workout the outer loop to find the sum
int sum To calculate and store the sum of the rows
int j To workout the inner loop to find the sum
Ques on 16: Define a class to accept the names of 10 students in an array and
check for the existence of the given name in the array using “Linear search
technique”, if found print the posi on of the name, if not found print the
appropriate message. Also print the names which begins with the word “Mr”.

import java.u l.Scanner;


public class hell
{
public sta c void main(String args[])
{
Scanner sc=new Scanner(System.in);
String n[]=new String[10];
System.out.println("Enter the names of 10 students:");
for (int i=0;i<10;i++)
{
n[i]=sc.nextLine();
}
System.out.print("Enter the name to search: ");
String s=sc.nextLine();
int a=-1;
for(int i=0;i<10;i++)
{
if(n[i].equals(s))
{
a=i;
break;
}
}
if(a==-1)
{
System.out.println("Search Unsuccessful: " + s + " not found");
}
else
{
System.out.println("Search successful: " + s + " found at posi on " + (a+1));
}
System.out.println("Names beginning with 'Mr':");
for(int i=0;i<10;i++)
{
if(n[i].startsWith("Mr"))
{
System.out.println(n[i]);
}
}
}//Main ends
}//Class ends

Variable
Descrip ons
String n[] To declare an array of size 10
int i To accept values in the array
String s To store the name to be searched
int a It is used as a flag
int i To workout the loop
int i To print the array element which starts with Mr
Ques on 17: Define a class to accept values into a 3×3 array and check if it is a
special array. An array is a special array if the sum of the even elements = sum
of the odd elements.

4 5 6 Sum of even elements=4+6+2+4+2=18


Sum of even elements=5+5+3+5=18
5 3 2
4 2 5

import java.u l.*;


public class Spl_array
{
public sta c void main(String args[])
{
int a[][]=new int[3][3];
Scanner sc=new Scanner(System.in);
System.out.println("Enter the values in the 3x3 array");
int se=0,so=0;
for(int i=0;i<3;i++)
{
for(int j=0;j<3;j++)
{
a[i][j]=sc.nextInt();
if(a[i][j]%2==0)
se=se+a[i][j];
else
so=so+a[i][j];
}
}
if(se==so)
System.out.println("Special Array");
else
System.out.println("Special Array");
}//Main ends
}//Class ends
Variable Descrip ons
int a[][] To accept and store values in 3x3 array
int se To find and store the sum of the even terms
int so To find and store the sum of the odd terms
int i To workout the outer loop
int j To workout the inner loop
Ques on 18: Write a program to store the numbers in 4×4 array in double
dimensional array and display the largest and the smallest value within the
array.
Example: Input: Output:

13 2 23 4
The highest value in the array is :120
52 61 71 18 The smallest value in the array is :2

95 100 110 120

13 41 15 16 import java.u l.*;


public class aray
{
public sta c void main(String args[])
{
int arr[][]=new int[4][4];
Scanner sc=new Scanner(System.in);
System.out.println("Enter the values in the 4x4 array");
int a,b;
for(int i=0;i<4;i++)
{
for(int j=0;j<4;j++)
{
arr[i][j]=sc.nextInt();
}
}
int l=arr[0][0],s=arr[0][0];
for(int i=0;i<4;i++)
{
for(int j=0;j<4;j++)
{
a=arr[i][j];
b=arr[i][j];
if(a>l)
l=a; else
if(b<s)
s=b;
}
}
System.out.println("The largest value within the array: "+l);
System.out.println("The smallest value within the array: "+s);
}//Main ends
}//Class ends
Variable Descrip ons
int a[][] To declare an array of size 4x4
int a To calcultate and store the highest value of the array
int b To calculate and store the lowest value of the array
int i To workout the outer loop
int j To workout the inner loop
int l To compare the values and print them
Ques on 19: A book seller maintains records of books belonging to the various
publishers. He uses a class with the specifica ons given below:

Class name Stock

Data Members
String tle To store the tle of the book
String author To store the author name of the book
String pub To store the publisher of the book
int noc To store the number of copies of the book
Member Func ons
Stock() Default constructor to ini alize all the data
members.
void getdata() To accept tle, author, publisher’s name and
the number of copies.
void (String t, String a, String p, int n) To check the existence of the book by
comparing tle, author’s and publisher’s
name. Also check whether number of
noc>=n.
If yes, maintain the balance noc-n,
otherwise the message “Book is not
available or stock is under flowing.”
Define a class Stock with the above specifica ons and write the main method to create an
object of the class and call the above member methods.

import java.u l.Scanner;


public class Stock
{
String tle;
String
author;
String pub;
int noc;
Stock()
{
tle="";
author="";
pub="";
noc=0;
}
public void getdata()
{
Scanner sc=new Scanner(System.in);
System.out.println("Enter the Title of the book: ");
tle=sc.nextLine();
System.out.println("Enter the Author's name: ");
author=sc.nextLine();
System.out.println("Enter the Publisher's name: ");
pub=sc.nextLine();
System.out.println("Enter the Number of copies: "); noc=sc.nextInt();
}
public void purchase(String t,String a,String p,int n)
{
if( tle.equals(t)&&author.equals(a)&&pub.equals(p))
{
if(noc>=n)
{
noc-=n;
System.out.println("Purchase successful Remaining copies: " + noc);
}
else
System.out.println("Book is not available or Stock is under flowing.");
}
}
public sta c void main(String args[])
{
Stock ob=new Stock();
ob.getdata();
ob.purchase("Halloween Havoc", "Shaurya Gupta ", "P.T. Publica ons ", 18);
}//Main ends
}//Class ends

Variable Descrip ons


String tle To store the tle of the book
String author To store the author name of the book
String pub To store the publisher of the book
int noc To store the publisher of the book
Ques on 20: Define a class SmartShop with the specifica ons given below:

Class name SmartShop


Data Members
String name To store the name of the item purchased
double price To store the price of the item purchased
double netamount To store the netamount paid by the customer
a er the discount.
Member Func ons
SmartShop() Default constructor to ini alize name= “ “ and
price=0.0
void accept() To input the name and the price of the item
using the method of Scanner class
void calculate() To calculate the net amount to be paid by
the customer, based on the following
criteria:

Price Discount
Upto 15000 5%
15001-25000 8%
25001-50000 10%
More than 50000 12%
void display() To display the details in the given format:
Item name Item price Net amount
xxx xxx xxx

Define a class SmartShop with the above specifica ons and write the main method to
create an object of the class and call the above member methods.

import java.u l.*;


public class SmartShop
{
String name; double
price,netamount;
SmartShop()
{
name="";
price=0.0;
}
void accept()
{
Scanner sc=new Scanner(System.in);
System.out.println("Enter the Name: ");
name=sc.nextLine();
System.out.println("Enter the Price of the item: ");
price=sc.nextDouble();
}
void calculate()
{
if(price<=15000)
netamount=price-(0.05*price); else
if(price>=15001&&price<=25000)
netamount=price-(0.08*price); else
if(price>=25001&&price<=50000)
netamount=price-(0.10*price);
else
netamount=price-(0.12*price);
}
void display()
{
System.out.println("Item Name"+"\t"+"Item Price"+"\t"+"Net Amount");
System.out.println(name +"\t"+ price +"\t"+ netamount);
}
public sta c void main(String args[])
{
SmartShop ob=new
SmartShop(); ob.accept();
ob.calculate(); ob.display();
}//Main ends
}//Class ends

Variable Descrip ons


String name To store the name of the item purchased
Double price To store the price of the item purchased
Double netamount To store the price of the item purchased
REFRENCES
~ TOTAL COMPUTER APPLICATIONS 10 ICSE [MORNING STAR]
~ TOTAL COMPUTER APPLICATIONS 9 ICSE [MORNING STAR]
~ COPILOT BING
~ CHATGPT-4
~ GOOGLE
~ INSTAGRAM

You might also like