Question

A university has the following dormitories: Allen Hall: $1,500 per semester Pike Hall: $1,600 per semester...

A university has the following dormitories:

  • Allen Hall: $1,500 per semester
  • Pike Hall: $1,600 per semester
  • Farthing Hall: $1,200 per semester
  • University Suites: $1,800 per semester

The university also offers the following meal plans:

  • 7 meals per week: $560 per semester
  • 14 meals per week: $1,095 per semester
  • Unlimited meals: $1,500 per semester

Create an application with two combo boxes. 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. Answer with javaFX

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

// Java Program To Create A Dormitory And Meal Charges Calculator
import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.control.*;
import javafx.scene.layout.*;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.collections.*;
import javafx.geometry.Pos;
import javafx.stage.Stage;
import javafx.scene.text.Text.*;
import javafx.scene.paint.*;
import javafx.scene.text.*;
public class combo_box_2 extends Application {

   // Launch the application
   public void start(Stage stage)
   {
       // Set title for the stage
       stage.setTitle("Dormitory And Meal Charges Calculator");
  
       // Dormitories
       String dormitories[] =
               { "Allen Hall", "Pike Hall", "Farthing Hall", "University Suites" };

       // Creating a combo box to show a list of dormitories
       ComboBox combo_box_dormitories =
                   new ComboBox(FXCollections
                           .observableArrayList(dormitories));
  
// Meal Plans
       String meal_plans[] =
               { "7 meals per week", "14 meals per week", "Unlimited meals" };

       // Creating a combo box to show a list of meal plans
       ComboBox combo_box_meal_plans =
                   new ComboBox(FXCollections
                           .observableArrayList(meal_plans));

       // Label to display the total charges for the semester
       Label total_charges_label = new Label("Total Charges = $0");

       // Creating action event to handle selection of different items in both lists
// and calculating charges according to the selections of the user
       EventHandler<ActionEvent> event = new EventHandler<ActionEvent>() {
           public void handle(ActionEvent e)
           {
int dormitory_charges = 0, meal_charges = 0, total_charges = 0;
  
//Calculating dormatory charges according to the current selection
if(combo_box_dormitories.getValue()=="Allen Hall")
{
dormitory_charges = 1500;
}
else if(combo_box_dormitories.getValue()=="Pike Hall")
{
dormitory_charges = 1600;
}
else if(combo_box_dormitories.getValue()=="Farthing Hall")
{
dormitory_charges = 1200;
}
else if(combo_box_dormitories.getValue()=="University Suites")
{
dormitory_charges = 1800;
}
  
//Calculating meal charges according to the current selection
if(combo_box_meal_plans.getValue()=="7 meals per week")
{
meal_charges = 560;
}
else if(combo_box_meal_plans.getValue()=="14 meals per week")
{
meal_charges = 1095;
}
else if(combo_box_meal_plans.getValue()=="Unlimited meals")
{
meal_charges = 1500;
}
  
//Calculating total charges as sum of both dormatory charges and meal charges
total_charges = dormitory_charges + meal_charges;
  
//Displaying total charges on the "total_charges" label
total_charges_label.setText("Total Charges = $" + Integer.toString(total_charges));
           }
       };

       // Setting on action
       combo_box_dormitories.setOnAction(event);
combo_box_meal_plans.setOnAction(event);

       // Creating a tile pane
       TilePane tile_pane = new TilePane(combo_box_dormitories, combo_box_meal_plans, total_charges_label);

       // Creating a scene
       Scene scene = new Scene(tile_pane, 350, 200);

       // Setting the scene
       stage.setScene(scene);
  
//Setting stage not to be resized
stage.setResizable(false);

       stage.show();
   }

   public static void main(String args[])
   {
       // Launch the application
       launch(args);
   }
}

Output

Add a comment
Know the answer?
Add Answer to:
A university has the following dormitories: Allen Hall: $1,500 per semester Pike Hall: $1,600 per semester...
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
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