الفريق العربي للبرمجةأرشيف المنتديات · 2000 – 2023
نسخة أرشيفية للقراءة فقط — التسجيل والمشاركة مغلقان، والمحتوى محفوظ كما كان.

[ تنبيه ] تصحيح كود

بدأه الطالبه بنان في 11 ديسمبر 2010 · 2 رد · 378 مشاهدة · في JavaSE
مشاركة: واتساب X فيسبوك تيليجرام
#1 صاحب الموضوع

السلام عليكم ورحمة الله وبركاته

هذا الكود انا كتبته وطلع لي الاوت بوت بس الي حيرني انها كتبة الميس في السؤال هذا الكلام

Initialize the data members of the class by using a parameterized constructor’s, when the object is instantiated.

Display the message “constructor called” in the constructor definition.

أتوقع انه لازم استخدم CONSTRACTOR

بس ماعرفت أستخدمه مع برايفت وغير كذا ان اليوزر راح يدخل البيانات

بليزززززززز سااااعدوني

class Hospital
{public int Beds_available;
public int Total_charges;
private int Rooms;
private int Beds;
private int per_day_charges;
private int Days;
private int Patients;

public int getRooms()
{return Rooms;}
public void setRooms(int r)
{Rooms=r;}

public int getBeds()
{return Beds;}
public void setBeds(int b)
{Beds=b;}

public int getper_day_charges()
{return per_day_charges;}
public void setper_day_charges(int p)
{per_day_charges=p;}

public int getDays()
{return Days;}
public void setDays(int d)
{Days=d;}


public int getPatients()
{return Patients;}
public void setPatients(int s)
{Patients=s;}

public int bed_allotment()  
{return Beds_available = (Rooms * Beds) - Patients;}

public int total_charges() 
{return Total_charges = per_day_charges * Days;}
}

import java.util.Scanner;
class Hospitaltest
{public static void main(String args[])
{Scanner input=new Scanner(System.in);
Hospital H=new Hospital();
System.out.print("Number of rooms in the Hospital: ");
int room=input.nextInt();
H.setRooms(room);

System.out.print("Number of beds in each room: ");
int beds=input.nextInt();
H.setBeds(beds);

System.out.print("Total Number of patients in the hospital: ");
int patient=input.nextInt();
H.setPatients(patient);

System.out.print("Per day charges of the hospital: ");
int per=input.nextInt();
H.setper_day_charges(per);

System.out.print("Total number of days the patient stayed in the hospital: ");
int day=input.nextInt();
H.setDays(day);

System.out.println("Number of available beds is: "+H.bed_allotment());
System.out.println("Total charges are: "+H.total_charges());

}
}
410602433.gif
#2

بعتقد دا اللى بتحتاجينه

class Hospital {

	public int Beds_available;
	public int Total_charges;
	private int Rooms;
	private int Beds;
	private int per_day_charges;
	private int Days;
	private int Patients;

	public Hospital(int Rooms, int Beds, int per_day_charges, int Days, int Patients) {
    	this.Rooms = Rooms;
    	this.Beds = Beds;
    	this.per_day_charges = per_day_charges;
    	this.Days = Days;
    	this.Patients = Patients;
    	System.out.println("constructor called");
	}

	public int getRooms() {
    	return Rooms;
	}

	public void setRooms(int r) {
    	Rooms = r;
	}

	public int getBeds() {
    	return Beds;
	}

	public void setBeds(int b) {
    	Beds = b;
	}

	public int getper_day_charges() {
    	return per_day_charges;
	}

	public void setper_day_charges(int p) {
    	per_day_charges = p;
	}

	public int getDays() {
    	return Days;
	}

	public void setDays(int d) {
    	Days = d;
	}

	public int getPatients() {
    	return Patients;
	}

	public void setPatients(int s) {
    	Patients = s;
	}

	public int bed_allotment() {
    	return Beds_available = (Rooms * Beds) - Patients;
	}

	public int total_charges() {
    	return Total_charges = per_day_charges * Days;
	}
}

import java.util.Scanner;

class Hospitaltest {

	public static void main(String args[]) {
    	Scanner input = new Scanner(System.in);
    	System.out.print("Number of rooms in the Hospital: ");
    	int room = input.nextInt();

    	System.out.print("Number of beds in each room: ");
    	int beds = input.nextInt();

    	System.out.print("Total Number of patients in the hospital: ");
    	int patient = input.nextInt();

    	System.out.print("Per day charges of the hospital: ");
    	int per = input.nextInt();

    	System.out.print("Total number of days the patient stayed in the hospital: ");
    	int day = input.nextInt();

    	Hospital hTest = new Hospital(room, beds, per, day, patient);

    	System.out.println("Number of available beds is: " + hTest.bed_allotment());
    	System.out.println("Total charges are: " + hTest.total_charges());

	}
}

بالتوفيق ان شاء الله

Software Developer
Mahmoudkelany.com


 

#3

*- يحظر استخدام اللهجة العامية

*- أو كتابة الأسئلة باللغة الإنجليزية

*- أو كتابة الكلمات الإنجليزية بالعربية

====

Do as I say, not as I do

We are Anonymous. We are Legion. We don't forgive. We don't forget

مواضيع مشابهة