Java program help. You are to write a Java program that has at least three funct
ID: 3603376 • Letter: J
Question
Java program help.
You are to write a Java program that has at least three functions: main, bubSort, and binSearch. main will be the entry point/driver, bubSort will be called to perform a bubble sort, and binSearch will be called to perform binary searches. Your program should input two separate data files. Both contain text strings. Neither file will be excessively large. You should not modify the files themselves. You will be able to view and become familiar with the files, but you should still write a general program. You should not write your program to work with these files, specifically. Your program should work properly for files containing any number of strings up to 50 The first file, InputFile1, will contain alphanumeric strings of varying lengths. You should input the file and sort it with a bubble sort. The second file, InputFile2, will also contain alphanumeric strings of varying lengths. You should input this file and use binSearch to determine if each of the InputFile2 strings is in the sorted InputFile1. In both your sort and search functions you will need to compare two strings repeatedly to implement the algorithms. Comparing two strings with relational operators, !, etc.) is permitted in Java and will not result in a compilation error. However, it is probably not the operation you want. Also, when searching with your binary search function you will need to determine greater than, less than and equality. You should study the functions of the String class to find why using the relational operators is not correct and to determine how to correctly compare two strings You should print a clearly labeled, formatted report of your results. Submit your work as a jar file through Canvas as detailed in the Lab Submission Guidelines document. Email submissions will not be accepted. Your .jar file should be executable. Your .jar file should contain your source code. If your source code is recompiled, it should produce a.class file identical to the class file in your .jar Your jar file should also contain both data files with file names identical to the file names above. All internal references to the files in your program should be the file names only. Do not include the full path.Explanation / Answer
//package org.pgs.seminar; 002 import javax.swing.*; 003 004 import java.awt.event.*; 005 import java.awt.*; 006 public class GuiDemo1 extends JFrame// implements ActionListener 007 { 008 public static void main(String [] args) 009 { 010 new GuiDemo1(); 011 } 012 JTextField name, amount, cash,change; 013 JRadioButton small, medium, large, thick, thin; 014 JCheckBox Beef, Mushroom, Ham,Onion,Pineapple; 015 JComboBox PizzaType, Order; 016 String type[]={"Select Pizza Type","Super Supreme","Meat Lover", 017 "Hawaiiwan Supreme","Bacon Supreme"}; 018 String orders[]={"Type of Order","DineIn","TakeOut"}; 019 public GuiDemo1 () 020 { 021 this.setTitle("PizzaHat"); 022 this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); 023 JPanel panel1 = new JPanel(); 024 panel1.setLayout(new GridBagLayout()); 025 addItem(panel1, new JLabel("Customer Name:"), 026 0, 0, 1, 1, GridBagConstraints.WEST); 027 addItem(panel1, new JLabel("AmountDue:"), 028 0, 7, 1, 1, GridBagConstraints.WEST); 029 addItem(panel1, new JLabel("Cash:"), 030 0, 8, 1, 1, GridBagConstraints.WEST); 031 addItem(panel1, new JLabel("Change:"), 032 0, 9, 1, 1, GridBagConstraints.WEST); 033 034 name = new JTextField(20); 035 amount = new JTextField("Php",10); 036 amount.setEditable(false); 037 cash = new JTextField(20); 038 change = new JTextField("Php",20); 039 change.setEditable(false); 040 addItem(panel1, name, 1, 0, 2, 1, 041 GridBagConstraints.WEST); 042 addItem(panel1, amount, 1, 7, 1, 1, 043 GridBagConstraints.WEST); 044 addItem(panel1, cash, 1, 8, 2, 1, 045 GridBagConstraints.WEST); 046 addItem(panel1, change, 1, 9, 1, 1, 047 GridBagConstraints.WEST); 048 addItem(panel1, new JComboBox(type), 049 0, 1, 1, 1, GridBagConstraints.EAST); 050 addItem(panel1, new JComboBox(orders), 051 0, 1, 2, 1, GridBagConstraints.EAST); 052 Box sizeBox = Box.createVerticalBox(); 053 small = new JRadioButton("Personal"); 054 medium = new JRadioButton("Regular"); 055 large = new JRadioButton("Family"); 056 ButtonGroup sizeGroup = new ButtonGroup(); 057 sizeGroup.add(small); 058 sizeGroup.add(medium); 059 sizeGroup.add(large); 060 sizeBox.add(small); 061 sizeBox.add(medium); 062 sizeBox.add(large); 063 sizeBox.setBorder( 064 BorderFactory.createTitledBorder("Size")); 065 addItem(panel1, sizeBox, 0, 2, 1, 1, 066 GridBagConstraints.NORTH); 067 068 Box topBox = Box.createVerticalBox(); 069 Beef = new JCheckBox("Beef"); 070 Ham = new JCheckBox("Ham"); 071 Onion = new JCheckBox("Onion"); 072 Pineapple = new JCheckBox("Pineapple"); 073 Mushroom = new JCheckBox("Mushroom"); 074 075 add(Beef); 076 add(Mushroom); 077 add(Ham); 078 add(Onion); 079 add(Pineapple); 080 topBox.add(Beef); 081 topBox.add(Mushroom); 082 topBox.add(Ham); 083 topBox.add(Onion); 084 topBox.add(Pineapple); 085 topBox.setBorder( 086 BorderFactory.createTitledBorder("Extra Toppings")); 087 addItem(panel1, topBox, 1, 2, 1, 1, 088 GridBagConstraints.NORTH); 089 090 this.add(panel1); 091 this.pack(); 092 this.setVisible(true); 093 } 094 private void addItem(JPanel p, JComponent c, 095 int x, int y, int width, int height, int align) 096 { 097 GridBagConstraints gc = new GridBagConstraints(); 098 gc.gridx = x; 099 gc.gridy = y; 100 gc.gridwidth = width; 101 gc.gridheight = height; 102 gc.weightx = 100.0; 103 gc.weighty = 100.0; 104 gc.insets = new Insets(5, 5, 5, 5); 105 gc.anchor = align; 106 gc.fill = GridBagConstraints.NONE; 107 p.add(c, gc); 108 109 } 110 }
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.