Task 1
- Create a class called 'Jewellery'
- Create below static variables: static int goldPrice = 7100; static int silverPrice = 150; 2.1. Create below non-static variables int making_charges, wastage;
- Create main method.
- Inside main method, create instance as below Jewellery jewel1 = new Jewellery(); Jewellery jewel2 = new Jewellery();
- Using jewel1, assign making_charges and wastage.
- Using jewel2, assign making_charges and wastage.
- Call a non-static method as below. jewel1.bill(); jewel2.bill();
- Save, Compile and fix the error.
- Inside bill() method, print making_charges and wastage.
public class Jewellery
{
static int goldPrice = 7100;
static int silverPrice = 150;
int making_charge;
int wastage;
public static void main (String[] args)
{
Jewellery jewel1 = new Jewellery();
Jewellery jewel2 = new Jewellery();
jewel1.making_charge = 2000;
jewel1.wastage = 1000;
jewel2.making_charge = 1000;
jewel2.wastage = 500;
jewel1.bill1();
jewel2.bill2();
}
public void bill1()
{
System.out.println("Jewel 1 Bill: "+"\n"+"Gold Price = " +goldPrice+"\n"+"Making Charge = " +making_charge+"\n"+"Wastage = " +wastage+"\n"+"Total = " +(goldPrice+making_charge+wastage));
}
public void bill2()
{
System.out.println("Jewel 2 Bill: "+"\n"+"Silver Price = " +silverPrice+"\n"+"Making Charge = " +making_charge+"\n"+"Wastage = " +wastage+"\n"+"Total = " +(silverPrice+making_charge+wastage));
}
}
Output
Jewel 1 Bill:
Gold Price = 7100
Making Charge = 2000
Wastage = 1000
Total = 10100
Jewel 2 Bill:
Silver Price = 150
Making Charge = 1000
Wastage = 500
Total = 1650
Task 2
- Create a class called 'Shop'
- Create below static variables: static int doorNo = 5; static int discount = 10; 2.1. Create below non-static variables int price, weight;
- Create main method.
- Inside main method, create instance as below Shop product1 = new Shop(); Shop product2 = new Shop();
- Using product1, assign price and weight.
- Using product2, assign price and weight.
- Call a non-static method as below. product1.bill(); product2.bill();
- Save, Compile and fix the error.
- Inside bill() method, print price and weight.
- Inside main method and inside bill() method, print doorNo and discount
public class Shop
{
static int doorNo = 5;
static int discount = 10;
int price;
int weight;
public static void main (String[] args)
{
Shop product1 = new Shop();
Shop product2 = new Shop();
product1.price = 1000;
product2.price = 2000;
product1.weight = 10;
product2.weight = 20;
System.out.println("Door No: "+doorNo);
System.out.println("Discount: "+discount);
product1.bill1();
product2.bill2();
}
public void bill1()
{
System.out.println("Product 1"+"\n"+"Price = "+price+"\n"+"Weight = "+weight);
}
public void bill2()
{
System.out.println("Product 2"+"\n"+"Price = "+price+"\n"+"Weight = "+weight);
}
}
Output
Door No: 5
Discount: 10
Product 1
Price = 1000
Weight = 10
Product 2
Price = 2000
Weight = 20
Top comments (0)