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
Code:
public class Jewellery
{
static int goldPrice=7100;
static int silverPrice=150;
int making_charges,wastage;
public static void main(String[] args)
{
Jewellery jewel1 = new Jewellery();
Jewellery jewel2 = new Jewellery();
jewel1.making_charges = 15000;
jewel1.wastage = 140;
jewel2.making_charges = 50000;
jewel2.wastage = 5000;
jewel1.bill();
jewel2.bill();
}
public void bill()
{
System.out.println("Making charges:"+making_charges+ " Wastages:"+wastage);
}
}
Output:
Top comments (0)