DEV Community

Pavithra Saravanan
Pavithra Saravanan

Posted on

Task 1(28/12)

Task 1:

  1. Create a class called 'Jewellery'
  2. Create below static variables: static int goldPrice = 7100; static int silverPrice = 150; 2.1. Create below non-static variables int making_charges, wastage;
  3. Create main method.
  4. Inside main method, create instance as below Jewellery jewel1 = new Jewellery(); Jewellery jewel2 = new Jewellery();
  5. Using jewel1, assign making_charges and wastage.
  6. Using jewel2, assign making_charges and wastage.
  7. Call a non-static method as below. jewel1.bill(); jewel2.bill();
  8. Save, Compile and fix the error.
  9. 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);
}
}
Enter fullscreen mode Exit fullscreen mode

Output:

Image description

Top comments (0)