Database System Concepts
Database System Concepts
7th Edition
ISBN: 9780078022159
Author: Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher: McGraw-Hill Education
expand_more
expand_more
format_list_bulleted
Bartleby Related Questions Icon
Related questions
Question
PLEASE ADD SOME DESIGNS ON MY JAVA PROGRAM , LIKE FONTS, BACKGROUND COLOR ETC.
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.util.*;
//class declaration
public class foodtest extends JFrame implements ActionListener {
// declare global variables
JCheckBox cbBurger, cbEggs, cbFriedChicken, cbBrownRice, cbIceCream;
JLabel lblTitle, lblBurger, lblEggs, lblFriedChicken, lblBrownRice, lblIceCream;
JButton b1Calculate, b2Check, b3Reset, b4Cancel;
JTextArea t1Output;
int burgerCal = 295, eggsCal = 72, friedchickenCal = 260, brownriceCal = 111, icecreamCal = 300;
int totalCal = 0;
ArrayList<String> foodItems = new ArrayList<String>();
ArrayList<Integer> foodCalories = new ArrayList<Integer>();
// constructor
public foodtest() {
// set frame properties
setTitle("IS YOUR FOOD HEALTHY?");
setSize(630, 520);
setLayout(new FlowLayout());
setResizable(false);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
// initialize variables
lblTitle = new JLabel("Whats your order:");
lblBurger = new JLabel("Burger");
lblEggs = new JLabel("Eggs");
lblFriedChicken = new JLabel("Fried Chicken");
lblBrownRice = new JLabel("Brown Rice");
lblIceCream = new JLabel("Ice Cream");
cbBurger = new JCheckBox();
cbEggs = new JCheckBox();
cbFriedChicken = new JCheckBox();
cbBrownRice = new JCheckBox();
cbIceCream = new JCheckBox();
b1Calculate = new JButton("Calculate");
b2Check = new JButton("Check");
b3Reset = new JButton("Reset");
b4Cancel = new JButton("Cancel");
t1Output = new JTextArea(10, 30);
// add action listeners
b1Calculate.addActionListener(this);
b2Check.addActionListener(this);
b3Reset.addActionListener(this);
b4Cancel.addActionListener(this);
// add items to frame
add(lblTitle);
add(lblBurger);
add(cbBurger);
add(lblEggs);
add(cbEggs);
add(lblFriedChicken);
add(cbFriedChicken);
add(lblBrownRice);
add(cbBrownRice);
add(lblIceCream);
add(cbIceCream);
add(b1Calculate);
add(b2Check);
add(b3Reset);
add(b4Cancel);
add(t1Output);
// display frame
setVisible(true);
}
// actionPerformed method
public void actionPerformed(ActionEvent e) {
// declare local variables
Object source = e.getSource();
if (source == b1Calculate) {
// get selected food items and add them to array list
if (cbBurger.isSelected()) {
foodItems.add("Burger");
foodCalories.add(burgerCal);
}
if (cbEggs.isSelected()) {
foodItems.add("Eggs");
foodCalories.add(eggsCal);
}
if (cbFriedChicken.isSelected()) {
foodItems.add("Fried Chicken");
foodCalories.add(friedchickenCal);
}
if (cbBrownRice.isSelected()) {
foodItems.add("Brown Rice");
foodCalories.add(brownriceCal);
}
if (cbIceCream.isSelected()) {
foodItems.add("Ice Cream");
foodCalories.add(icecreamCal);
}
// calculate total calories
for (
int i = 0; i < foodCalories.size(); i++) {
totalCal += foodCalories.get(i);
}
// display selected food items and total calories
t1Output.setText("You have selected:");
for (int i = 0; i < foodItems.size(); i++) {
t1Output.append(foodItems.get(i) + "\n");
}
t1Output.append("Total Calories: " + totalCal);
} else if (source == b2Check) {
// check if food is healthy or not
if (totalCal <= 200) {
t1Output.append("\nThis food is healthy!");
} else {
t1Output.append("\nThis food is unhealthy!");
}
} else if (source == b3Reset) {
// clear all selections
cbBurger.setSelected(false);
cbEggs.setSelected(false);
cbFriedChicken.setSelected(false);
cbBrownRice.setSelected(false);
cbIceCream.setSelected(false);
foodItems.clear();
foodCalories.clear();
totalCal = 0;
t1Output.setText("");
} else if (source == b4Cancel) {
// exit program
System.exit(0);
}
}
// main method
public static void main(String[] args) {
new foodtest();
}
}
Expert Solution
Check MarkThis question has been solved!
Explore an expertly crafted, step-by-step solution for a thorough understanding of key concepts.
bartleby
This is a popular solution
bartleby
Trending nowThis is a popular solution!
bartleby
Step by stepSolved in 3 steps
Knowledge Booster
Background pattern image
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.Similar questions
- Java Programingarrow_forwardPlease help me with this. I am really struggling Please help me modify my java matching with the image provide below or at least fix the errors import java.awt.*; import java.awt.event.*; import javax.swing.*; public class Game extends JFrame implements ActionListener { int hallo[][] = {{4,6,2}, {1,4,3}, {5,5,1}, {2,3,6}}; int rows = 4; int cols = 3; JButton pics[] = new JButton[rows*cols]; public Game() { setSize(600,600); JPanel grid = new JPanel(new GridLayout(rows,cols)); int m = 0; for(int i = 0; iarrow_forwardimport bridges.base.ColorGrid;import bridges.base.Color;public class Scene {/* Creates a Scene with a maximum capacity of Marks andwith a background color.maxMarks: the maximum capacity of MarksbackgroundColor: the background color of this Scene*/public Scene(int maxMarks, Color backgroundColor) {}// returns true if the Scene has no room for additional Marksprivate boolean isFull() {return false;}/* Adds a Mark to this Scene. When drawn, the Markwill appear on top of the background and previously added Marksm: the Mark to add*/public void addMark(Mark m) {if (isFull()) throw new IllegalStateException("No room to add more Marks");}/*Helper method: deletes the Mark at an index.If no Marks have been previously deleted, the methoddeletes the ith Mark that was added (0 based).i: the index*/protected void deleteMark(int i) {}/*Deletes all Marks from this Scene thathave a given Colorc: the Color*/public void deleteMarksByColor(Color c) {}/* draws the Marks in this Scene over a background...arrow_forward
- Please help me fix the errors in this java program. I can’t get the program to work Class: AnimatedBall Import java.swing.*; import java.awt.*; import java.awt.event.*; public class AnimatedBall extends JFrame implements ActionListener { private Button btnBounce; // declare a button to play private TextField txtSpeed; // declare a text field to enter number private Label lblDelay; private Panel controls; // generic panel for controls private BouncingBall display; // drawing panel for ball Container frame; public AnimatedBall () { // Set up the controls on the applet frame = getContentPane(); btnBounce = new Button ("Bounce Ball"); //create the objects txtSpeed = new TextField("10000", 10); lblDelay = new Label("Enter Delay"); display = new BouncingBall();//create the panel objects controls = new Panel(); setLayout(new BorderLayout()); // set the frame layout controls.add (btnBounce); // add controls to panel controls.add (lblDelay); controls.add (txtSpeed); frame.add(controls,...arrow_forwardPlease teach me how to fix an error from my JAVA source code. I have set up the source code with class name "ProductionWorker" and there were a error occured on second page of sceenshot where it is highlighted. //import the file import java.util.*; //create the class class Employee { //create the variable private String emp_num; //create the date variable private Date hiring_date; // default constructor public Employee() { //assign the emp num. this.emp_num = "000-A"; //assign the Date this.hiring_date = new Date(); } // constructor parameter public Employee(String emp_num, Date hiring_date) { this.emp_num = emp_num; this.hiring_date = hiring_date; } // getter method public String getEmployeeNumber() { return this.emp_num; } // call the gethiringdate function public Date gethiringDate() { // return the date return this.hiring_date; } // setter method public void setEmployeeNumber(String emp_num) { //set the emp num. this.emp_num = emp_num; } //set the hiring date public void...arrow_forwardImplement a date picker in javafx having following properties1) only numerical value can be typed in it2) / ( forward slash) appears in it when form prompt and user can write date in it3)only 8 digits can be typed in itarrow_forward
- can someone help me resize the picture in Java. This is my code: import java.awt.*;import java.awt.image.BufferedImage;import java.io.File;import java.io.IOException;import javax.imageio.ImageIO; class ImageDisplayGUI { public static void main(String[] args) { SwingUtilities.invokeLater(() -> { createAndShowGUI(); }); } private static void createAndShowGUI() { JFrame frame = new JFrame("Bears"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setSize(800, 600); frame.setLayout(new BorderLayout()); // Load and display the JPG image try { BufferedImage image = ImageIO.read(new File("two bears.png")); // Replace with your image path ImageIcon icon = new ImageIcon(image); JLabel imageLabel = new JLabel(icon); frame.add(imageLabel, BorderLayout.CENTER); } catch (IOException e) { // Handle image loading error...arrow_forwardPlease add the code after this one. The code has to be in java eclipse. Please add comments in what you are doing. I'll appreciate it public class Computer { private String ModelNumber; private String BrandName; private String manufacturingDate; private int NumberOfCores; //Constructor a public Computer() {} //Construct a computer object with model, BrandName, NumberOfCoresComputer (String ModelNumber, String BrandName, String manufacturingDate, int NumberOfCores){ this.ModelNumber=ModelNumber; this.BrandName=BrandName; this.manufacturingDate=manufacturingDate; this.NumberOfCores=NumberOfCores;}//generate getters/setterspublic String getModel() { return ModelNumber;} public void setModel(String ModelNumber) { ModelNumber = ModelNumber;} public String getBrandName() { return BrandName;} public void setBrandName(String brandName) { BrandName = brandName;} public String getManufacturingDate() { return manufacturingDate;} public void setManufacturingDate(String...arrow_forwardCreate a UML class diagram of the application illustrating class hierarchy, collaboration, and the content of each class. There is only one class. There is a main method that calls four methods. I am not sure if I made the UML Class diagram correct. import java.util.Random; // import Random packageimport java.util.Scanner; // import Scanner Package public class SortArray{ // class name public static void main(String[] args) { //main method Scanner scanner = new Scanner(System.in); // creates object of the Scanner classint[] array = initializeArray(scanner); System.out.print("Array of randomly generated values: ");displayArray(array); // Prints unsorted array sortDescending(array); // sort the array in descending orderSystem.out.print("Values in desending order: ");displayArray(array); // prints the sorted array, should be in descending ordersortAscending(array); // sort the array in ascending orderSystem.out.print("Values in asending order: ");displayArray(array); // prints the...arrow_forward
- please code in java..refer the 2 codes BankAccount and AccountTest.. BankAccount source code is given below and AccountTest source code is added in image Question is to add code to be able to lock the account. for example if someone withdraws a certain amount of money the accounts locks, etc /** The BankAccount class simulates a bank account.*/ public class BankAccount{ private double balance; // Account balance /** This constructor sets the starting balance at 0.0. */ public BankAccount() { balance = 0.0; } /** This constructor sets the starting balance to the value passed as an argument. @param startBalance The starting balance. */ public BankAccount(double startBalance) { balance = startBalance; } /** This constructor sets the starting balance to the value in the String argument. @param str The starting balance, as a String. */ public BankAccount(String str) { balance =...arrow_forwardImplement the following in the .NET Console App. Write the Bus class. A Bus has a length, a color, and a number of wheels. a. Implement data fields using auto-implemented Properies b. Include 3 constructors: default, the one that receives the Bus length, color and a number of wheels as input (utilize the Properties) and the Constructor that takes the Bus number (an integer) as input.arrow_forwardPlease help me fix the errors in the java program below. There are two class AnimatedBall and BouncingBall import javax.swing.*;import java.awt.*;import java.awt.event.ActionEvent;import java.awt.event.ActionListener;public class AnimatedBall extends JFrame implements ActionListener{private Button btnBounce; // declare a button to playprivate TextField txtSpeed; // declare a text field to enterprivate Label lblDelay;private Panel controls; // generic panel for controlsprivate BouncingBall display; // drawing panel for ballContainer frame;public AnimatedBall (){// Set up the controls on the appletframe = getContentPane();btnBounce = new Button ("Bounce Ball");//create the objectstxtSpeed = new TextField("10000", 10);lblDelay = new Label("Enter Delay");display = new BouncingBall();//create the panel objectscontrols = new Panel();setLayout(new BorderLayout()); // set the frame layoutcontrols.add (btnBounce); // add controls to panelcontrols.add (lblDelay);controls.add...arrow_forward
arrow_back_ios
SEE MORE QUESTIONS
arrow_forward_ios
Recommended textbooks for you
- Text book imageDatabase System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationText book imageStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONText book imageDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- Text book imageC How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONText book imageDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningText book imageProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education
Text book image
Database System Concepts
Computer Science
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:McGraw-Hill Education
Text book image
Starting Out with Python (4th Edition)
Computer Science
ISBN:9780134444321
Author:Tony Gaddis
Publisher:PEARSON
Text book image
Digital Fundamentals (11th Edition)
Computer Science
ISBN:9780132737968
Author:Thomas L. Floyd
Publisher:PEARSON
Text book image
C How to Program (8th Edition)
Computer Science
ISBN:9780133976892
Author:Paul J. Deitel, Harvey Deitel
Publisher:PEARSON
Text book image
Database Systems: Design, Implementation, & Manag...
Computer Science
ISBN:9781337627900
Author:Carlos Coronel, Steven Morris
Publisher:Cengage Learning
Text book image
Programmable Logic Controllers
Computer Science
ISBN:9780073373843
Author:Frank D. Petruzella
Publisher:McGraw-Hill Education