Java Programming (MindTap Course List)
Java Programming (MindTap Course List)
8th Edition
ISBN: 9781285856919
Author: Joyce Farrell
Publisher: Cengage Learning
Expert Solution & Answer
Book Icon
Chapter 3, Problem 1CP

Explanation of Solution

a.

CarlysEventPriceWithMethods.java

//import the required packages

import java.util.Scanner;

//define a method CarlysEventPriceWithMethods

public class CarlysEventPriceWithMethods

{

//Scanner object

private static Scanner sc = new Scanner(System.in);

//define a method getEventNum()

public static String getEventNum()

{

//print the statement

System.out.println("Enter event number: ");

//scan the values

return sc.next();

}

//define the method getNoGuests

public static int getNoOfGuests()

{

//print the statement

System.out.println("Enter no of guests: ");

//return the value scanned

return sc.nextInt();

}

//define the method displayMotto()

public static void displayMotto(Event e)

{

//prin the values

System.out.println(String.format("%26s", " ").replace(" ", "*"));

System.out.printf("* %22s *", " ");

System.out.println("\n* Carly’s Catering *");

System.out.printf("* %22s *\n", " ");

System.out.println(String.format("%26s", " ").replace(" ", "*"));

System.out.println("Event No: " + e.getEventNum());

System.out.println("No. of guests:" + e.getNoOfGuest());

System.out.println("Price per guest: $" + Event.PRICE_PER_GUEST);

//call the method computePrice

computePrice(e);

}

//define the method computePrice

public static void computePrice(Event e)

{

//print the values

System.out.println("Price: $" + e.getPrice());

System.out.println("Large event: " + ((e.getNoOfGuest() > Event.CUT_OFF) ? "Yes" : "No"));

}

//define the main method

public static void main(String[] args)

{

//Close scanner

sc.close();

}

}

Explanation:

The above snippet of code is used to create a class “CarlysEventPriceWithMethods”. In the code,

  • Import the required header files.
  • Define a class “CarlysEventPriceWithMethods”
    • Declare the object of “Scanner” class.
    • Define the “getEventNum()” method.
      • Prompt the user to enter the event number.
      • Return the value of “name”.
    • Define the “getNoGuests()” method.
      • Return the scanned value.
    • Define the “displayMotto()” method.
      • Print the values.
      • Call the method “computePrice()”.
    • Define the “computePrice()” method.
      • Print the values.
    • Define the “main()” method.
      • Close the scanner.

b.

Event.java

//define a class Event

public class Event

{

//declare the class members

public final static int PRICE_PER_GUEST = 35;

public final static int CUT_OFF = 50;

private String eventNum;

private int noOfGuest;

private int price;

//define a method setEventNum()

public void setEventNum(String eventNum)

{

//set the value of eventNum

this.eventNum = eventNum;

}

//define a method setNoOfGuest()

public void setNoOfGuest(int noOfGuest)

{

//set the values of noOfGuest

this.noOfGuest = noOfGuest;

//set the values of price

this...

Blurred answer
Students have asked these similar questions
C++ program Write a method that displays information about a movie. The method accepts the movie title, running time in minutes and the release year as arguments. Provide a default value for the running time so that if you call the method without minutes, it defaults to 90. Write a main() method that demonstrates you can call the method with two or three arguments. Save the file as Movie.cpp
In C# Previously, you wrote a program named Admission for a college admissions office in which the user enters a numeric high school grade point average and an admission test score. The program displays Accept or Reject based on those values. Now, create a modified program named AdmissionModularized in which the grade point average and test score are passed to a method that returns a string containing Accept or Reject. using System; using static System.Console; class Admission { staticvoidMain() { double gpa; int testScore; string inputString; WriteLine("Enter grade point average "); inputString = ReadLine(); gpa = Convert.ToDouble(inputString); WriteLine("Enter test score "); inputString = ReadLine(); testScore = Convert.ToInt32(inputString); WriteLine(AcceptOrReject(gpa, testScore)); } public static string AcceptOrReject(double gpa, int testScore) { constdouble MINGPA =3.0; constint ADMIN1 =60, ADMIN2 =80; if (gpa >= MINGPA) if (testScore >= ADMIN1) return"Accept"; else…
C++ Program: A menu is a list of options for a user to select. The selection is the single character chosen for a menu item. An example menu is below: 1. Buy2. Sell3. ConvertX. Exit   Assignment: Write a method called "promptForInput" that will help you write user menus.  You should be able to use this in future programs if wanted.  The purpose for this method is to be the "end all of methods" that you could reuse in other situations. The code should pass an C-String of valid characters to select to the promptForInput method as the 1st parameter. See "C-Strings Stored in Arrays" on page 556 8th ed. or 566 9th ed.  In the example above, the C-String would be "123X". The code should pass a C-String that is the menu to display as the 2nd parameter. It may help your display to have embedded \n characters.I.E.    char menu[] = "1. Buy\n2. Sell\n3. Convert\nX. Exit";Example pseudo code:define c-string char array of valid input charactersdefine menuloop until X inputchar input =…
Knowledge Booster
Background pattern image
Similar questions
SEE MORE QUESTIONS
Recommended textbooks for you
Text book image
EBK JAVA PROGRAMMING
Computer Science
ISBN:9781337671385
Author:FARRELL
Publisher:CENGAGE LEARNING - CONSIGNMENT
Text book image
EBK JAVA PROGRAMMING
Computer Science
ISBN:9781305480537
Author:FARRELL
Publisher:CENGAGE LEARNING - CONSIGNMENT
Text book image
Microsoft Visual C#
Computer Science
ISBN:9781337102100
Author:Joyce, Farrell.
Publisher:Cengage Learning,
Text book image
Programming Logic & Design Comprehensive
Computer Science
ISBN:9781337669405
Author:FARRELL
Publisher:Cengage