Question

In: Computer Science

Draw a UML diagram for the classes. Code for UML: // Date.java public class Date {...

Draw a UML diagram for the classes.

Code for UML:

// Date.java

public class Date {
  
   public int month;
   public int day;
   public int year;

   public Date(int month, int day, int year) {
   this.month = month;
   this.day = day;
   this.year = year;
   }
  
   public Date() {
   this.month = 0;
   this.day = 0;
   this.year = 0;
   }
}

//end of Date.java

// Name.java

public class Name {
  
   public String fname;
   public String lname;

   public Name(String fname, String lname) {
   this.fname = fname;
   this.lname = lname;
   }
  
   public Name() {
   this.fname = "";
   this.lname = "";
   }
}

//end of Name.java

// Address.java

public class Address {
  
   public String street ;
   public String state ;
   public String city;
   public int zipcode;

   public Address(String street, String state, String city, int zipcode) {
   this.street = street;
   this.state = state;
   this.city = city;
   this.zipcode = zipcode;
   }
  
   public Address() {
   this.street = "";
   this.state = "";
   this.city = "";
   this.zipcode = 0;
   }
}

//end of Address.java

// Employee.java

public class Employee {
  
   public int number;
   public Date mydate;
   public Address myadress;
   public Name myname;

   public Employee(int number, Name myname, Date mydate, Address myadress) {
   this.number = number;
   this.mydate = mydate;
   this.myadress = myadress;
   this.myname = myname;
   }
  
   public Employee() {
   this.number = 0;
   this.mydate = new Date();
   this.myadress = new Address();
   this.myname = new Name();
   }
  
   // method to display the details of the Employee
   public void display()
   {
       System.out.println("Number: "+number);
       System.out.println("Name: "+myname.fname+" "+myname.lname);
       System.out.println("Data: "+mydate.month+"/"+mydate.day+"/"+mydate.year);
       System.out.println("Address: "+myadress.street+" "+myadress.city+", "+myadress.state+", "+myadress.zipcode);
   }
}
// end of Employee.java

// SalariedEmployee.java

public class SalariedEmployee extends Employee
{
   public double salary;
  
   // parameterized constructor
   public SalariedEmployee(int number, Name myname, Date mydate, Address myadress, double salary)
   {
       super(number, myname, mydate, myadress); // call Employee's constructor
       this.salary = salary;
   }
  
   // default constructor
   public SalariedEmployee()
   {
       super();
       this.salary = 0;
   }
  
   // override Employee's display method to display the additional details
   public void display()
   {
       super.display();
       System.out.printf("Salary: $%,.2f\n",salary);
   }
}
//end of SalariedEmployee.java

// HourlyEmployee.java

public class HourlyEmployee extends Employee
{
   public double pay_rate;
   public int hours_worked;
   public double earnings;
  
   // parameterized constructor
   public HourlyEmployee(int number, Name myname, Date mydate, Address myadress, double pay_rate, int hours_worked)
   {
       super(number, myname, mydate, myadress);
       this.pay_rate = pay_rate;
       this.hours_worked = hours_worked;
       // calculate earnings
       if(hours_worked <= 40) // no overtime
           earnings = this.pay_rate*this.hours_worked;
       else // overtime
           earnings = this.pay_rate*40 + (this.hours_worked-40)*1.5*this.pay_rate;
   }
  
   // default constructor
   public HourlyEmployee()
   {
       super();
       pay_rate = 0;
       hours_worked = 0;
       earnings = 0;
   }
  
   // override display method
   public void display()
   {
       super.display();
       System.out.printf("Pay rate: $%,.2f\n",pay_rate);
       System.out.println("Hours Worked: "+hours_worked);
       System.out.printf("Earnings: $%,.2f\n",earnings);
   }
}
//end of HourlyEmployee.java

// Employeeinfo.java

public class Employeeinfo {
  
   public static void main(String[] args)
   {
       // create SalariedEmployee
       SalariedEmployee s = new SalariedEmployee(12, new Name("Shaun","Marsh"), new Date(11, 7, 1995), new Address("Street1","State1","City1",70081), 75000);

       // create HourlyEmployee without any overtime
       HourlyEmployee h1 = new HourlyEmployee(15, new Name("Harry","Doe"), new Date(7, 16, 2000), new Address("Street2","State2","City2",60181), 45.75, 35);

       // create HourlyEmployee with overtime
       HourlyEmployee h2 = new HourlyEmployee(25, new Name("Jerry","Hope"), new Date(10, 16, 2007), new Address("Street3","State3","City3",80111), 45.75, 45);
      
       // display the details
       s.display();
       System.out.println();
       h1.display();
       System.out.println();
       h2.display();
   }

}


//end of Employeeinfo.java

Solutions

Expert Solution

Step 1:Date, Address, and Name are used as attributes in Employee, we introduce a dependency relationship

Step 2:Since there is a parent /Child relationship between Employee(Parent) and SalariedEmployee(Child) and HoulrlyEmployee(Child) we introduce the Generalization relationship.

Step 3:Since we are using SalariedEmployee and HourlyEmployee in Employeeinfo we introduce a dependency relationship.

The UML Class Diagram is :


Related Solutions

(Using Date Class) The following UML Class Diagram describes the java Date class: java.util.Date +Date() +Date(elapseTime:...
(Using Date Class) The following UML Class Diagram describes the java Date class: java.util.Date +Date() +Date(elapseTime: long) +toString(): String +getTime(): long +setTime(elapseTime: long): void Constructs a Date object for the current time. Constructs a Date object for a given time in milliseconds elapsed since January 1, 1970, GMT. Returns a string representing the date and time. Returns the number of milliseconds since January 1, 1970, GMT. Sets a new elapse time in the object. The + sign indicates public modifer...
create the UML Diagram to model a Movie/TV viewing site. Draw a complete UML class diagram...
create the UML Diagram to model a Movie/TV viewing site. Draw a complete UML class diagram which shows: Classes (Only the ones listed in bold below) Attributes in classes (remember to indicate privacy level, and type) No need to write methods Relationships between classes (has is, is a, ...) Use a program like Lucid Cart and then upload your diagram. Each movie has: name, description, length, list of actors, list of prequals and sequals Each TV Show has: name, description,...
Draw a UML diagram that describes a class that will be used to describe a product...
Draw a UML diagram that describes a class that will be used to describe a product for sale on Glamazon.com. The product has a name, a description, a price, ratings by many customers (1 to 5 stars), and a group of customer comments. New products have no ratings or comments by customers, but do have a name, description and price. The price can be changed and more customer ratings and comments can be added. A global average rating of all...
UML Diagram for this java code //java code import java.util.*; class Message { private String sentence;...
UML Diagram for this java code //java code import java.util.*; class Message { private String sentence; Message() { sentence=""; } Message(String text) { setSentence(text); } void setSentence(String text) { sentence=text; } String getSentence() { return sentence; } int getVowels() { int count=0; for(int i=0;i<sentence.length();i++) { char ch=sentence.charAt(i); if(ch=='a' || ch=='e' || ch=='i' || ch=='o' || ch=='u' || ch=='A' || ch=='E' || ch=='I' || ch=='O' || ch=='U') { count=count+1; } } return count; } int getConsonants() { int count=0; for(int i=0;i<sentence.length();i++)...
Please perform reverse engineering to compose a UML class diagram for the provided java code /*...
Please perform reverse engineering to compose a UML class diagram for the provided java code /* Encapsulated family of Algorithms * Interface and its implementations */ public interface IBrakeBehavior { public void brake(); } public class BrakeWithABS implements IBrakeBehavior { public void brake() { System.out.println("Brake with ABS applied"); } } public class Brake implements IBrakeBehavior { public void brake() { System.out.println("Simple Brake applied"); } } /* Client that can use the algorithms above interchangeably */ public abstract class Car {...
<<<<<<<<. I need the UML diagram for all classes.java below. >>>>> // Vehicle.java public class Vehicle...
<<<<<<<<. I need the UML diagram for all classes.java below. >>>>> // Vehicle.java public class Vehicle {    // data members declared as private    private String make;    private double weight;    private double height;    private double length;    private int maxSpeed;    private int noOfDoors;    private int numberSeats;    /**    * @param make    * @param weight    * @param height    * @param length    * @param maxSpeed    * @param noOfDoors    *...
Draw UML diagram Define a class named Document that contains a member variable of type string...
Draw UML diagram Define a class named Document that contains a member variable of type string named text that stores any textual content for the document. Create a function named getText that returns the text field and a way to set this value. Next, define a class for Email that is derived from Document and that includes member variables for the sender , recipient , and title of an e-mail message. Implement appropriate accessor and mutator functions. The body of...
Write two classes, ToDoList and Driver ToDoList should implement the following UML class diagram: ToDoList -list:String[]...
Write two classes, ToDoList and Driver ToDoList should implement the following UML class diagram: ToDoList -list:String[] -size:int +ToDoList() +add(String item):void +remove(String item): boolean +toString():String add(String item) should add the item as the last element in the list, updating size. remove(String item) should remove the item and return true, or, if the item was not in the list, return false.   To remove the item, check every list element from 0 to size-1, and if that item is equal to the parameter...
Use the UML tool to draw a UML class diagrambased on the descriptions provided below....
Use the UML tool to draw a UML class diagrambased on the descriptions provided below.The diagram should be drawn with a UML toolIt should include all the classes listed below and use appropriate arrows to identify the class relationshipsEach class should include all the described attributes and operations but nothing elseEach constructor and method should include the described parameters and return types - no more and no lessPlease do one of the following in JavaDescriptions of a PriceBecause of the...
NEed UML diagram for this java code: import java.util.ArrayList; import java.util.Scanner; class ToDoList { private ArrayList<Task>...
NEed UML diagram for this java code: import java.util.ArrayList; import java.util.Scanner; class ToDoList { private ArrayList<Task> list;//make private array public ToDoList() { //this keyword refers to the current object in a method or constructor this.list = new ArrayList<>(); } public Task[] getSortedList() { Task[] sortedList = new Task[this.list.size()];//.size: gives he number of elements contained in the array //fills array with given values by using a for loop for (int i = 0; i < this.list.size(); i++) { sortedList[i] = this.list.get(i);...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT