please write program in java and comment the code clearly. I am providing previous classes Media and payment codes to be used for this class.(its not a big code to write , it seems ,because i added previous classes , pleases help.
public class Media {
String name;
int year;
// a constructor which initializes the media with the provided name
and publication year.
public Media(String name, int year) {
this.name = name;
this.year = year;
}
// retrieves the stored name of the media.
public String getName() {
return this.name;
}
// retrieves the stored year of the media.
public int getYear() {
return this.year;
}
@Override
public boolean equals(Object other)
{
// checking if both the object references are
// referring to the same object.
if(this == other)
return true;
// it checks if the argument is of the
// type Media by comparing the classes
// of the passed argument and this object.
// if(!(other instanceof Media)) return false;
if(other == null || other.getClass()!= this.getClass())
return false;
// type casting of the argument.
Media media = (Media) other;
// comparing the state of argument with
// the state of 'this' Object.
return (media.name == this.name && media.year ==
this.year);
}
// It is sufficent for this method to return
getName().hashCode().
public int hashCode() {
return getName().hashCode();
}
// displays information about the media as a string, in the format
"NAME (YEAR)".The Imitation Game(2014)
public String toString() {
return this.name + " (" + this.year + ")";
}
}
public class Payment {
String cardNo;
String name;
int expMonth;
int expYear;
public Payment(String cardNo, String name, int expMonth, int
expYear) {
this.cardNo = cardNo;
this.name = name;
this.expMonth = expMonth;
this.expYear = expYear;
}
public String getCardNo() {
return cardNo;
}
public String getName() {
return name;
}
public int getExpMonth() {
return expMonth;
}
public int getExpYear() {
return expYear;
}
@Override public String toString() {
return "#" + this.cardNo + " (" + this.name + ")" + ", " + "exp " +
this.expMonth +"/"+ this.expYear;
}
}
I need help with the claasess below
public class Rental
The class should contain the following:
Period.between(firstDate, secondDate).getDays()
The Imitation Game (2014) DVD [PG-13, 114 min], rented on 2019-09-15 using #0011223344556677 (George Mason), exp 10/2025
DailyRental Task:
public class DailyRental extends Rental
this class will contain the following methods:
Solution)=>
Program:-
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.concurrent.TimeUnit;
class Media {
String name;
int year;
// a constructor which initializes the media with the provided name
and publication year.
public Media(String name, int year) {
this.name = name;
this.year = year;
}
// retrieves the stored name of the media.
public String getName() {
return this.name;
}
// retrieves the stored year of the media.
public int getYear() {
return this.year;
}
@Override
public boolean equals(Object other)
{
// checking if both the object references are
// referring to the same object.
if(this == other)
return true;
// it checks if the argument is of the
// type Media by comparing the classes
// of the passed argument and this object.
// if(!(other instanceof Media)) return false;
if(other == null || other.getClass()!= this.getClass())
return false;
// type casting of the argument.
Media media = (Media) other;
// comparing the state of argument with
// the state of 'this' Object.
return (media.name == this.name && media.year ==
this.year);
}
// It is sufficent for this method to return
getName().hashCode().
public int hashCode() {
return getName().hashCode();
}
// displays information about the media as a string, in the format
"NAME (YEAR)".The Imitation Game(2014)
public String toString() {
return this.name + " (" + this.year + ")";
}
}
class Payment {
String cardNo;
String name;
int expMonth;
int expYear;
public Payment(String cardNo, String name, int expMonth, int
expYear) {
this.cardNo = cardNo;
this.name = name;
this.expMonth = expMonth;
this.expYear = expYear;
}
public String getCardNo() {
return cardNo;
}
public String getName() {
return name;
}
public int getExpMonth() {
return expMonth;
}
public int getExpYear() {
return expYear;
}
@Override public String toString() {
return "#" + this.cardNo + " (" + this.name + ")" + ", " + "exp " +
this.expMonth +"/"+ this.expYear;
}
}
class Rental {
private Media media;
private Payment payment;
private Date rentedDate;
private Date returnDate;
private double fees;
public Rental(Media media, Payment payment, Date
today, double fee) {
this.media = media;
this.payment=payment;
this.rentedDate = today;
this.fees = fee;
}
public Media getMedia() {
return media;
}
public void setMedia(Media media) {
this.media = media;
}
public Payment getPayment() {
return payment;
}
public void setPayment(Payment payment) {
this.payment = payment;
}
public Date getRenteddate() {
return rentedDate;
}
public void setRenteddate(Date localdate) {
this.rentedDate = localdate;
}
public double getFees() {
return fees;
}
public void setFees(double fees) {
this.fees = fees;
}
//This method checked whether the given media is
returned or not if it not returned then set today date as returned
date and returned the total fees
//If it is already returned then just return the total
fees
public double dropoff(Date today){
if(getReturnDate()==null) {
setReturnDate(today);
//getFees() gives one day price .
To calculate total fees we need to multiply it with number of
days.
double totalfees =
getFees() * (int)daysRented(today);
return fees;
}else {
double totalfees =
getFees()* (int)daysRented(today);
return fees;
}
}
public boolean isRented() {
if(getReturnDate()==null) {
return
true;
}
return false;
}
public long daysRented(Date today) {
if(getReturnDate()==null) {
return
findPeriod(getRenteddate(),today);
}else {
return
findPeriod(getRenteddate(),getReturnDate());
}
}
public Date getReturnDate() {
return returnDate;
}
public void setReturnDate(Date returnDate) {
this.returnDate = returnDate;
}
private long findPeriod(Date renteddate2, Date today)
{
// TODO Auto-generated method
stub
long diff = renteddate2.getTime() -
today.getTime();
return TimeUnit.DAYS.convert(diff,
TimeUnit.MILLISECONDS);
}
public String toString() {
SimpleDateFormat formatter = new
SimpleDateFormat("dd/MM/yyyy");
return "'"+this.getMedia()+",
rented on "+formatter.format(this.getRenteddate())+" using "+
this.getPayment()+"'";
}
}
public class DailyRental extends Rental {
private double credit;
//Constructor when the media have credit
public DailyRental(Media media, Payment payment, Date
today, double fee, double credit) {
super(media,payment,today,fee);
this.credit = credit;
}
//Constructor when the media doesn't have the
credits
public DailyRental(Media media, Payment payment, Date
today, double fee) {
super(media,payment,today,fee);
this.credit=0;
}
public double getCredit() {
return credit;
}
public void setCredit(double credit) {
this.credit = credit;
}
//Returns the total fees
public double getTotalFee(Date today) {
double totalfees =
getFees()* (int)daysRented(today) - this.credit;
return totalfees;
}
public static void main(String[] args) {
// TODO Auto-generated method
stub
Media m = new Media("The
Imitation Game",2014);
Payment p1 = new
Payment("#0011223344556677","George Mason",10,2025);
DailyRental r1 = new
DailyRental(m,p1,new Date(),5.0);
Media m2 = new Media("Prison
Break",2014);
Payment p2 = new
Payment("#0548448455748545","Himanshu Tomar",10,2028);
DailyRental r2 = new
DailyRental(m2,p2,new Date(),9.0);
System.out.println(r1);
System.out.println(r2);
}
}
Code Output:-
'The Imitation Game (2014), rented on 29/02/2020 using
##0011223344556677 (George Mason), exp 10/2025'
'Prison Break (2014), rented on 29/02/2020 using ##0548448455748545
(Himanshu Tomar), exp 10/2028'
Hope you will like the answer.
Thanks.
please write program in java and comment the code clearly. I am providing previous classes Media...
java questions: 1. Explain the difference between a deep and a shallow copy. 2. Given the below classes: public class Date { private String month; private String day; private String year; public Date(String month, String day, String year) { this.month = month; this.day = day; this.year = year; } public String getMonth() { return month; } public String getDay() { return day; } public String...
Hi, I am writing Java code and I am having a trouble working it out. The instructions can be found below, and the code. Thanks. Instructions Here are the methods needed for CIS425_Student: Constructor: public CIS425_Student( String id, String name, int num_exams ) Create an int array exams[num_exams] which will hold all exam grades for a student Save num_exams for later error checking public boolean addGrade( int exam, int grade ) Save a grade in the exams[ ] array at...
I need help with my code. It keeps getting this error:
The assignment is:
Create a class to represent a Food object. Use the
description provided below in UML.
Food
name : String
calories : int
Food(String, int) // The only constructor. Food name and
calories must be
// specified
setName(String) : void // Sets the name of the
Food
getName() : String // Returns the name of the
Food
setCalories(int) : void // Sets the calories of the
Food...
PLEASE DO IN JAVA 3) Add the following method to College: 1. sort(): moves all students to the first positions of the array, and all faculties after that. As an example, let fn indicate faculty n and sn indicate student n. If the array contains s1|f1|f2|s2|s3|f3|s4, after invoking sort the array will contain s1|s2|s3|s4|f1|f2|f3 (this does not have to be done “in place”). Students and faculty are sorted by last name. You can use any number of auxiliary (private) methods, if needed....
I need help converting the following two classes into one sql table package Practice.model; import java.util.ArrayList; import java.util.List; import Practice.model.Comment; public class Students { private Integer id; private String name; private String specialties; private String presentation; List<Comment> comment; public Students() {} public Students(Integer id,String name, String specialties, String presentation) { this.id= id; this.name = name; this.specialties = specialties; this.presentation = presentation; this.comment = new ArrayList<Commment>(); } public Students(Integer id,String name, String specialties, String presentation, List<Comment> comment) { this.id= id; this.name...
For the code below write a public static main() method in class Student that: - creates an ArrayList<Student> object called students - adds 4 new Student objects to the students list, with some made up names and dates - sort the students list by name and display the sorted collection to System.out. use function getCompByName() - sort the students list by enrollment date and display the sorted collection to System.out. use function getCompByDate() import java.util.Comparator; import java.util.Date; public...
I need code in java
The Student class:
CODE IN JAVA:
Student.java file:
public class Student {
private String name;
private double gpa;
private int idNumber;
public Student() {
this.name = "";
this.gpa = 0;
this.idNumber = 0;
}
public Student(String name, double gpa, int
idNumber) {
this.name = name;
this.gpa = gpa;
this.idNumber = idNumber;
}
public Student(Student s)...
Please answer the following question with Java Modify the Employee and ProductionWorker classes provided below so they throw exceptions when the following errors occur. - The Employee class should throw an exception named InvalidEmployeeNumber when it receives an employee number that is less than 0 or greater than 9999. - The ProductionWorker class should throw an exception named InvalidShift when it receives an invalid shift. - The ProductionWorker class should thrown anexception named InvalidPayRate when it receives a negative number...
How to solve and code the following requirements (below) using the JAVA program? 1. Modify the FoodProduct Class to implement Edible, add the @Overrride before any methods that were there (get/set methods) that are also in the Edible interface. 2. Modify the CleaningProduct Class to implement Chemical, add the @Overrride before any methods that were there (get/set methods) that are also in the Chemical interface. 3. Create main class to read products from a file, instantiate them, load them into...
Java. Java is a new programming language I am learning, and so far I am a bit troubled about it. Hopefully, I can explain it right. For my assignment, we have to create a class called Student with three private attributes of Name (String), Grade (int), and CName(String). In the driver class, I am suppose to have a total of 3 objects of type Student. Also, the user have to input the data. My problem is that I can get...