I have 30 minutes to compete this. 34 is a cut off but assume what is missing, o
ID: 3807504 • Letter: I
Question
I have 30 minutes to compete this. 34 is a cut off but assume what is missing, otherwise you don't have to answer! Please answer these Coding questions in Java format! Please number your answers.
noN DATE. Coding Exercises: For all problems follow proper coding guidelines with regard to punctuaton, spacing, syntax, etc . Assume all methods coded are in the same program as a main" Use annta (with specifiers if needed) for prompts and output. Assume input for the Scanner class is already declared. Do not write in all caps except where permitted according to Java rules. For each question, read the entire instruction first then follow step-by-step. 31. Code a value-receiving method called costumes() that receives a number for a party event. Inside this method is a switch statement that tests partyEvent so when partyEvent is 1 the value- returning method valentines is called; when 2 the value-returning method mardiGras is called, When 3 the value-returning method halloween is called, and when it is not any of the above we message "The party you want is not planned!" is displayed. The methods valentines mardGras, and halloween return the number of attendees for each respective party event whic added to a global variable called totalAttendees that is already declared. (10 points)Explanation / Answer
(31).
public int totalAttendees = 0; //global variable assigned 0 so that sum is done correctly
public int valentines() // returns number of people for the party displayed as the method name.
{
return 100;
}
public int mardiGras() // returns number of people for the party displayed as the method name.
{
return 50;
}
public int halloween() // returns number of people for the party displayed as the method name.
{
return 70;
}
public void costumes(int partyEvent)
{
int number = 0; // if the partyEvent number is not 1 2 or 3, this 0 is added to global variable so that the value // remains unchanged.
switch(partyEvent)
{
case 1: number = valentines(); break;
case 2: number = mardiGras(); break;
case 3: number = halloween(); break;
default: System.out.println("The party you want is not planned!");
}
totalAttendees = totalAttendees + number; // adding the number to global variable.
}
(32).
public int avgAttendees()
{
for(int i=1; i<=3; i++)
{
costumes(1);
costumes(3);
costumes(2);
}
int avg = totalAttendees / 3;
return avg;
}
Here, the for loop is used to call the method costume() 3 times and so the total attendees are found after this for loop so find the average I divided this sum by 3. The return type of this should be int as we should not write the average 64.3 people instead we write 64 it is better. So, this average is returned.
(33).
public boolean games(String bannerID, String asapBannerID)
{
boolean admitFree;
if (bannerID.equals(asapBannerID)) {
admitFree = true;
} else {
admitFree = false;
}
return admitFree;
}
This method is returning admitFree variable value and as it was a boolean, return type of this method is boolean.
So, in this method, 2 IDs are taken as String because the bannerID may start from a character 'B' in the student's ID card so.. Two strings are compared for equality using equals() method, not ==. So I checked it and set the value of admitFree variable accordingly and the same value is returned.
(34).
public void games(String bannerID, String asapBannerID, boolean fullTime) {
boolean admitFree;
if (bannerID.equals(asapBannerID) && fullTime) {
System.out.println("Ticket printing for your fee admittance to the game! Go Roadrunners!");
}
else{
System.out.println("Sorry! You need to purchase a ticket to the game.");
}
}
This method has return type void. It takes 3 parameters and if 2 are equal as above method and also the variable fullTime is true (if(fullTime) means if(fullTime==true)) it prints the 1st message otherwise it prints the 2nd sentence.
Please comment if there is any query. Thank you. :)
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.