Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

i need help coding this in java: A university has the following dormitories: Allen Hall: $ 1 , 8 0 0 per semester Pike Hall:

i need help coding this in java:
A university has the following dormitories:
Allen Hall: $1,800 per semester
Pike Hall: $2,200 per semester
Farthing Hall: $2,800 per semester
University Suites: $3,000 per semester
The university also offers the following meal plans:
7 meals per week: $600 per semester
14 meals per week: $1,100 per semester
Unlimited meals: $1,800 per semester
Create an application with two ComboBox controls. One should hold the names of the dormitories, and the other should hold the meal plans. The user should select a dormitory and a meal plan, and the application should show the total charges for the semester.
this is in main.java
import javafx.application.Application;
import javafx.stage.Stage;
import javafx.scene.Scene;
import javafx.scene.layout.VBox;
import javafx.scene.layout.HBox;
import javafx.geometry.Pos;
import javafx.geometry.Insets;
import javafx.scene.control.Label;
import javafx.scene.control.Button;
import javafx.scene.control.ComboBox;
/**
Dorm and Meal Plan Calculator
*/
public class DormAndMealPlan extends Application
{
public static void main(String[] args)
{
// Launch the application.
launch(args);
}
@Override
public void start(Stage primaryStage)
{
// Build the Dorm ComboBox.
// Label to prompt the user to select a dorm
// Build the Meal Plan ComboBox.
// Label to prompt the user to select a meal plan
// Create the output label for total cost.
// Create the Calculate button.
// Register event handler for the button
calcButton.setOnAction(event ->
{
double dormCharges =0.0;
double mealCharges =0.0;
double totalCharges =0.0;
if (dormComboBox.getValue()!= null)
{
String dorm = dormComboBox.getValue();
if (dorm.equals("Allen Hall"))
dormCharges =1800.0;
else if (dorm.equals("Pike Hall"))
dormCharges =2200.0;
else if (dorm.equals("Farthing Hall"))
dormCharges =2800.0;
else if (dorm.equals("University Suites"))
dormCharges =3000.0;
else
dormCharges =0.0;
}
if (mealComboBox.getValue()!= null)
{
//code for mealComboBox
}
// Get the total charges
totalCharges = dormCharges + mealCharges;
// Display the charges.
costOutputLabel.setText(String.format("%,.2f", totalCharges));
});
// Put everything into a VBox
VBox mainVBox = new VBox(10, dormAndMealHBox, costHBox, calcButton);
mainVBox.setAlignment(Pos.CENTER);
mainVBox.setPadding(new Insets(10));
// Add the main VBox to a scene.
Scene scene = new Scene(mainVBox);
// Set the scene to the stage aand display it.
primaryStage.setScene(scene);
primaryStage.show();
}
}
this is in problem.txt:
show output as well, please.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access with AI-Powered Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions