منتدى مصر التقني
هل تريد التفاعل مع هذه المساهمة؟ كل ما عليك هو إنشاء حساب جديد ببضع خطوات أو تسجيل الدخول للمتابعة.

تمارين محلولة بالجافا ...Create and implement the methods of the Vehicle, Car, Bike, and MainProgram Classes.

اذهب الى الأسفل

تمارين محلولة بالجافا ...Create and implement the methods of the Vehicle, Car, Bike, and MainProgram Classes.  Empty تمارين محلولة بالجافا ...Create and implement the methods of the Vehicle, Car, Bike, and MainProgram Classes.

مُساهمة من طرف أحمد مناع الثلاثاء مايو 19, 2020 2:21 pm

اهلا وسهلا بكم

أحد الاصدقاء راسلني طالبا حل النشاط التالى :

تمارين محلولة بالجافا ...Create and implement the methods of the Vehicle, Car, Bike, and MainProgram Classes.  Untitl26


Answer the following questions:



(a) Create and implement the methods of the Vehicle, Car, Bike, and MainProgram Classes.


(b) Implement the bahavior of the createVehicles() method to allow the user specify the type of the Vehicle that he/she wishes to create(Vehicle – this will be a generic vehcile, Car or Bike). The user should be able to set (using Mutator or Constructor Methods) the values for the different attributes of each newly created Object. 

 
Implement the saveFile(vehicles:<Vehicle>, path:String) default method in the FileOperator Interface#. This method should be first called in the MainProgram class to save all created vehicles (vehicle names only) in a file on the Hard Disk.


(c) Implement the readFile(path:String): ArrayList<String> method that is defined as an abstract method in the FileOperator Interface. This method should be implemented as a Lambda Expression in the MainProgram class to read all vehicle names from the file that was saved on the Hard Disk.


(d) Implement the convertArrayToArrayList(names: ArrayList<String>):String[] default method in the FileOperator Interface to enable users convert the ArrayList with vehicle names into an Array of Strings.


(e) Implement the printContent(t[]:T):voiddefault method in the FileOperator Interface to enable users print the contents of an array of generic data type. When you call the method in the MainProgram class, you will need to pass the ArrayList with vehicle names as an argument to this method.


(f) Implement the compareCars(c1:Car, c2:Car):int method in the MainProgram class so that the user will be able to compare between two car objects and return the one with the higher price.
 

(g) Implement the cloneBikes(bike:Bike):Bike method in the MainProgram class. The method takes a Bike object as input and return a cloned copy of type Bike.


حل السؤال مع الشرح بعد الافطار ان شاء الله تعالى

ـــــــــــــــــــ التوقيع ــــــــــــــــــــ
سبحان الله وبحمدة .....سبحان الله العظيم
أحمد مناع
أحمد مناع
.
.

تاريخ التسجيل : 15/02/2011
المساهمات : 1108
النقاط : 202034
التقيم : 144
الدولة : مصر
الجنس : ذكر

https://egy-tech.forumegypt.net

الرجوع الى أعلى الصفحة اذهب الى الأسفل

تمارين محلولة بالجافا ...Create and implement the methods of the Vehicle, Car, Bike, and MainProgram Classes.  Empty رد: تمارين محلولة بالجافا ...Create and implement the methods of the Vehicle, Car, Bike, and MainProgram Classes.

مُساهمة من طرف jonuer السبت أغسطس 01, 2020 3:33 pm

@أحمد مناع لو سمحت اخي بتقدر تحل هذا السوال لان هذا السوال عدلي مدة بشتغل عليه ومش زابط لو سمحت بتقدر تحله بسرعة اذا امكن بكرة يعني يوم الاحد 2/8/2020 لو سمحت
jonuer
jonuer
.
.

تاريخ التسجيل : 01/08/2020
المساهمات : 3
النقاط : 3
التقيم : 0
الدولة : مصر
الجنس : ذكر

الرجوع الى أعلى الصفحة اذهب الى الأسفل

تمارين محلولة بالجافا ...Create and implement the methods of the Vehicle, Car, Bike, and MainProgram Classes.  Empty رد: تمارين محلولة بالجافا ...Create and implement the methods of the Vehicle, Car, Bike, and MainProgram Classes.

مُساهمة من طرف أحمد مناع السبت أغسطس 01, 2020 4:49 pm

jonuer كتب:@أحمد مناع لو سمحت اخي بتقدر تحل هذا السوال لان هذا السوال عدلي مدة بشتغل عليه ومش زابط لو سمحت بتقدر تحله بسرعة اذا امكن بكرة يعني يوم الاحد 2/8/2020 لو سمحت

اهلا بيك الاخ الكريم

سوف ارسله لك غدا إن شاء الله تعالى ....على الظيرة ؟يناسبك هذا الموعد ....لان ها الايام اعياد و بحادثك من الجوال وليس الحاسب

ـــــــــــــــــــ التوقيع ــــــــــــــــــــ
سبحان الله وبحمدة .....سبحان الله العظيم
أحمد مناع
أحمد مناع
.
.

تاريخ التسجيل : 15/02/2011
المساهمات : 1108
النقاط : 202034
التقيم : 144
الدولة : مصر
الجنس : ذكر

https://egy-tech.forumegypt.net

الرجوع الى أعلى الصفحة اذهب الى الأسفل

تمارين محلولة بالجافا ...Create and implement the methods of the Vehicle, Car, Bike, and MainProgram Classes.  Empty رد: تمارين محلولة بالجافا ...Create and implement the methods of the Vehicle, Car, Bike, and MainProgram Classes.

مُساهمة من طرف jonuer الأحد أغسطس 02, 2020 7:39 am

@أحمد مناعشكرا الك اخي ويعطيك العافية بناسبني هذا الموعد ويعني مش عارف كيف بدي اشكرك حل السوال كامل صحيح  ويعطيك العافية وهل يوجد لك حساب فيسبوك
jonuer
jonuer
.
.

تاريخ التسجيل : 01/08/2020
المساهمات : 3
النقاط : 3
التقيم : 0
الدولة : مصر
الجنس : ذكر

الرجوع الى أعلى الصفحة اذهب الى الأسفل

تمارين محلولة بالجافا ...Create and implement the methods of the Vehicle, Car, Bike, and MainProgram Classes.  Empty رد: تمارين محلولة بالجافا ...Create and implement the methods of the Vehicle, Car, Bike, and MainProgram Classes.

مُساهمة من طرف jonuer الإثنين أغسطس 03, 2020 7:06 am

@أحمد مناعالسلام عليكم اخي ممكن ترسلي اياه باسرع وقت لو سمحت
jonuer
jonuer
.
.

تاريخ التسجيل : 01/08/2020
المساهمات : 3
النقاط : 3
التقيم : 0
الدولة : مصر
الجنس : ذكر

الرجوع الى أعلى الصفحة اذهب الى الأسفل

تمارين محلولة بالجافا ...Create and implement the methods of the Vehicle, Car, Bike, and MainProgram Classes.  Empty رد: تمارين محلولة بالجافا ...Create and implement the methods of the Vehicle, Car, Bike, and MainProgram Classes.

مُساهمة من طرف أحمد مناع الإثنين أغسطس 03, 2020 1:14 pm

@jonuer


الفئة Vehicle.class

الكود:

package myVehicle;

import java.time.LocalDate;

public class Vehicle {
    
    private String name;
    private LocalDate dateOfManufactuing;

        
     public void setName(String name) {
        this.name = name;
    }

    public String getName() {
        return name;
    }
 
     public void setDateOfManufactuing(LocalDate dateOfManufactuing) {
       this.dateOfManufactuing = dateOfManufactuing;
    }

     public LocalDate setDateOfManufactuing() {
        return dateOfManufactuing;
      
    }

    public int comparecars(Car c1,Car c2){
    
     return  c1.compareTo(c2);
     }



  

 }



الفئة Bike.class

الكود:

import java.time.LocalDate;

public class Bike extends Vehicle implements Cloneable{
      private int id;
      private int gears;
      Vehicle vec;
      
    public Bike(){};
    
    public Bike(int id, int gears, String name, LocalDate dateOfManufactuing) {
        this.id = id;
        this.gears = gears;
    }
      @Override
    public Object clone() throws CloneNotSupportedException{
        try{
            return super.clone();
        }
        catch(Exception e){
            System.out.println("error happend");
        return null;
    }}
    
    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    public int getGears() {
        return gears;
    }

    public void setGears(int gears) {
     this.gears = gears;
    }

  
}


الفئة Car.class

الكود:

import java.time.LocalDate;


public class Car extends Vehicle implements Comparable <Car>{
    private String brand;
    private String color;
    private double price;

    
    public Car(){};
    
    public Car(String brand, String color, double price, String name, LocalDate dateOfManufactuing) {
    this.brand = brand;
    this.color = color;
    this.price = price;
    }

    public String getBrand() {
        return brand;
    }

    public void setBrand(String brand) {
    this.brand = brand;
    }

    public String getColor() {
        return color;
    }

    public void setColor(String color) {
    this.color = color;
    }

    public double getPrice() {
        return price;
    }

    public void setPrice(double price) {
     this.price = price;
    }

  
    @Override
    public int compareTo(Car other) {
      if(this.price>other.price)
        return 1;
    else
        if(this.price<other.price)
            return -1;
    return 0;  
    }

}


الواجهة FileOperator

الكود:

import java.util.ArrayList;


public interface FileOperator  {
 
    
    
     <T> void printContent(T[] t) ;
    
     void saveFile(ArrayList<Vehicle>vehicles,String path);
     abstract ArrayList<String> readFile(String path);
     String[] convertArrayToArrayList( ArrayList<String>names);
    
}


الفئة MainProgram

الكود:

import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.FileReader;
import java.io.PrintWriter;
import java.time.LocalDate;
import java.time.Year;
import java.time.format.DateTimeFormatter;
import java.util.ArrayList;
import java.util.Scanner;
import java.util.logging.Level;
import java.util.logging.Logger;


public class MainProgram implements FileOperator{

    static ArrayList<Vehicle> vehicles = new ArrayList<>();
    static ArrayList<String> names= new ArrayList<>();
    
    public static void main(String[] args) {
    
     MainProgram main = new MainProgram();
    
     System.out.println("           Welcome to our system");
     System.out.println("");
      main.menu();
    
     Scanner input=new Scanner(System.in);
     int choice= input.nextInt();
     switch (choice){

     case 0:
         System.exit(0);
         break;
     case 1:
        main.createVehicles();
        break;
  
     case 2:
        main.saveFile(vehicles, "output.txt");
      
         break;
     case 3:
          names = main.readFile("output.txt");
         break;
     case 4:
         String []nameOfvehicles = main.convertArrayToArrayList(names);
         main.printContent(nameOfvehicles);
         break;    
     default:
         System.out.println("Invalid Entry!");
     }
      
          
    }
  
    void menu(){
    
     System.out.println("           MAIN MENU FOR THE SYSTEM");
     System.out.println("===============================================");
     System.out.println("1. Create Vehicles");
     System.out.println("2. Save Vehicle Names Into Text File");
     System.out.println("3. Read Vehicle Names Form Text File");
     System.out.println("4. Print Content");
     System.out.println("0. Exit");
     System.out.println("===============================================");
     System.out.println("Please Enter From The Above List:");
    }
    public  void createVehicles() {
        
        
     Scanner scnr = new Scanner(System.in);
     DateTimeFormatter Format = DateTimeFormatter.ofPattern("yyyy");
    
     System.out.println("1. Bicycle");
     System.out.println("2. Car");
     System.out.println("3. Main Menu");
     System.out.println("4. Exit");
     System.out.println("Enter the type of the Vehicle that youe wishes to create:");
  
     Scanner input=new Scanner(System.in);
     int choice= input.nextInt();
     switch (choice){

     case 1:
        
      
        Bike B = new Bike();
        
        System.out.println("Enter vehicle Name:");
        B.setName(scnr.nextLine());
        System.out.println("Please set the Bicycle ID:");
        B.setId(scnr.nextInt());
        System.out.println("Enter The Bicycle model_format 2020:");
        String dt =scnr.next();
        LocalDate date = Year.parse(dt, Format).atDay(1);
        B.setDateOfManufactuing(date);
        System.out.println("Please set the Bicycle Gears:");
        B.setGears(scnr.nextInt());
      
        
        vehicles.add(B);
          
        
         break;
        
        
     case 2:
        
        Car C = new Car();
        System.out.println("Enter vehicle Name:");
        C.setName(scnr.nextLine());
        System.out.println("Please set the car brand:");
        C.setBrand(scnr.nextLine());
        System.out.println("Enter The Car model:");
        String dt1 =scnr.next();
        LocalDate date1 = Year.parse(dt1, Format).atDay(1);
        C.setDateOfManufactuing(date1);
        System.out.println("Please set the car color:");
        C.setColor(scnr.nextLine());
        System.out.println("PPlease set the price of the car:");
        C.setPrice(scnr.nextDouble());
        
        vehicles.add(C);
         break;
     case 3:
         menu();
         break;  
     case 4:
         System.exit(0);
         break;
     default:
         System.out.println("Invalid Entry!");
     }
      
         System.out.println();
         System.out.println("The Vehicle has been successfully creating");
         System.out.println();
         System.out.println("        Choose from the following Menu         ");
         System.out.println("===============================================");
         System.out.println("1: Save Vehicle Names Into Text File.");
         System.out.println("0: Exit.");
          int option = input.nextInt();
            
            switch (option) {
            case 1:saveFile(vehicles, "output.txt"); break;      
            case 0: System.exit(0); break;
            default: System.out.println("Wrong Selection, Please try again.");
      
         }  
        
      
    }

    @Override
    public <T> void printContent(T[] t) {
       for (T element : t){
            System.out.println(element);
        }
      
    
    }

    @Override
    public void saveFile(ArrayList<Vehicle> vehicles, String path) {
      
        PrintWriter pw = null;
         try {
             pw = new PrintWriter(new FileOutputStream(path));
             for (Vehicle V : vehicles)
                 pw.println(V.getName());
             pw.close();
         } catch (FileNotFoundException ex) {
             Logger.getLogger(MainProgram.class.getName()).log(Level.SEVERE, null, ex);
         } finally {
             pw.close();
         }
         System.out.println("The data has been saved to the file successfully");
        
    }

    @Override
    public ArrayList<String> readFile(String path) {
        
    
       ArrayList <String> names = new ArrayList<>();
       try{
  
           try (BufferedReader reader = new BufferedReader(new FileReader(path))) {
               String line;
               while ((line = reader.readLine()) != null)
               {
                   names.add(line);
               } }
         return names;
         }
        catch (Exception e)
        {
    System.err.format("Exception occurred trying to read '%s'.", path);
    return null;
  }
        
        
    }

    @Override
    public String[] convertArrayToArrayList(ArrayList<String> names) {
      
        String[] array = names.toArray(new String[0]);
        return array;
    
    }
    
  
}



طبعا الفئة الرئسية MainProgram شوية تعديلات بسيطة .....سعاود تعديلها لانى حاليا مطر للخروج

ـــــــــــــــــــ التوقيع ــــــــــــــــــــ
سبحان الله وبحمدة .....سبحان الله العظيم
أحمد مناع
أحمد مناع
.
.

تاريخ التسجيل : 15/02/2011
المساهمات : 1108
النقاط : 202034
التقيم : 144
الدولة : مصر
الجنس : ذكر

https://egy-tech.forumegypt.net

الرجوع الى أعلى الصفحة اذهب الى الأسفل

تمارين محلولة بالجافا ...Create and implement the methods of the Vehicle, Car, Bike, and MainProgram Classes.  Empty احتاج الى مساعده بالجافا

مُساهمة من طرف العريقي١ الجمعة مايو 21, 2021 3:36 am

اولا السلام عليكم 
احتاج لمساعدة لدي اختبار بعد ساعتين من الان اختبار بالجافا درست سنة أولى I.T وثم اكملت الدراسه C.S
ولكن لم اتمكن من اللحاق ببعض المحاضرات بالجافا بسبب التشديد بالمطارات اتاخرت بالسفر والان احتاج لبعض المساعده فضلا منكم لمن يقدر ان يساعدني لا يبخل 
وتحياتي لكم من اليمن 

ملاحظه طريقة الاختبار ستكون كالاتي هذه هو سنبل الاختبار

صفحه ١
Sample ExamII CSCI300 - Fall 2020
Part I: Implement the following classes
Consider the following UML diagram for an application that manages spheres in the 3D space.
Question 1:
Create the class Point
 Implement the no-arg and all-arg constructors.
 Implement the calculateDistance method that returns the distance between
two points.
 Implement the isEqual method that returns true if all coordinates are equal in both
points and false otherwise.
 Implement the toString() method. If x=2.0, y=3.5, and z=4.0, then the method
returns a string in the form: (2.0, 3.5, 4.0)
Question 2:
Create the class Sphere
 Implement the two constructors.
 The no-arg constructor should initialize the color to “black”, the radius to 1.0,
and the center to (0.0, 0.0, 0.0).
 Implement the getCenter method that returns the center of the sphere. Don’t
implement the rest of getters and setters.
 Implement the method calculateVolume() that returns the volume of the
sphere.
Sphere
-radius: double
-center: Point
-color: String
+Sphere( )
+Sphere (radius: double, center: Point,
color: String)
+getCenter( ):Point
+calculateVolume(): double
+isEqual(sphere:Shpere):boolean
+toString(): String
Point
-x: double
-y: double
-z: double
+Point( )
+Point(x: double, y: double, z: double)
+calculateDistance(point :Point) :double
+isEqual(point : Point) :boolean
+toString(): String



صفحه ٢
푉표푚푢푛푓 =
4
3
× 휋 × 푠푎푒푖푢푡3
 Implement the isEqual method that returns true if both spheres have the same
center and radius and false otherwise.
 Override the toString() method. The method returns a string in the form:
Sphere{Radius:2.0, Center:(1.0, 2.0, 3.0), Color:RD, Volume:33.49333}. Note that
you should only display the first and last letters of the color capitalized.
Part II: Write an application (driver program) for the classes in Part I
Complete the application (driver class) TestSphere as requested below.
Write code to perform the following operations:
a) Create an array of 3 spheres.
b) Ask the user to enter the radius, color, and center coordinates for these spheres:
 Create them.
 Store them inside the array.
c) Print the information of all spheres (using the toString() method)
d) Print the number of spheres with volume greater than 50.
e) Print whether or not the first and last spheres are equal.
f) Print the distance between the centers of the second and last spheres.
العريقي١
العريقي١
..
..

تاريخ التسجيل : 21/05/2021
المساهمات : 12
النقاط : 22
التقيم : 0
الدولة : اليمن
الجنس : أخرى / أرفض التصريح

الرجوع الى أعلى الصفحة اذهب الى الأسفل

الرجوع الى أعلى الصفحة

ََ

مواضيع ذات صلة


 
صلاحيات هذا المنتدى:
لاتستطيع الرد على المواضيع في هذا المنتدى