1. The system design will include a class named User to represent a user. That c
ID: 3728413 • Letter: 1
Question
1. The system design will include a class named User to represent a user. That class should i nclu and a list containing the IDs of the watched iter The class should include a method for computing the number of similar items between two use To allow for representing diverse items, the system will include an abstract class named Item represent a generic item. This class will include the item's ID, name and description. 2. 3. To represent movie items, the system will include a class named Movie that inherits from t abstract Item class. It will include the movie's genre and director. L Diagram for the System Design: User Item ID: int - name: String n items: int - Items: intll # ID: int # name: String # description: String +get ID):int +set ID(i: int) void +get name):String +set name(n: String) void +get n itemsÜ:int +set n items(i: int):void +add item(i: int):void +similarity():int +get ID():int +set ID(ü: int):void +get name) String +set name(n: String):void +get_description():String +set description(d strind):void Movie genre: String director: String +get genre)-String +set-genre(n: String):void +get director():String +set director(n: String):void RecApp +main(args: String[):void call the meanings of the UML Symbols: rivate ublic rotectedExplanation / Answer
public class RecApp {
public static void main(String[] args) {
// TODO Auto-generated method stub
Movie m1,m2,m3;
m1 = new Movie("Science","Christopher Nolan",1000,"Interstellar", "A team of explorers travel through a wormhole in space in an attempt to ensure humanity's survival. ");
m2 = new Movie("Crime","Martin Scorsese ",1001,"Taxi Driver","A mentally unstable veteran works as a nighttime taxi driver in New York City, where the perceived decadence and sleaze fuels his urge for violent action, while attempting to liberate a twelve-year-old prostitute. ");
m3 = new Movie("Drama","Francis Ford Coppola",1003,"The Conversation","A paranoid, secretive surveillance expert has a crisis of conscience when he suspects that a couple, on whom he is spying, will be murdered.");
User u1,u2;
Item[] item1 = new Item[2];
item1[0] = m1;
item1[1] = m2;
Item[] item2 = new Item[1];
item2[0] = m1;
u1 = new User(100,"Vinoth",2,item1);
u2 = new User(101,"Peter",1,item2);
System.out.print("No of similar items: " +u1.similarity(u2));
}
}
----------------------------
public class User {
int id;
String name;
int no_of_items;
Item items[];
static int OBJECT_COUNT = 0;
public User(int id,String name,int no,Item[] its){
this.id = id;
this.name = name;
this.no_of_items = no;
this.items = its;
OBJECT_COUNT ++;
System.out.println("Initialization successful for USer object " + name);
System.out.println("No of user object created " + OBJECT_COUNT);
}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getNo_of_items() {
return no_of_items;
}
public void setNo_of_items(int no_of_items) {
this.no_of_items = no_of_items;
}
public Item[] getItems() {
return items;
}
public void setItems(Item[] items) {
this.items = items;
}
public int similarity(User u){
int thismovieCount = this.items.length;
int uMocieCount = u.items.length;
int similarCount = 0;
if(thismovieCount > uMocieCount){
for(int i=0;i<uMocieCount;i++){
for(int j=0;j<thismovieCount;j++)
if((u.items[i].getName()).equalsIgnoreCase(this.items[j].getName()))
similarCount++;
}
}else
{
for(int i=0;i<thismovieCount;i++){
for(int j=0;j<uMocieCount;j++)
if((this.items[i].getName()).equalsIgnoreCase(u.items[j].getName()))
similarCount++;
}
}
return similarCount;
}
}
-------------------------
public class Movie extends Item{
String genre;
String director;
public Movie(String genre,String director,int id, String name, String desctption){
this.id = id;
this.name = name;
this.director = director;
this.genre = genre;
this.description = description;
System.out.println("Initialization successfull for Movie object");
}
public String getGenre() {
return genre;
}
public void setGenre(String genre) {
this.genre = genre;
}
public String getDirector() {
return director;
}
public void setDirector(String director) {
this.director = director;
}
}
------------------------------------
package com.vinoth.chegg2702;
public abstract class Item {
int id;
String name;
String description;
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
}
-----------------------------------------------
Output:
Initialization successfull for Movie object
Initialization successfull for Movie object
Initialization successfull for Movie object
Initialization successful for USer object Vinoth
No of user object created 1
Initialization successful for USer object Peter
No of user object created 2
No of similar items: 1
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.