You are on page 1of 7

Name:jahnavi tulasi.

Rg.no:21MIS0019

Java assignment 6

1.Ram works in a mobile shop where he will do mobile recharges, sells


mobiles
and mobile accessories like temper glass, cover, earphones and headset. He
also
handles the stock details and purchases the required products every week.
Ram
has to report to his boss weekly to show the sales and purchases done on
the
particular week.
Write a java program for the above scenario where Ram will provide details
regarding all the sales and purchases made by him weekly. The program
should
calculate the total number of products sold, price and the total number of
purchases made. Ram can choose the option for computing the sales or
purchase
details per week. Also, he can see the profit/ loss incurred per week.
The boss would like to see the number of purchases and the number of sales
per
week. Upon his request, the program should display the number of sales,
purchases, and profit per week.

Code:
import java.util.Scanner;

class requirements{

int no_sold_temper_glass,no_sold_cover,no_sold_earphones,no_sold_headset;

int no_pur_temper_glass,no_pur_cover,no_pur_earphones,no_pur_headset;

float sold_pri_temper_glass,sold_pri_cover,sold_pri_earphones,sold_pri_headset;

float pri_pur_temper_glass,pri_pur_cover,pri_pur_earphones,pri_pur_headset;

float tot_pro_temper_glass,tot_pro_cover,tot_pro_earphones,tot_pro_headset;

float tot_sold_temper_glass,tot_sold_cover,tot_sold_earphones,tot_sold_headset;

float tot_sold,tot_pur,tot_f;

class calc extends requirements{

Scanner sc=new Scanner(System.in);

void get_sold() {

System.out.print("Enter The Number Of sold temper glass : ");


super.no_sold_temper_glass=sc.nextInt();

System.out.print("Enter The Price Per sold temper glass : ");

super.sold_pri_temper_glass=sc.nextFloat();

System.out.print("Enter The Number Of sold cover : ");

super.no_sold_cover=sc.nextInt();

System.out.print("Enter The Price Per sold cover : ");

super.sold_pri_cover=sc.nextFloat();

System.out.print("Enter The Number Of sold earphones : ");

super.no_sold_earphones=sc.nextInt();

System.out.print("Enter The Price Per sold earphones : ");

super.sold_pri_earphones=sc.nextFloat();

System.out.print("Enter The Number Of sold headset : ");

super.no_sold_headset=sc.nextInt();

System.out.print("Enter The Price Per sold headset : ");

super.sold_pri_headset=sc.nextFloat();

void get_product() {

System.out.print("Enter The Number Of temper glass Purchased :");

super.no_pur_temper_glass=sc.nextInt();

System.out.print("Enter The Price Per purchased temper glass : ");

super.pri_pur_temper_glass=sc.nextFloat();

System.out.print("Enter The Number Of cover Purcahsed : ");

super.no_pur_cover=sc.nextInt();

System.out.print("Enter The Price Per purchased cover : ");

super.pri_pur_cover=sc.nextFloat();

System.out.print("Enter The Number Of earphones Purchased");

super.no_pur_earphones=sc.nextInt();

System.out.print("Enter The Price Per purchased earphones : ");

super.pri_pur_earphones=sc.nextFloat();

System.out.print("Enter The Number Of headset Purchased : ");

super.no_pur_headset=sc.nextInt();
System.out.print("Enter The Price Per purchased headset : ");

super.pri_pur_headset=sc.nextFloat();

void cal_product() {

tot_pro_temper_glass=no_pur_temper_glass*pri_pur_temper_glass;

tot_pro_earphones=no_pur_earphones*pri_pur_earphones;

tot_pro_cover=no_pur_cover*pri_pur_cover;

tot_pro_headset=no_pur_headset*pri_pur_headset;

tot_pur=tot_pro_temper_glass+tot_pro_earphones+tot_pro_cover+tot_pro_headset;

void cal_sold() {

tot_sold_temper_glass=no_sold_temper_glass*sold_pri_temper_glass;

tot_sold_earphones=no_sold_earphones*sold_pri_earphones;

tot_sold_cover=no_sold_cover*sold_pri_cover;

tot_sold_headset=no_sold_headset*sold_pri_headset;

tot_sold=tot_sold_temper_glass+tot_sold_earphones+tot_sold_cover+tot_sold_headset;

class disp extends calc{

void profit_or_loss() {

System.out.println("You Have Sold Total Ammount Of"+super.tot_sold);

System.out.println("You Have Purchased Total Ammount Of"+super.tot_pur);

super.tot_f=super.tot_sold-super.tot_pur;

if(super.tot_f>0) {

System.out.println("You were Got Profit \nAmmount Of"+super.tot_f);

else {

System.out.println("You were Got Loss \nAmmount Of"+super.tot_f);

}
class Main {

public static void main(String[] args) {

Scanner sc=new Scanner(System.in);

disp d=new disp();

String op;

while(true) {

System.out.println("Enter Your Option : \nsold-To GetValues And Calculate Sold


Products\npurchased-To Get Values And CalculatePurchased Products\nexit-To Get Exit From The
Loop\ndisplay-To Get DisplayThe Result\n");

op=sc.next();

switch(op.toLowerCase()) {

case "sold":

d.get_sold();

d.cal_sold();

break;

case "purchased":

d.get_product();

d.cal_product();

break;

case "display":

d.profit_or_loss();

break;

case "exit":

System.exit(0);

break;

default:

System.out.println("You Have Entered WrongOption :");

}
Output:

2. Write the java program for different shapes (Line, Triangle, Rectangle
and
Circle) and compute the area of shapes. Apply the multilevel inheritance
concept
in the above code to show how method overriding takes place and how the
final
keyword is used for avoiding method overriding?

Code:
class Line{
int length;
Line(){
length = 5;
}
void area(){
System.out.println("Line Has No Area");
}
}
class Triangle extends Line{
int height,base;
Triangle(){
height = 6;
base = 3;
}
void area(){
System.out.println("Area of Triangle = "+0.5*height*base);
}
}
class Rectangle extends Triangle{
int length,breadth;
Rectangle(){
length = 3;
breadth = 5;
}
void area(){
System.out.println("Area of Rectangle = "+length*breadth);
}
}
class Circle extends Rectangle{
int radius;
Circle(){
radius = 2;
}
void area(){
System.out.println("Area of Circle = "+3.14*radius*radius);
}
}
public class Week {
public static void main(String[] args) {
Line l = new Line();
l.area();
Triangle t = new Triangle();
t.area();
Rectangle r = new Rectangle();
r.area();
Circle c = new Circle();
c.area();
}
}

Output:

You might also like