Friday, September 4, 2020

#155 Your task is to develop a Ticket class

Your task is to develop a Ticket class - Computer Science

ChemistryExplain daily providing Q&A content “#155 Your task is to develop a Ticket class" in Computer science, Ba computer science, Berkeley computer science, Computer science associate degree jobs.
ChemistryExplain “#155 Your task is to develop a Ticket class in Computer science, Ba computer science, Berkeley computer science, Computer science associate degree jobs
Get the Free Online Chemistry Q&A Questions And Answers with explain. To crack any examinations and Interview tests these Chemistry Questions And Answers are very useful. Here we have uploaded the Free Online Chemistry Questions. Here we are also given the all chemistry topic.
 ChemistryExplain team has covered all Topics related to inorganic, organic, physical chemistry, and others So, Prepare these Chemistry Questions and Answers with Explanation Pdf.
For More Chegg Questions

Free Chegg Question

Your task is to develop a Ticket class of object. A Ticket object represents a car park ticket. It has a unique ID and time of issue (24-hour clock).
Your class must meet the following specification.
Class Ticket
A Ticket object represents a car park ticket. It has a unique ID and time of issue (24 hour clock).
Instance variables
String id;
Time issue Time;
Constructors
Ticket(Time currentTime, String ID)
// Create a new Ticket that has the given issue time and unique ID.
Methods
public String ID() //
Obtain this Ticket's ID.
public Duration age(Time currentTime)
// Obtain this ticket's age i.e. the issue time subtracted from the given time.
public String toString()
// Obtain a String representation of this Ticket object in the form:
// "Ticket[id="ddddd", time="hh:mm:ss")".
Here's a code snippet to illustrate behaviour:
//..
Time tone = new Time ("6:50", "800001");
Ticket ticket = new Ticket (tone) ;
Time t Two = new Time ("7:19", "8005A3");
System.out.println(ticket.toString() );
Duration d ticket.age (tTwo);
System.out.println(d.intValue ("minute"));
//...
The output from this code would be:
Ticket[id=800001, time=06:50:00]. 29 The class has a single constructor that is used to (i) assign the current time as the ticket issue time and to (ii) assign a unique ID.
 For More Chemistry Notes and Helpful Content Subscribe Our YouTube Chanel - Chemistry Explain  

Free Chegg Answer

import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.time.Duration;
import java.time.LocalDateTime;
import java.time.temporal.Temporal;
import java.util.Date;
//import java.time.LocalDate;
class Time
{
String time;
String id;
public Time(String time, String id) {
this.time = time;
this.id = id;
}
}
class Tick
{
String id;
Time issuetime;
Tick(Time t)
{
this.issuetime=t;
this.id=t.id;
}
public String id()
{
return id;
}
public Duration age(Time currenttime) throws ParseException
{
//DateFormat format=new SimpleDateFormat("hh:mm:ss");
Date d1= new Date();
Date d2=new SimpleDateFormat("hh:mm").parse(currenttime.time);
System.out.print("d2 is"+d2);
long d=d1.getTime()-d2.getTime();
System.out.println(" d is"+d);
return Duration.ofMinutes(d);
}
@Override
public String toString() {
return "Tick [id=" + id + ", issuetime=" + issuetime.time + "]";
}
}
public class Ticket {
public static void main(String[] args) throws ParseException {
// TODO Auto-generated method stub
Time tOne=new Time("06:50","800001");
Tick ticket= new Tick(tOne);
Time tTwo=new Time("07:19","8005A3");
System.out.print(ticket.toString());
Duration d=ticket.age(tTwo);
System.out.println(d);
}
}

Labels: , ,

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home