DOUBT OF INHERITANCE IN JAVA(SMALL)

Asked

Viewed 66 times

-3

You were hired to develop a system for a motorcycle workshop, cars and trucks. Your first task will be to build a set of classes for represent the vehicles that will be met in the workshop. having regard to the concepts of inheritance, encapsulation and composition seen in class, create a set of classes for such vehicles: - A vehicle can be a motorcycle, car or truck; - each vehicle has a plate; - vehicles contain two, four or more wheels; • Each wheel has a diameter, width and serial number; - each vehicle has several screws; • A bolt has a diameter, height and a serial number. I JUST NEED AN IDEA OF HOW TO CREATE THESE CLASSES

  • Dude, it’s good for you to read before or watch some heritage videos, I don’t know what your knowledge on the subject, but try to study a little, if you like: https://www.devmedia.com.br/understanding- and application-heranca-em-java/24544

  • The "idea" is already in the announced. What is your doubt?

  • I believe his doubt is: "Which classes should I create and which attributes"

1 answer

1

Going by parts, I believe you should create a parent class Veículos, with the attributes: placa, roda(which must be of the rodas) and parafuso (which must be of the screw type);

Create the subclasses motos, carros and caminhões -- These subclasses must extend the parent class;

I would create a class rodas that receives the attributes diâmetro, largura and número de série;

It would also create the screw class that receives the attributes diâmetro, altura and número de série;

I’m giving you an "idea", but you should study several things before you do your job or task, I don’t know, things like: encapsulamento, learn to create a objeto de uma classe, create the methods get and set for each attribute (you must also learn to use these methods), you must learn extends also, I believe that’s it, good luck.

  • I already know all the concepts, the point is that I did this everything that Oce said but the teacher said it was not totally correct and as it is a challenge,

  • the biggest doubt msm was which class I inherited from which, but I did it msm you spoke int now n know msm where I went wrong since he did not speak

  • No more description? No method? maybe it’s something like making the attributes private, but I have no idea, tell me when he tells me what the mistake was

  • type in the vehicle class I have the attribute plate that is of all, I passed in the builder of the plate class the value of it ,all normal, and as all classes inherit from vehicle I would have to call the vehicle builder within the other classes like car, motorcycle etc

  • public class veiculos { private long placa; public veiculos(long placa) { this.placa = placa; }

  • public class car extends vehicles { public car(long plate) { super(plate); } } //and so my car class was like the other tbm, there must be something else in them?

  • It is likely that the manufacturer in the vehicle class is not necessary, the vehicle class must be of the abstract type, as it will not be instantiated I believe. I also believe that this way is good, I can imagine what your teacher wants

  • public class carro extends veiculos { public carro(long placa) { this.placa; } //I would do so because there is no constructor needed in the parent class

  • this is the rest of the statement

  • Also, in the class representing the vehicle create methods to add, search (by serial number), delete (from & #Xa;the serial number) each element that makes up the vehicle.

  • but these methods do not interfere in the ultlization of inheritance because after all I will only call them, and I believe they are right because I have created them several times

  • 2

    @Jeffhenrique, your answer would be better structured if you created the classes and not only informed the attributes, thus, both his problem and the answer, would become more conclusive

  • @Ivansilva what he asked was an "idea" of how to create, I showed my idea of how it could be done, but thanks for the tip

Show 8 more comments

Browser other questions tagged

You are not signed in. Login or sign up in order to post.