برنامه نویسی
وظایف

وظیفه 1
- ایجاد یک کلاس به نام “جواهرات”
- ایجاد متغیرهای استاتیک زیر: static int goldPrice = 7100; نقره بین المللی ثابت قیمت = 150; 2.1. ایجاد متغیرهای غیر استاتیک زیر int make_charges, wastage;
- ایجاد روش اصلی
- در داخل متد main، نمونه ای را به صورت زیر بسازید Jewellery jewel1 = new Jewellery(); Jewellery jewel2 = new Jewellery();
- با استفاده از jewel1، make_charges و wastage را تعیین کنید.
- با استفاده از jewel2، make_charges و wastage را تعیین کنید.
- یک روش غیر استاتیک را به صورت زیر فراخوانی کنید. jewel1.bill(); jewel2.bill();
- ذخیره، کامپایل و رفع خطا.
- روش Inside bill()، print making_charges و 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));
}
}
خروجی
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
وظیفه 2
- ایجاد یک کلاس به نام “خرید”
- متغیرهای استاتیک زیر را ایجاد کنید: static int doorNo = 5; تخفیف int static = 10; 2.1. ایجاد زیر متغیرهای غیر استاتیک int price, weight.
- ایجاد روش اصلی
- در داخل متد main، نمونه ای را به صورت زیر ایجاد کنید Shop product1 = new Shop(); خرید محصول2 = فروشگاه جدید();
- با استفاده از product1، قیمت و وزن را تعیین کنید.
- با استفاده از product2، قیمت و وزن را تعیین کنید.
- یک روش غیر استاتیک را به صورت زیر فراخوانی کنید. product1.bill(); product2.bill();
- ذخیره، کامپایل و رفع خطا.
- روش Inside bill() قیمت و وزن چاپ.
- Inside main method و inside bill() ، print doorNo و 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);
}
}
خروجی
Door No: 5
Discount: 10
Product 1
Price = 1000
Weight = 10
Product 2
Price = 2000
Weight = 20