DEV Community

SATHISH BALAJI
SATHISH BALAJI

Posted on

Tasks

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.
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));
}
}
Enter fullscreen mode Exit fullscreen mode

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

Enter fullscreen mode Exit fullscreen mode

Task 2

  1. Create a class called 'Shop'
  2. Create below static variables: static int doorNo = 5; static int discount = 10; 2.1. Create below non-static variables int price, weight;
  3. Create main method.
  4. Inside main method, create instance as below Shop product1 = new Shop(); Shop product2 = new Shop();
  5. Using product1, assign price and weight.
  6. Using product2, assign price and weight.
  7. Call a non-static method as below. product1.bill(); product2.bill();
  8. Save, Compile and fix the error.
  9. Inside bill() method, print price and weight.
  10. 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);
}
}
Enter fullscreen mode Exit fullscreen mode

Output

Door No: 5
Discount: 10
Product 1
Price = 1000
Weight = 10
Product 2
Price = 2000
Weight = 20

Enter fullscreen mode Exit fullscreen mode

Top comments (0)