Professional Documents
Culture Documents
To avoid plagiarism, acknowledge the source and provide the full citation of each reference used,
including URL. يجب ذكر المصادر التي استلت منه((ا المعلوم((ات ح((تى يك((ون البحث غ((ير مقتبس و نحاف((ظ على حق((وق الملكي((ة
لالخرين
Heavy penalty would be imposed for:
Late submission of final task اي تاخير في التسليم سيكون عليه حسم درجات
Non-compliance to the instructions given ال يمكن االعتراض بعد التسليم ال يمكن( رفعه(ا( ب(اي طريق(ة
اخرى
Final Task Submission
Completed final task should be submitted to blackboard website Folder Named (Final Exam
Submission).
المس((مى (رف((ع االختب(ارblackboard يجب رفع الملف النصي بعد االنتهاء( و التاكد من صحة المععلومات بالملف إلى مجلد موقع ويب
)النهائي
1
Q1: (10 marks) Write Java desktop application that satisfy the following:
.انسخ الكود هنا باقل المسافات بين السطورمع المحافظة على المسافة البادئة
import java.lang.*;
import java.util.*;
import java.io.*;
import java.io.ObjectInputStream;
/**
*
* @author Shoroog Abdulla Al-Jedaani
*/
class car
{
int car_id;
String car_name ;
String car_type ;
int car_price ;
int car_model;
int count = 1;
car(){
System.out.println("");
}
if (carList.isEmpty()){
2
int i = 1;
car_id =1;
String car_no = Integer.toString(i);
carList.add(car_no);}
else{
String item ;
try{
for(int i=0 ; i<count-1; i++ ){
item = carList.get(i++);
System.out.print ("car Number: " + item + " ");
item = carList.get(i++);
System.out.print ("& car Name: " + item + " ");
item = carList.get(i++);
System.out.print ("& car Type: " + item + " ");
item = carList.get(i++);
System.out.print ("& car Price : " + item + " ");
item = carList.get(i);
System.out.print ("& car model: " + item + " ");
System.out.println ();
}}
catch(IndexOutOfBoundsException e){
System.out.println(" ");
}
3
car_Display();
}
os.close();
System.out.println (" saved successfully!");
}
catch(FileNotFoundException e){
System.out.println (" ");
}
catch(IOException e){
System.out.println (" ");
}
catch(Exception e){
System.out.println (" ");
}
// car_Display();
}
public void car_show(){
String item ;
try{
for(int i=0 ; i<count-1; i++ ){
item = carList.get(i++);
System.out.print ("car Number: " + item + " ");
item = carList.get(i++);
System.out.print ("& car Name: " + item + " ");
item = carList.get(i++);
System.out.print ("& car Type: " + item + " ");
item = carList.get(i++);
System.out.print ("& car Price : " + item + " ");
item = carList.get(i);
System.out.print ("& car model: " + item + " ");
System.out.println ();
4
}}
catch(IndexOutOfBoundsException e){
System.out.println(" ");
}
}
line = is.readLine();
}
is.close();
}
catch(FileNotFoundException e){
System.out.println (" ");
}
catch(IOException e){
System.out.println (" ");
}
catch(Exception e){
System.out.println (" ");
}
//car_Display();
car_show();
if(x != 1){
x--;
x = x*5;
x++;
}
try{
System.out.println("Enter car name :- ");
c_name = input.next();
carList.set(x++, c_name);
System.out.println("Enter car Type :- ");
c_name = input.next();
carList.set(x++, c_name);
System.out.println("Enter car Price :- ");
c_name = input.next();
carList.set(x++, c_name);
System.out.println("Enter car model :- ");
c_name = input.next();
carList.set(x, c_name);
}
catch(IndexOutOfBoundsException e){
System.out.println(" ");
}
System.out.println("update Done !");
car_Display();
int x = 0 ;
Scanner input = new Scanner(System.in);
car_show();
System.out.println("Enter car namber :- ");
x = input.nextInt();
if(x != 1){
x--;
x = x*5;
}
try{
carList.remove(x);
carList.remove(x);
carList.remove(x);
carList.remove(x);
carList.remove(x);
6
System.out.println("delete Done !");
}
catch(IndexOutOfBoundsException e){
System.out.println(" ");
}
car_Display();
String item ;
//System.out.println ( carList.size()) ;
Boolean success = false;
try{
for(int i=0 ; i<count-1; i++ ){
if(car_ser.equals(carList.get(i))){
success = true;
i--;
System.out.println (car_ser + " is exists..!" );
item = carList.get(i++);
System.out.print ("car Number: " + item + " ");
item = carList.get(i++);
System.out.print ("& car Name: " + item + " ");
item = carList.get(i++);
System.out.print ("& car Type: " + item + " ");
item = carList.get(i++);
System.out.print ("& car Price : " + item + " ");
item = carList.get(i);
System.out.print ("& car model: " + item + " ");
System.out.println ();
break; }}
if(success == false){
//car_Display();
}
int menus;
Scanner input = new Scanner(System.in);
7
System.out.println("================ Welcome to car System
:==================");
System.out.println("Enter the number of operation ");
System.out.println("Enter 1 for Add a car ");
System.out.println("Enter 2 for Add a Toyota's car ");
System.out.println("Enter 3 for Update a car ");
System.out.println("Enter 4 for Search a car ");
System.out.println("Enter 5 for Delete a car ");
System.out.println("Enter 6 for Print cars ");
System.out.println("Enter 7 for Read from Binary file ");
System.out.println("Enter 8 for Exit & save in file ");
try {
menus = input.nextInt();
String csearch ;
switch (menus) {
case 1:
car_add();
break;
case 2:
Toyota_car tc = new Toyota_car();
tc.car_add();
break;
case 3 :
car_update();
break;
case 4:
System.out.println ("Enter value you want to search :");
csearch =input.next();
car_Search(csearch);
break;
case 5:
car_delete();
break;
case 6:
car_print();
break;
case 7:
car_fread();
break;
case 8:
car_file();
break;
}
}
catch(Exception e)
{
System.out.println(e.toString());
}
8
}
} ;
Toyota_car(){
super();
}
if (this.carList.isEmpty()){
int i = 1;
car_id =1;
String car_no = Integer.toString(i);
carList.add(car_no);}
else{
carList.add("TOYOTA");
System.out.println("Enter " + car_name + " Price :- ");
car_price = input.nextInt();
String car_cost = Integer.toString(car_price);
carList.add( car_cost);
System.out.println("Enter " + car_name + " car model :- ");
car_model = input.nextInt();
String car_amount = Integer.toString(car_model);
carList.add(car_amount);
count += 5;
car_id++;
this.t_count++;
car_Display();
}
};
9
public class carpro {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
car pro = new car();
pro.car_Display();
}
Q1: (10 marks) In chapter 1, you have studied the 7 key concepts of object-
oriented design. You are requested to think about any three of them you are
currently facing (or you faced in the past) then do the following:
اشرح عن اي ثالثة منها، مبادئ اساسية في تصميم الكائنات الموجهة7 في الوحدة االولى درسنا
: و طبق عليها التاليwواجهت خالل البرمجة في هذه المادة
. اشرح اي ثالثة منها بلغتك الخاصة بحيث يعكس استيعابك-1
.اذكري امثلة كود على كيفية استخدامها-2
1-
2- The Central role of the object
Our class is "class car "In the next line we declare an object of the class car
public static void main(String[] args) {
car pro = new car();
this men that we declare copy of the class car that contain all the attributes and the
instance value of the class. Also we can also create an object of a class and access it in
another class.
3- Encapsulation
Also in our project we use Encapsulation the incpculation allow us to hides data from other
class inherited classes . we can access to this data type using an object of the same class it
product or data in the class .
class car
{
private int car_id;
private String car_name ;
private String car_type ;
private int car_price ;
private int car_model;
private int count = 1;
11