This is just a practice problem I wrote that shows the steps to solving a quadratic equation
Main java class package quadaraticformulagui; import javax.swing.JFrame; public class QuadaraticFormulaGui { public static void main(String[] args) { JFrame frame = new JFrame("Quadratic formula"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.getContentPane().add(new quadaraticFormulaGuiPanel()); frame.pack(); frame.setResizable(false); frame.setVisible(true); } } The GUI ( Graphical User Interface )
package quadaraticformulagui;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.Graphics;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;
public class quadaraticFormulaGuiPanel extends JPanel{
g.drawString("Solve rest of equation . . . ", 10, 450);
repaint();
}
} Click to watch the program
Thursday, September 5, 2013
Here are some free resource for Java. Eclipse and NetBeans are the two common (free) compilers. I prefer NetBeans over Eclipse. You can also find free tutorials on YouTube, or just Google Java tutorials. I'll also post some tutorials when I get the chance.
The compiler translates your Java code and converts it into machine language. You need to have Java installed in your computer to compiler Java. Most computer should come default with Java already installed, if its' not you can download it for free from Oracle.com. The best part about Java is that everything you need is free. Java was first written to write codes on appliances such as Microwave, refrigerator etc. Java is a high level language.
package project1; import java.util.Scanner; import java.util.Random; import java.text.NumberFormat; /** * Tony Antony * CSIT 210 - Project 1 * Overview: Gets franchise name and converts it to all uppercase, then displays a total of all sales with a 9 digit confirmation code * Input: franchise name and number of each sizes sold * Output: franchise name, number each size sold, prices of each size, total of each size, and final total of all sales * Variables: CHILD_PRICE, MEDIUM_PRICE, LARGE_PRICE, EXTRA_LARGE_PRICE, childSales, mediumSales, largeSales, extraLargeSales, * childTotal, mediumTotal, largeTotal, extraLargeTotal, finalTotal, confirmation_code, franchise * Plan: * 1. Gets the franchise name as a String * 2. Gets the number of child, medium large and extra large sizes sold as integers * 3. Converts the franchise name to all uppercase * 4. calculates totals for each as doubles * 5. displays the franchise name and receipt in currency format to screen * @version 1.0 09.26.2013 */ public class Project1 { public static void main(String[] args) { // declaring prices of each sizes as constants final double CHILD_PRICE, MEDIUM_PRICE, LARGE_PRICE, EXTRA_LARGE_PRICE; // declaring variables needed long confirmation_code; int childSales, mediumSales, largeSales, extraLargeSales; double childTotal, mediumTotal, largeTotal, extraLargeTotal, finalTotal; String franchise; // assigning values to each sizes CHILD_PRICE = 1.23; MEDIUM_PRICE = 2.34; LARGE_PRICE = 3.45; EXTRA_LARGE_PRICE = 4.56; // starting new scanner and random objects Scanner scan = new Scanner(System.in); Random rand = new Random(); // displays 9 dight random number between 100000000 and 900000000 confirmation_code = rand.nextInt(900000000)+100000000; // currency number format option NumberFormat format = NumberFormat.getCurrencyInstance(); // getting user inputs for franchise name and how many each sizes sold System.out.print("Enter name of franchise: "); franchise = scan.nextLine(); System.out.print("Enter child sizes sold: "); childSales = scan.nextInt(); System.out.print("Enter medium sizes sold: "); mediumSales = scan.nextInt(); System.out.print("Enter large sizes sold: "); largeSales = scan.nextInt(); System.out.print("Enter extra large sizes sold: "); extraLargeSales = scan.nextInt(); // adding extra blank line between user input and output System.out.println(); // equation to find totals for each size childTotal = CHILD_PRICE * childSales; mediumTotal = MEDIUM_PRICE * mediumSales; largeTotal = LARGE_PRICE * largeSales; extraLargeTotal = EXTRA_LARGE_PRICE * extraLargeSales; finalTotal = childTotal + mediumTotal + largeTotal + extraLargeTotal; // converts the franchise name to all uppercase and displays the bill in currency format System.out.println("\t\t\t " + franchise.toUpperCase()); System.out.println("\t\t\t//----//----~----\\\\----\\\\"); System.out.println("\t\t# of Sales\tPrice\t\tTotal"); System.out.println("Child\t\t" + childSales +"\t\t" + format.format(CHILD_PRICE) + "\t\t" + format.format(childTotal)); System.out.println("Medium\t\t" + mediumSales +"\t\t" + format.format(MEDIUM_PRICE) + "\t\t" + format.format(mediumTotal)); System.out.println("Large\t\t" + largeSales +"\t\t" + format.format(LARGE_PRICE) + "\t\t" + format.format(largeTotal)); System.out.println("Extra Large\t" + extraLargeSales +"\t\t" + format.format(EXTRA_LARGE_PRICE) + "\t\t" + format.format(extraLargeTotal)); System.out.println(); System.out.println("\t\tTotal:\t\t\t\t" + format.format(finalTotal)); System.out.println("\t\tConfirmation code: " + confirmation_code); } }