Computer Projectots
Computer Projectots
Q1.
A Class Telcall calculates the monthly phone bill of a consumer. Some of the members of Class are given below:Class Name Data Members Telcall phno: Phone Number name: Name of Consumer n: No. of calls made amt: Bill Amount Member Functions i) Telcall(int x, String y, int k) Parameterized constructor to assign value to data members. void Compute() To calculate the phone bill amount based on the slabs given below. void Display() To display the details in the specified format.
ii)
iii)
Rate Rs. 500/- as rental charge Rs. 1.00/-per call + rental charge Rs. 1.20/-per call + rental charge
Above 300
The calculations need to be done as per the details of the constructor, void Compute(), void Display(). In the main function create an object of class Telcall and display the phone bill in the following format. Phone Number Amount ************ Name ***** Total Calls ******** *******
Program Code Below: import java.io.*; class Telcall { private int phno, n; String name; double amt; public void Telcall(int x, String y, int k) { phno = x; name = y; n = k; } public void Compute( ) { if((n>=1)&&(n<=100)) { amt = 500; } else if((n>100)&&(n<=200))
ISC Computer Science Project { amt = 500+(1*(n-100)); } else if((n>200)&&(n<=300)) { amt = 500+(1*(n-100))+(1.20*(n-200)); } else { amt = 500+(1*(n-100))+(1.20*(n-200))+(1.50*(n-300)); } } public void Display() { System.out.println("phoneno."+\t+"name"+"\t"+"totalcall"+"\t"+"amou nt"); System.out.println(phno+"\t"+name+"\t"+n+"\t"+amt); } public static void main(String [ ] args)throws IOException { InputStreamReader Reader =new InputStreamReader(System.in); BufferedReader Input =new BufferedReader(Reader); System.out.println("enter phone no."); String v=Input.readLine( ); int a = Integer.parseInt(v); System.out.println("enter name"); String b = Input.readLine( ); System.out.print("enter total no. of calls"); String v1=Input.readLine( );
ISC Computer Science Project int c = Integer.parseInt(v1); Telcall obj = new Telcall(); obj.Telcall(a,b,c); obj.Compute( ); obj.Display( ); } }
INPUT :Enter Phone Number: 232345 Enter Name: Xavier Total Calls: 345 OUTPUT :Phone Number 232345 Xavier Name 345 Total Calls 787.5 Amount
Q2.
The Distance between two points (x1, y1) and (x2, y2) is calculated as x1-x22+(y1-y2)2
An abstract class Point represents a point on a 2-D plane while another class Distance is declared to help in finding distance between two points and midpoint. The details of both the classes are as:Class Name Data Members Point -x1, y1,x2, y2 Double type variables to store coordinate. -dist Double type variable to store distance. Member Functions -Point() Constructor to assign 0 to x1, y1, x2, y2. -abstract void readPoint()
ISC Computer Science Project To declare abstract type function. -abstract void findDistance() To declare abstract type function. -void show() To print value of x1, y1, x2, y2 using suitable statements. Derived Class Data Members Distance -midx, midy Double type variable to store midpoint of x and y. Member Functions -void readPoint() To input values of x1, y1, x2, y2 for this abstract function declared in the class Point. -void findDistance() To find the distance between the two points(x1,y1) and (x2,y2) for this abstract function declared in the class Point. -void findmidpoint() To calculate the mid point using the coordinate (x1, y1) and (x2, y2). The mid point is calculated as midx=(x1+x2)/2 & midy=(y1+y2)/2. -void show() To display the values of dist, midx and midy.
A) Specify the class Point giving details of constructor, function void show() and declare abstract functions abstract void readPoint() and abstract void findDistance().
giving details of the abstract functions abstract void readPoint(), abstract void findDistance(), void findmidpoint() and void show. The class Distance is derived from class Point. You need to write the main function.
ISC Computer Science Project } class Distance extends Point { private double midx,midy; void readPoint()throws IOException { InputStreamReader Reader=new InputStreamReader(System.in); BufferedReader input =new BufferedReader(Reader); System.out.println("Enter the coordinates of first point:"); String v1=input.readLine(); x1=Double.parseDouble(v1); String v2=input.readLine(); y1=Double.parseDouble(v2); System.out.println("Enter the coordinates of second point:"); String v3=input.readLine(); x2= Double.parseDouble(v3); String v4=input.readLine(); y2=Double.parseDouble(v4); } void findDistance() { dist=Math.sqrt(Math.pow((x2-x1),2)+Math.pow((y2-y1),2)); } public void findMidpoint( ) { midx=(x1+x2)/2; midy=(y1+y2)/2; }
ISC Computer Science Project public void show() { super.show(); System.out.println("Distance"+dist); System.out.println("Mid point ("+midx+","+midy+")"); } public static void main(String[]args)throws IOException { Distance o=new Distance(); o.readPoint(); o.findDistance(); o.findMidpoint(); o.show(); } }
INPUT:Enter the coordinates of first point: 4 3 Enter the coordinates of second point: 26 3 OUTPUT:The abscissa of first point: 4.0 The ordinate of first point: 3.0 The abscissa of second point: 26.0 The ordinate of second point: 3.0
ISC Computer Science Project Distance: 22.0 Mid point: (15.0, 3.0)
Q3. The following is the process of finding factorial of a number n: n!= n (n-1) (n-2) (n-3). A class Factorial is declared with the following details. Class Name Data Members Factorial -n int to store a no. >=0 -m int to store the factorial Member Function -Factorial() A constructor to assign 0 to m. -int fact(int num) To find and return the factorial of num (if num>0) using recursive technique otherwise it should return 1(if num=0). -void getNumber(int x) To assign x to n and by invoking function fact(), Store
Print value stored in f using suitable message. Specify the class factorial by giving details of constructor and all the functions. Write a main function to print the factorial of integer number. Program Code Below
import java.io.*; class Factorial { private
int n,m; int f=1; Factorial() { } int fact(int num) { { } else if(num>0) { f=f*num; if(num==0) return(1); m=0;
ISC Computer Science Project } public static void main(String args[])throws IOException { Factorial obj=new Factorial();
BufferedReader buf=new BufferedReader(new InputStreamReader(System.in)); System.out.println("Enter the number to find factorial."); int k=Integer.parseInt(buf.readLine()); obj.getNumber(k); } }
Q4. Class Sorter contains an array of 5 integers. Some of the member functions of Sorter are given below.
Sorter An array of 5 integers -Sorter() Constructor -void readList() To input 5 integers. -void displayList() To display the list of sorted integer. -int indexofMin(int
ISC Computer Science Project startindex) Returns the index of the smallest integer between the start index and the last index in the array. -void selectionSort() Sorts the array in ascending order using selection sort technique.
Specify the class Sorter giving the details of the constructor and the function void displayList(), int indexofMin(int startindex), void selectionSort(). You may assume that the other functions are also written. Program Code Below:import java .io.*; import java.lang.*; class Sorter { private int a[]=new int[100]; int index=0; int i; public Sorter() { { for(i=0; i<5; i++) a[i]= 0; } }
String v=input.readLine();
index=i; } }
System.out.println("Index of min is:"+index); return(index); } void selectionSort() { int i, j, small, temp, pos=0, k=0;
temp = a[pos]; a[pos] = a[i]; a[i] = temp; } void displayList( ) { System.out.println("The sorted array is:"); }
public static void main(String args[])throws IOException { InputStreamReader reader = new InputStreamReader(System.in);
INPUT:Enter start index value: 2 Enter 1no. : 1 Enter 2no.: 4 Enter 3no.: 3 Enter 4no.: 2 Enter 5no.: 5 OUTPUT:Index of min is : 4 The Sorted array: 1 2 3 4 5
Q5.
Class Checker has been defined to check whether a number is palindrome or not. The details of the class are given below:Class Name Data Members Checker num: long integer variable to store number
Specify the class Checker giving details of constructor the functions long ReverseNum(long q) and void display(). The main function needs to be written.
long num; long rev=0; public Checker(long z) { } long reverseNum(long q) { if(q>0) { num=z;
public static void main(String args[ ])throws IOException { InputStreamReader reader= new InputStreamReader(System.in); BufferedReader input= new BufferedReader(reader); System.out.println("Enter the no."); String v=input.readLine(); long x=Long.parseLong(v); Checker obj= new Checker(x); obj.display(); } }
Q6.
A class Student defines student related info such as name, roll no., and date of work. While another class defines marks in various Subjects and Total, Percentage and Grade. The details of both the classes are given below:Class Name Data Members Student -Name, dob String variables to store name and D.O.B. -roll Integer variable to store roll number. Member Functions -void inputData() To input values of all the data members. -void printData() To display values of all the data members with suitable headings. Class Name Data Members Marks -tot, per Double type variables to store total and percentage. -gd Character variable to store grade as per the result.:Percentage >=85 >=60 and <85 >=40 and <60 <40 Member Function -void readData() To read Total Marks out of 500. -void Compute Grade A B C D
import java.io.*; class Student { private String nam, dobirth; int roll;
public void inputData()throws IOException { BufferedReader buf=new BufferedReader(new InputStreamReader(System.in)); System.out.println("Name:"); nam=buf.readLine(); System.out.println("Date of Birth :"); dobirth=buf.readLine(); System.out.println("Roll No. :"); String v=buf.readLine(); roll=Integer.parseInt(v); void printData() { System.out.println("NAME :"+nam); System.out.println("D.O.B. :"+dobirth); System.out.println("Role Number :"+roll); class Marks extends Student { private double tot, per; char gd; public void readData()throws IOException { BufferedReader buf=new BufferedReader(new InputStreamReader(System.in)); System.out.println("Enter the Total Marks."); tot=Double.parseDouble(buf.readLine()); public void Compute() { per=(tot*100.0)/500; } } } }
else if(per<40) { } void showData() { printData(); System.out.println("Total Marks: "+tot); System.out.println("Percentage: "+per); System.out.println("Grade: "+gd); } gd='D'; }
public static void main(String args[])throws IOException { Marks St=new Marks(); St.inputData(); St.readData(); System.out.println("Student Information:-"); St.Compute(); St.showData(); } }
INPUT:Name: Priya Date of Birth: 26/07/1994 Roll no.: 31 Enter the Total Marks: 451 OUTPUT:Students Information:Name: Priya D.O.B.: 26/07/1994
Q7.
A class printNaturals has been defined to print Natural no. in reverse order which are even in nature. Some of the members of the class are given below:Class Name Data Members printNaturals -m Integer type as last limit of natural series. Member Function -printNaturals() Constructor to assign 0 to m. -void input() To accept last integer for series. -void printseries(int num) To print only those natural no.s from n to 2, which are even in nature. Use recursive technique to generate and print natural no.s that are given.
Specify the class printNaturals giving the details of constructor, void input(), void print() and void printseries(int num). Program Code Below:import java.io.*; class printNaturals { private int n; public printNaturals() { n=0; } void input()throws IOException { BufferedReader bbk= new BufferedReader(new InputStreamReader(System.in)); System.out.print("Input the last limit>2:"); n=Integer.parseInt(bbk.readLine()); } void printSeries(int num) { if(num>1) { if(num%2==0) { System.out.print(num+" "); } printSeries(num-1);
Q8.
Write a program that inputs the names of people in to different arrays, A and B. Array a has N number of names while array B has M number of names, with no duplicates in either of them. Merge arrays A and B in to a single array C, such that the resulting array is stored alphabetically.
Display all the three arrays, A, B and C, stored alphabetically. Test your program for the given data and some random data. Program Code Below:import java.io.*; class SortedNames
String str1[]=new String[10]; String str2[]=new String[10]; String str3[]=new String[20]; int n,m; String s; int i,j; public void take ()throws Exception { System.out.println("Number of Names for first array:"); n=Integer.parseInt(br.readLine()); System.out.println("Number of Names for second array:"); m=Integer.parseInt(br.readLine()); System.out.println("Names for 1st array:"); for(i=0;i< n;i++) { System.out.println("Name:"); str1[i]=br.readLine().trim(); } System.out.println("Names for 2nd array:"); for(i=0;i< m;i++) { System.out.println("Name:"); str2[i]=br.readLine().trim(); } sort(); merge(); display(); } private void sort() { int flag; for(i=0;i< n;i++) {
str1[j]=str1[j+1]; str1[j+1]=s; flag=1; } } if(flag==0) break; } for(i=0;i< m;i++) { flag=0; for(j=0;j< m-i-1;j++) { { if(str2[j].compareTo(str2[j+1]) >0) s=str2[j]; str2[j]=str2[j+1]; str2[j+1]=s; flag=1; if(flag==0) break; } } } }
private void merge() { int x=0; i=0; j=0; while(i!=n && j!=m) { if(str1[i].compareTo(str2[j])<=0) str3[x++]=str1[i++]; else
for(i=0;i< m+n;i++) System.out.println(str3[i]); System.out.println("\n*********\n"); System.out.println("\nFirst array names\n"); for(i=0;i< n;i++) System.out.println(str1[i]); System.out.println("\n*********\n"); System.out.println("\nSecond array names\n"); for(i=0;i< m;i++) System.out.println(str2[i]); }
public static void main(String args[])throws Exception { SortedNames obj=new SortedNames(); obj.take(); } }
INPUT:Number of names for 1st Array: 4 Number of names for 2nd Array: 3 Names for 1st Array: Name: Name: Name: Name: Anil Ajay Roxen Saif
Q9.
The classes Data and Process are declared with following details: Class Name Data Members Member Functions Data Str: string variable of protected type Data() Constructor to assign blank to Str void acceptstr() To read a sentence into Str void Print()
Model the above situation by defining classes Data and Process using concept of inheritance. The class Process is derived from class Data. Program Code Below:import java.io.*; class Data { protected String str; public Data() { str=" "; } void acceptstr()throws IOException { InputStreamReader Reader= new InputStreamReader(System.in); BufferedReader Input=new BufferedReader(Reader); System.out.println("Enter the sentence:"); str=Input.readLine();
INPUT:Enter the Sentence: Youuuu arrrre ooon thhee wwwrongg waaayyy. OUPUT:The Sentence is You are on the wrong way.
Q10. Write a program which takes a string (maximum 80 characters terminated by a full stop. The words in this string are assumed to be separated by one or more blanks.
Program Code Below:import java.io.*; import java.util.*; class StringArrangement { String str,str2; StringTokenizer stk; String sr[]; int i,j,x; int flag; BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); public void takeString()throws IOException { char ch; while(true) { System.out.println("\nEnter the sentence:"); str=br.readLine().trim(); if(str.length() >80) { System.out.println("\nString exceeds 80 characters.");
INPUT: Enter the sentence: "To handle yourself use your head and to handle others use your heart." OUTPUT: Yourself Handle Handle Others Heart Head Your Your And Use Use To To.
Q11. Write a program using Binary File concept to create a Binary File Invoise.dat to input name, quantity of product and unit price of product for N products. Program Code Below:-
{ BufferedReader inp=new BufferedReader(new InputStreamReader(System.in)); String pname; int qty; double price; FileOutputStream std=new FileOutputStream("Invoice.dat"); DataOutputStream mat=new DataOutputStream(std); System.out.println("input the no. of products"); int N=Integer.parseInt(inp.readLine()); for(int x=1;x<=N;x++) { System.out.print("input product name");
pname=inp.readLine(); System.out.println("input quantity"); qty=Integer.parseInt(inp.readLine()); System.out.println("Enter unit price"); price=Double.parseDouble(inp.readLine()); mat.writeUTF(pname); mat.writeInt(qty); mat.writeDouble(price); System.out.println(Your File is Created Successfully.); } } }
Input Product Name: Gems Input Product Quantity: Input Unit Price: 543 ActimoSN 5 4
Input Product Name: Input Product Quantity: Input Unit Price: 123
Input Product Name: Input Product Quantity: Input Unit Price: 402
UltraZone VL 3
Input Product Name: Input Product Quantity:7 Input Unit Price: 754
Verizon T
Q12. Write a program using Binary File concept to read the Binary File created in Q11 to calculate the total cost of each product, discount on total cost as 20% on total cost if it is more than 12000.0 otherwise no discount. Calculate net price to be paid. Print the cash memo. Program Code Below:import java.io.*;
Product Quantity: 2 Unit Price: Total Cost: Discount: Net Price: 315 630 0.0 630
Product Name: Gems Product Quantity: 4 Unit Price: Total Cost: Discount: Net Price: 543 2172 0.0 2172 ActimoSN
Product Name:
Product Quantity: 5 Unit Price: Total Cost: Discount: Net Price: 123 615 0.0 615 UltraZone VL
Product Name:
Product Quantity: 3
Product Name:
Product Quantity: 7 Unit Price: Total Cost: Discount: Net Price: 754 5278 0.0 5278