Question

Draw the UML class diagram in Java and write the equivalent Java code.

Exercise 6 Person + name: string + age : int=0 Student + grades: list Professor + listofstudents : list

Exercise 6 


Person 

+ name: string 

+ age : int=0 


Student 

+ grades: list 


Professor 

+ listofstudents : list

1 0
Add a comment Improve this question Transcribed image text
✔ Recommended Answer
Answer #1

CODE:

import java.util.ArrayList;

class Person {

    // class datamembers

    public String name;

    public int age;

    // default constructor

    Person() {

        age = 0;

    }

}

// Student class inherits from Person

class Student extends Person {

    public ArrayList grades;

}

// Professor class inherits from Person

class Professor extends Person {

    public ArrayList listOfStudents;

}

1 import java.util.ArrayList; 2 3 4 class Person { // class datamembers public String name; public int age; 5 6 7 8 9 // defa

Please upvote if you like my answer and comment below if you have any queries or need any further explanation.

Add a comment
Know the answer?
Add Answer to:
Draw the UML class diagram in Java and write theequivalent Java code.Exercise 6 Person...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Similar Homework Help Questions
  • JAVA PLEASE HELP The following is a UML diagram for a class. Write the code for...

    JAVA PLEASE HELP The following is a UML diagram for a class. Write the code for this class. Cat - breed : String - color : Color - name : String + Cat( name : String) + Cat(name : String, breed : String, color : Color) + getName() : String + getColor() : Color + getBreed() : String setColor(Color) setBreed(Breed) toString()

  • 1) This exercise is about Inheritance (IS-A) Relationship. A) First, draw the UML diagram for class...

    1) This exercise is about Inheritance (IS-A) Relationship. A) First, draw the UML diagram for class Student and class ComputerSystemsStudent which are described below. Make sure to show all the members (member variables and member functions) of the classes on your UML diagram. Save your UML diagram and also export it as a PNG. B) Second, write a program that contains the following parts. Write each class interface and implementation, in a different .h and .cpp file, respectively. a) Create...

  • 1. Write a class that represents a Recipe as shown in the UML diagram below. Recipe...

    1. Write a class that represents a Recipe as shown in the UML diagram below. Recipe -name: string -cookTime: int -prepTime: int - ingredients: ArrayList<String> +Recipe(String name, int cTime, int pTime, String... ingredients) +Recipe(String name, int cTime, int pTime) +getNumberOfIngredients(): int +addIngredient(String ingredient): void +getName(): String +getTotalRecipeTime(): int +get Ingredient(int index): String +remove Ingredient(String ingredient): String

  • Consider the following partial UML class diagram for the class Student:

    Consider the following partial UML class diagram for the class Student:Student-studentID: String-name: String-school: String+validateStudentID (s: Student):boolean studentID is a string that consists of a letter representing the school followed by 5 digits. The codes used for the schools in this scenario are shown below:SchoolCodeExample of student IDFASC'A'"A12345" refers to a student from FASC.FAFB'B'"B88888" refers to a student from FAFB.Write the code for the method validateStudentID (Student student) such that it performs validations on the parameter's student ID to ensure that:- the...

  • Create a UML diagram to help design the class described in exercise 3 below. Do this...

    Create a UML diagram to help design the class described in exercise 3 below. Do this exercise before you attempt to code the solution. Think about what instance variables will be required to describe a Baby class object; should they be private or public? Determine what class methods are required; should they be private or public? Write Java code for a Baby class. A Baby has a name of type String and an age of type integer. Supply two constructors:...

  • Draw the UML DIAGRAM ALSO PLEASE DRAW THE UML DIAGRAM.ALSO in java should use the program in java For this task you will create a Point3D class to represent a point that has coordinates in thr...

    Draw the UML DIAGRAM ALSO PLEASE DRAW THE UML DIAGRAM.ALSO in java should use the program in java For this task you will create a Point3D class to represent a point that has coordinates in three dimensions labeled x, y and z. You will then use the class to perform some calculations on an array of these points. You need to draw a UML diagram for the class (Point3D) and then implement the class The Point3D class will have the...

  • What this Lab Is About: Given a UML diagram, learn to design a class Learn how...

    What this Lab Is About: Given a UML diagram, learn to design a class Learn how to define constructor, accessor, mutator and toStringOmethods, etc Learn how to create an object and call an instance method. Coding Guidelines for All ments You will be graded on this Give identifiers semantic meaning and make them easy to read (examples numStudents, grossPay, etc) Keep identifiers to a reasonably short length. Use upper case for constants. Use title case (first letter is u case)...

  • Draw a UML class diagram (with associations) to show the design of the Java application. public...

    Draw a UML class diagram (with associations) to show the design of the Java application. public class OOPExercises {     public static void main(String[] args) {         //A objA = new A();         B objB = new B();         System.out.println("in main(): ");         //System.out.println("objA.a = "+objA.getA());         System.out.println("objB.b = "+objB.getB());         //objA.setA (222);         objB.setB (333.33);         //System.out.println("objA.a = "+objA.getA());         System.out.println("objB.b = "+objB.getB());     } } public class A {     int a = 100;     public A() {...

  • Write a Java class named Employee to meet the requirements described in the UML Class Diagram...

    Write a Java class named Employee to meet the requirements described in the UML Class Diagram below: Note: Code added in the toString cell are not usually included in a regular UML class diagram. This was added so you can understand what I expect from you. If your code compiles cleanly, is defined correctly and functions exactly as required, the expected output of your program will solve the following problem: “An IT company with four departments and a staff strength...

  • using java Develop the classes and interface represented in the following UML diagram: <cinterface >> Passenger...

    using java Develop the classes and interface represented in the following UML diagram: <cinterface >> Passenger 1 String name has passengers String getNamel) String getFaro Typel) String getName() void display Passengers Person String frame String last Name intage Note that the Person class includes both a first and last name, but the Passenger interface requires a full name. The field fare Type is determined by a passenger's age: "Regular fare is the full fare, "Youth" is a reduced fare for...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
Active Questions
ADVERTISEMENT