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

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

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

  • I need some help with some homework questions. How would I implement the to-do's? ----------------------------------------------------------------------------------------------------------------------------------------------------------- AbstractArrayHea

    I need some help with some homework questions. How would I implement the to-do's? ----------------------------------------------------------------------------------------------------------------------------------------------------------- AbstractArrayHeap.Java package structures; import java.util.ArrayList; import java.util.Collections; import java.util.Comparator; import java.util.List; import java.util.NoSuchElementException; public abstract class AbstractArrayHeap<P, V> {   protected final ArrayList<Entry<P, V>> heap;   protected final Comparator<P> comparator; protected AbstractArrayHeap(Comparator<P> comparator) {     if (comparator == null) {       throw new NullPointerException();     }     this.comparator = comparator;     heap = new ArrayList<Entry<P, V>>();   } public final AbstractArrayHeap<P, V> add(P priority, V value) {     if (priority == null || value...

  • DataSetEmployee Can you please help me the JAVA program? Here is the requirement. Rewrite DataSetBook to...

    DataSetEmployee Can you please help me the JAVA program? Here is the requirement. Rewrite DataSetBook to be DataSetEmployee. DataSetEmployee should extend ArrayList<Employee> and have no instance variables. You'll have to decide what replaces the getPages concept for getMax/getMin. As a hint, what method of Employee returns a numeric value? Make a package com.acme.midmanager. This package should contain the Manager class. Make a package com.acme.personnel. This package should contain the DataSetEmployee class. Make a package com.acme.topmanagement. This package should contain the...

  • Solver.java package hw7; import java.util.Iterator; import edu.princeton.cs.algs4.Graph; import edu.princeton.cs.algs4.BreadthFirstPaths; public class Solver {    public static...

    Solver.java package hw7; import java.util.Iterator; import edu.princeton.cs.algs4.Graph; import edu.princeton.cs.algs4.BreadthFirstPaths; public class Solver {    public static String solve(char[][] grid) {        // TODO        /*        * 1. Construct a graph using grid        * 2. Use BFS to find shortest path from start to finish        * 3. Return the sequence of moves to get from start to finish        */               // Hardcoded solution to toyTest        return...

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
ADVERTISEMENT