Question

I have this problem now and I am not sure what we are exactly supposed to...

I have this problem now and I am not sure what we are exactly supposed to be sorting in ascending order. I am in java programming two and this is my first time using Cengage (online program), so I am unaware of the problems leading up to this one. I have provided the question and the code my professor provided the class, but with COVID-19 pushing our class to online we are not getting any assistance from the professor now. Can someone please help me?

Question

In Chapter 8, you modified the EventDemo program for Carly's Catering to accept and display data for an array of three Event objects. Now, modify the program to use an array of eight Event objects. Prompt the user to choose an option to sort Events in ascending order by event number, number of guests, or event type. Display the sorted list, and continue to prompt the user for sorting options until the user enters a sentinel value.

Previous Code provided by prof.

public class Event {
public final int lowpricePerGuest = 32;
public final int highpricePerGuest = 35;
public final int cutOffValue = 50;
private String eventNumber;
private int numberofGuests;
private double price;
//Code changes for Unit 4 case problem
Event()
{
this("AOOO",0);
//System.out.println("Inside the default constructor");
}
Event( double x, int guests)
{
}
Event( float x, int guests)
{
}
Event(String eventnum, int guests)
{
//System.out.println("Inside the overloaded constructor");
//System.out.println("eventType is" + eventnum);
//System.out.println("number of guests is" + guests);
//calling member function setEventNumber to initialize eventID
setEventNumber(eventnum);
setNumberofGuests(guests);
}
//End Code changes for Unit 4 case problem
public void setEventNumber(String eventNum)
{
eventNumber = eventNum;
}
public void setNumberofGuests(int numofguests)
{
numberofGuests = numofguests;
//changes made as part of case number 5
if (numofguests >= cutOffValue)
price = numberofGuests * lowpricePerGuest;
else
price = numberofGuests * highpricePerGuest;
//if (numofguests < cutOffValue)
//price = numberofGuests * highpricePerGuest;
}
//this function returns the event number
//defined in the class object.
public String getEventNumber()
{
return eventNumber;
}
public int getNumberofGuests()
{
return numberofGuests;
}
//this function calculates price and
//returns a double back to calling function
public double getPrice()
{
return price;
}
//***Start chapter 5 case problem *****
//this function returns price Per guests
public int getPricePerGuest()
{
return 0;
}
//this function checks if event is large,
//and if true it will return true, otherwise it will return false
public boolean isLargeEvent(){
{
if (numberofGuests >= cutOffValue)
return true;
else
return false;
}
}
}

This was Chapter 7's question

In previous chapters, you developed classes that work with catering event information for Carly's Catering. Now modify the Event and EventDemo classes as follows:

  • Modify the Event class to include an integer field that holds an event type. Add a final String array that holds names of the types of events that Carly's caters—wedding, baptism, birthday, corporate, and other. Include get and set methods for the integer event type field. If the argument passed to the method that sets the event type is larger than the size of the array of String event types, then set the integer to the element number occupied by other. Include a get method that returns an event's String event type based on the numeric event type.
  • To keep the EventDemo class simple, remove all the statements that compare event sizes and that display the invitation Strings.
  • Modify the EventDemo class so that instead of creating three single Event objects, it uses an array of three Event objects. Get data for each of the objects, and then display all the details for each object.

here is a chegg study q&a's for this problem but the answer doesnt look right or make sense to me

https://www.chegg.com/homework-help/questions-and-answers/please-help-question-java-programming-8th-edition-joyce-farrell-chapter-9-case-problem-las-q27320222

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

If you want any information regarding code please let me know in comments.

Here is the working code for above question:

1) Sort Events in ascending order by event number, number of guests, or event type.(done)

2) Rectified mistakes in the code.

import java.util.*;
import java.util.Scanner;

class comp implements Comparator<Event>{
   public int compare(Event e1,Event e2){
       return e1.eventNum.compareTo(e2.eventNum);
   }
}

class comps implements Comparator<Event>{
   public int compare(Event e1,Event e2){
       return e1.getEvents().compareTo(e2.getEvents());
   }
}

class compp implements Comparator<Event>{
   public int compare(Event e1,Event e2){
       return e1.getGuestsCount()-e2.getGuestsCount();
   }
}

class Event{

public static double highGuestPrice = 35.00;
public static double lowGuestPrice = 32.00;
public static final int MAX_LARGE_EVENT = 50;
public String phoneNum = "";
public String eventNum = "";
private int guests;
private double pricePerEvent;
private int eventType;
private final String[] EVENT_TYPES = {"wedding", "baptism", "birthday",
"corporate", "other"};
public int getEventType()
{
return this.eventType;   
}
public void setEventType(int eventType1)
{
if(eventType1 >= EVENT_TYPES.length)
{
this.eventType = EVENT_TYPES.length - 1;
}
else
{
this.eventType = eventType1;
}
}
public String getEvents()
{
return EVENT_TYPES[this.eventType];
}
public void setPhoneNumber()
{
Scanner scanner = new Scanner(System.in);
int count = 0;
System.out.println("Please enter phone number:");
String phNum = scanner.nextLine();
int len = phNum.length();
for(int i=0; i < len; i++)
{
char c = phNum.charAt(i);
if(Character.isDigit(c))
{
count++;
String ss = Character.toString(c);
phoneNum = phoneNum.concat(ss);
}
}
if(count!=10)
{
phoneNum = "";
phoneNum = phoneNum.concat("6133574628");
}
}
public String getPhoneNumber()
{
String ret = ("" + this.phoneNum.charAt(0)
+ "" + this.phoneNum.charAt(1) + "" + this.phoneNum.charAt(2)
+ "" + this.phoneNum.charAt(3) + "" + this.phoneNum.charAt(4)
+ "" + this.phoneNum.charAt(5) + "" + this.phoneNum.charAt(6)
+ "" + this.phoneNum.charAt(7) + "" + this.phoneNum.charAt(8)
+ "" + this.phoneNum.charAt(9));
return ret;
}
public void setGuests(int guests)
{
this.guests = guests;
if(isLargeEvent())
pricePerEvent = highGuestPrice;
else
pricePerEvent = lowGuestPrice;
}
public int getGuestsCount()
{
return guests;
}
public boolean isLargeEvent()
{
if(guests >= MAX_LARGE_EVENT)
{
return true;
}
else
{
return false;
}
}
public void setEventNumber(int n)
{
eventNum=String.valueOf(n);
}
public String getEventNumber()
{
String ret1 = "Event Number: " + this.eventNum;
return ret1;
}
public int getGuests(boolean largeEvent)
{
return guests;
}
}

class EventDemo {
  
static Scanner scanner = new Scanner(System.in);
  
public static void main(String[] args)
{
final int SIZE = 8;
int eventType;
Event[] eventObjects = new Event[SIZE];
int guestNum;
for (int i=0; i < eventObjects.length; i++)
{
eventObjects[i] = new Event();
System.out.println("Please enter Event Number: ");
eventType = scanner.nextInt();
eventObjects[i].setEventType(eventType);
eventObjects[i].setEventNumber(eventType);
System.out.println("The name of the event is: "
+ eventObjects[i].getEvents());
eventObjects[i].setPhoneNumber();
  
do
{
System.out.println("Please enter the number of guests:");
guestNum = scanner.nextInt();
if(guestNum < 5 || guestNum > 100)
System.out.println("Number of guests must be between 5 "
+ "and 100.");
}while(guestNum < 5 || guestNum > 100);
eventObjects[i].setGuests(guestNum);
}
/*for(int i=0; i < SIZE; i++)
{
System.out.println("" + eventObjects[i].getEventNumber()
+ "contact number: " + eventObjects[i].getPhoneNumber()
+ "printing message " + eventObjects[i].getGuestsCount());
}*/
int x=0;
do{
System.out.println();
System.out.println("Enter 1 to sort based on Event Number:");
System.out.println("Enter 2 to sort based on Number of Guests:");
System.out.println("Enter 3 to sort based on Event Type:");
System.out.println("Enter any number other than 1,2,3 to quit:");
System.out.println();
x=scanner.nextInt();
if(x==1){
   Arrays.sort(eventObjects,new comp());
for(int i=0; i < SIZE; i++)
{
System.out.println("" + eventObjects[i].getEventNumber()
+ " contact number: " + eventObjects[i].getPhoneNumber()
+ " Guests " + eventObjects[i].getGuestsCount()+
" EventType "+eventObjects[i].getEvents());
}
}
else if(x==3){
   Arrays.sort(eventObjects,new comps());
for(int i=0; i < SIZE; i++)
{
System.out.println("" + eventObjects[i].getEventNumber()
+ " contact number: " + eventObjects[i].getPhoneNumber()
+ " Guests " + eventObjects[i].getGuestsCount()+
" EventType "+eventObjects[i].getEvents());
}
}
else if(x==2){
   Arrays.sort(eventObjects,new compp());
for(int i=0; i < SIZE; i++)
{
System.out.println("" + eventObjects[i].getEventNumber()
+ " contact number: " + eventObjects[i].getPhoneNumber()
+ " Guests " + eventObjects[i].getGuestsCount()+
" EventType "+eventObjects[i].getEvents());
}
}
}while(x<=3&&x>=1);
}
}

Add a comment
Know the answer?
Add Answer to:
I have this problem now and I am not sure what we are exactly supposed to...
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
  • Hello everybody. Below I have attached a code and we are supposed to add comments explaining...

    Hello everybody. Below I have attached a code and we are supposed to add comments explaining what each line of code does. For each method add a precise description of its purpose, input and output.  Explain the purpose of each member variable. . Some help would be greaty appreciated. (I have finished the code below with typing as my screen wasnt big enough to fit the whole code image) } public void withdrawal (double amount) { balance -=amount; }...

  • In previous chapters, you developed classes that hold rental contract information for Sammy's Seashore Supplies. Now...

    In previous chapters, you developed classes that hold rental contract information for Sammy's Seashore Supplies. Now modify the Rental and RentalDemo classes as follows: Modify the Rental class to include an integer field that holds an equipment type. Add a final String array that holds names of the types of equipment that Sammy's rents—personal watercraft, pontoon boat, rowboat, canoe, kayak, beach chair, umbrella, and other. Include get and set methods for the integer equipment type field. If the argument passed...

  • How to build Java test class? I am supposed to create both a recipe class, and...

    How to build Java test class? I am supposed to create both a recipe class, and then a class tester to test the recipe class. Below is what I have for the recipe class, but I have no idea what/or how I am supposed to go about creating the test class. Am I supposed to somehow call the recipe class within the test class? if so, how? Thanks in advance! This is my recipe class: package steppingstone5_recipe; /** * *...

  • JAVA Use the class, Invoice, provided to create an array of Invoice objects. Class Invoice includes...

    JAVA Use the class, Invoice, provided to create an array of Invoice objects. Class Invoice includes four instance variables; partNumber (type String), partDescription (type String), quantity of the item being purchased (type int0, and pricePerItem (type double). Perform the following queries on the array of Invoice objects and display the results: Use streams to sort the Invoice objects by partDescription, then display the results. Use streams to sort the Invoice objects by pricePerItem, then display the results. Use streams to...

  • I have a program that reads a file and then creates objects from the contents of...

    I have a program that reads a file and then creates objects from the contents of the file. How can I create a linked list of objects and use it with the package class instead of creating and using an array of objects? I am not allowed to use any arrays of objects or any java.util. lists in this program. Runner class: import java.util.Scanner; import java.io.*; class Runner { public static Package[] readFile() { try { File f = new...

  • Update your Assignment 4 as follows (Assignment 4 codes will be on the bottom) Create a...

    Update your Assignment 4 as follows (Assignment 4 codes will be on the bottom) Create a new method called displayAll, that takes an ArrayList (of your base class) as a parameter, and doesn't return anything [25 pts] The displayAll method will loop through the ArrayList, and call the display (or toString) method on each object   [25 pts] In the main method, create an ArrayList containing objects of both your base class and subclass. (You should have at least 4 objects)  [25...

  • Java - Car Dealership Hey, so i am having a little trouble with my code, so...

    Java - Car Dealership Hey, so i am having a little trouble with my code, so in my dealer class each of the setName for the salesman have errors and im not sure why. Any and all help is greatly appreciated. package app5; import java.util.Scanner; class Salesman { private int ID; private String name; private double commRate; private double totalComm; private int numberOfSales; } class Car { static int count = 0; public String year; public String model; public String...

  • Java Assignment Calculator with methods. My code appears below what I need to correct. What I...

    Java Assignment Calculator with methods. My code appears below what I need to correct. What I need to correct is if the user attempts to divide a number by 0, the divide() method is supposed to return Double.NaN, but your divide() method doesn't do this. Instead it does this:     public static double divide(double operand1, double operand2) {         return operand1 / operand2;     } The random method is supposed to return a double within a lower limit and...

  • (Reading & Writing Business Objects) I need to have my Classes be able to talk to...

    (Reading & Writing Business Objects) I need to have my Classes be able to talk to Files. How do I make it such that I can look in a File for an account number and I am able to pull up all the details? The file should be delimited by colons (":"). The Code for testing 'Select' that goes in main is: Account a1 = new Account(); a1.select(“90001”); a1.display(); Below is what it should look like for accounts 90000:3003:SAV:8855.90 &...

  • I asked this a little bit ago but didn't clarify exactly what I needed, so I'm...

    I asked this a little bit ago but didn't clarify exactly what I needed, so I'm asking again...I've attached my code below the question. Thanks! Do not change the original contract of the Course class. Instead, ONLY change the implementation of property students, from an array to and ArrayList, and update any methods in class Course that access students to reflect ArrayList. The methods are overridden. That means that you do not need to change the header for methods, only...

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