Question

I need help to write a test case. 1. Go to the ConcertTicketTest.java file and write...

I need help to write a test case.

1. Go to the ConcertTicketTest.java file and write test cases for the compareTo method you just implemented.

/* ConcertTicket.java file */

package SearchingSorting;


/**
*
* @author clatulip
*/
public class ConcertTicket implements Comparable<ConcertTicket> {

private String name;
private int price;
private char row;
private int seat;

public ConcertTicket(String name, int price) {
this.name = name;
this.price = price;
// randomly create a row and seat
// assumes 60 seats across width of venue
// seat 1 at far left
seat = (int)(Math.random()*60 + 1);
// assume 26 rows from front to back
// row A at front
row = (char)((int)(Math.random()*26) + 65); // 065 is ASCII code for 'A'
}

public ConcertTicket() {
name = "";
price = 0;
}

public String getName() {
return name;
}

public int getPrice() {
return price;
}


public char getRow() {
return row;
}


public int getSeat() {
return seat;
}

@Override
public String toString() {
return "ConcertTicket{" + "\t price=" + price + "\t row=" + row + "\t seat= " + seat + "\t name=" + name +'}';
}
  
@Override
public int compareTo(ConcertTicket o) {
  
  
if(this.price == o.price){
return 0;
}
else if(this.price < o.price){
return -1;
}

if(this.price > o.price){
return 1;
}
  
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}

}

******************************************************************

/* ConcertTicketTest.java */

package SearchingSorting;

import SearchingSorting.ConcertTicket;
import org.junit.Test;
import static org.junit.Assert.*;

/**
*
* @author Kyle
*/
public class ConcertTicketTest {
  
ConcertTicket ct1;
ConcertTicket ct2;
ConcertTicket ct3;
ConcertTicket ct4;
  
public ConcertTicketTest() {
ct1 = new ConcertTicket("Niche Artist", 5);
ct2 = new ConcertTicket("Popular Artist", 6);
ct3 = new ConcertTicket("International Superstar", 7);
ct4 = new ConcertTicket("Pop Star", 7);
}

/**
* Test of compareTo method, of class ConcertTicket.
*/
@Test
public void testCompareTo() {
System.out.println("compareTo");
  

//TODO: Test the compareTo method for the ConcertTicket class
throw new UnsupportedOperationException("Not supported yet");
}
  
}

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

The completed code is given below.
Please do rate the answer if it helped. Thank you.


/* ConcertTicketTest.java */

package SearchingSorting;
import SearchingSorting.ConcertTicket;
import org.junit.Test;
import static org.junit.Assert.*;

/**
*
* @author Kyle
*/
public class ConcertTicketTest {

   ConcertTicket ct1;
   ConcertTicket ct2;
   ConcertTicket ct3;
   ConcertTicket ct4;

   public ConcertTicketTest() {
       ct1 = new ConcertTicket("Niche Artist", 5);
       ct2 = new ConcertTicket("Popular Artist", 6);
       ct3 = new ConcertTicket("International Superstar", 7);
       ct4 = new ConcertTicket("Pop Star", 7);
   }

   /**
   * Test of compareTo method, of class ConcertTicket.
   */
   @Test
   public void testCompareTo() {
       System.out.println("compareTo");
       assertEquals(ct1.compareTo(ct2), -1);
       assertEquals(ct3.compareTo(ct2), 1);
       assertEquals(ct3.compareTo(ct3), 0);
   }

}

Add a comment
Know the answer?
Add Answer to:
I need help to write a test case. 1. Go to the ConcertTicketTest.java file and write...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Objectives: GUI Tasks: In Lab 4, you have completed a typical function of music player --...

    Objectives: GUI Tasks: In Lab 4, you have completed a typical function of music player -- sorting song lists. In this assignment, you are asked to design a graphic user interface (GUI) for this function. To start, create a Java project named CS235A4_YourName. Then, copy the class Singer and class Song from finished Lab 4 and paste into the created project (src folder). Define another class TestSongGUI to implement a GUI application of sorting songs. Your application must provide the...

  • I need help in converting this into pseudo-code Student.java public class Student implements Comparable<Student>{ private String...

    I need help in converting this into pseudo-code Student.java public class Student implements Comparable<Student>{ private String name, major, status; private int rank;    public Student() { this.name = this.major = this.status = ""; this.rank = 0; }    public Student(String name, String major, String status) { this.name = name; this.major = major; this.status = status; } public String getName() { return name; } public String getMajor() { return major; } public String getStatus() { return status; }    public int...

  • How to solve and code the following requirements (below) using the JAVA program? 1. Modify the...

    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...

  • Hi I need help with a java program that I need to create a Airline Reservation...

    Hi I need help with a java program that I need to create a Airline Reservation System I already finish it but it doesnt work can someone please help me I would be delighted it doesnt show the available seats when running the program and I need it to run until someone says no for booking a seat and if they want to cancel a seat it should ask the user to cancel a seat or continue booking also it...

  • Hey guys I am having trouble getting my table to work with a java GUI if...

    Hey guys I am having trouble getting my table to work with a java GUI if anything can take a look at my code and see where I am going wrong with lines 38-49 it would be greatly appreciated! Under the JTableSortingDemo class is where I am having erorrs in my code! Thanks! :) import java.awt.*; import java.awt.event.*; import java.util.*; import java.util.List; import javax.swing.*; public class JTableSortingDemo extends JFrame{ private JTable table; public JTableSortingDemo(){ super("This is basic sample for your...

  • This is my playlist class: class Playlist{       private String name;    private int numberOfRecordings...

    This is my playlist class: class Playlist{       private String name;    private int numberOfRecordings = 0;    private int durationInSeconds = 0;    private int MAX_PLAYLIST_SIZE;    Recording recordingslist[];       Playlist(){        name = "Unknown";        MAX_PLAYLIST_SIZE = 5;        recordingslist = new Recording[MAX_PLAYLIST_SIZE];        durationInSeconds = 0;    }       Playlist(String name, int size){        this.name = name;        this.MAX_PLAYLIST_SIZE = size;        recordingslist = new Recording[MAX_PLAYLIST_SIZE];   ...

  • ATM Class Write an ATM class to test your Account Class. The ATM class will prompt...

    ATM Class Write an ATM class to test your Account Class. The ATM class will prompt for a user name, if there is no account with that user name it will prompt out an error statement and start over. If there is an account with that user name, then it will prompt the user for a password. If the password does not match the user name then another error message and the program will restart and prompt for another user...

  • I need help with adding comments to my code and I need a uml diagram for...

    I need help with adding comments to my code and I need a uml diagram for it. PLs help.... Zipcodeproject.java package zipcodesproject; import java.util.Scanner; import java.io.BufferedReader; import java.io.FileReader; import java.io.IOException; public class Zipcodesproject { /** * @param args the command line arguments */ public static void main(String[] args) { Scanner input=new Scanner(System.in); BufferedReader reader; int code; String state,town; ziplist listOFCodes=new ziplist(); try { reader = new BufferedReader(new FileReader("C:UsersJayDesktopzipcodes.txt")); String line = reader.readLine(); while (line != null) { code=Integer.parseInt(line); line =...

  • Use inheritance to create a new class AudioRecording based on Recording class that: it will retain...

    Use inheritance to create a new class AudioRecording based on Recording class that: it will retain all the members of the Recording class, it will have an additional field bitrate (non-integer numerical; it cannot be modified once set), its constructors (non-parametrized and parametrized) will set all the attributes / fields of this class (reuse code by utilizing superclass / parent class constructors): Non-parametrized constructor should set bitrate to zero, If arguments for the parametrized constructor are illegal or null, it...

  • is there anyway you can modify the code so that when i run it i can...

    is there anyway you can modify the code so that when i run it i can see all the song when i click the select button all the songs in the songList.txt file can be shown song.java package proj2; public class Song { private String name; private String itemCode; private String description; private String artist; private String album; private String price; Song(String name, String itemCode, String description, String artist, String album, String price) { this.name = name; this.itemCode = itemCode;...

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