You are on page 1of 2

Assignment 6

Question 1
b)Output:
2 4 5 6 7 8 9 10

Question 2
public class Stock
{
String item;
int qty,rate,amt;
Stock(String it, int q, int r)
{
item=it;
qty=q;
rate=r;
}
void display()
{
System.out.println("Item name\t"+item);
System.out.println("Item quantity\t"+qty);
System.out.println("Item rate\t"+rate);
}
}
public class purchase extends Stock
{
int pqty;
int prate;
purchase(String it, int qt, int rt, int pqt, int pr)
{
super(it,qt,rt);
pqty=pqt;
prate=pr;
}
void update()
{
qty=qty+pqty;
if(rate!=prate)
rate=prate;
amt=qty*rate;
}
void display()
{
super.display();
System.out.println("Update quantity\t"+qty);
System.out.println("Updated rate\t"+rate);
System.out.println("Updated amount\t"+amt);
}
}

Question 3
import java.io.*;
class Telcall
{
String phno,name;
int n;
double amt;
Telcall(String s1,String s2,int x)
{
phno=s1;
name=s2;
n=x;
amt=0;
}
void compute()
{
if(n>=1 && n<=100)
amt=500;
else if(n>=101 && n<=200)
amt=500+((n-100)*1);
else if(n>=201 && n<=300)
amt=500+((n-100)*1.2)+((n-100)*1);
else if(n>300)
amt=500+((n-100)*1.5)+((n-100)*1.2)+((n-100)*1);
}
void dispdata()
{
System.out.println("Phone no. Name Total Calls
Amount");
System.out.println(phno+" "+name+" "+n+"
"+amt);
}
public static void main(String ars[])throws IOException
{
BufferedReader br=new BufferedReader(new
InputStreamReader(System.in));
System.out.println("Enter Phone Number:");
String s1=br.readLine();
System.out.println("Enter Name:");
String s2=br.readLine();
System.out.println("Enter No. of calls:");
int x=Integer.parseInt(br.readLine());
Telcall ob=new Telcall(s1,s2,x);
ob.compute();
ob.dispdata();
}
}

You might also like