I am trying to make GPA calculator. I decided to use only switch statement and make it as simple as possible. The point is to enter as many classes and students as user wants. I keep getting credit points 0 at the end and also text format is not good too. Here is the code.
import java.util.Scanner;
import java.io.*;
public class SwitchExercise{
public static void main(String[] args) {
String grade = "";
String grades="";
String coursename="";
String headingleft="COURSES";
import java.util.Scanner; class test{ public static void main ( String[] args ) { Scanner scan = new Scanner ( System.in ); int choice = scan.nextInt();
I am making a programme for a calculator to - Divide, multiply, add and subtract. I have the code written but when I am running it and trying to add it was for some subtracting ....
import javax.swing.JOptionPane; public class calculator3 { public static void main(String[] args){ String number1,number2,operatorstring; double result=0,a,b;
We're told to make a cash register program for 5 products using Java. It loops until "-1" is entered on the "Continue?" input dialog box.There should be a:
1. Main Menu - where the user will pick what to buy (one product at a time) like the sample code below and prompt the user if he will buy another product or not. If yes, the program will go back to the main menu to buy another product and if not, continue to the program. And it looks something like this: LEvFOwQ.png
2. Receipt - at the end of every transaction.
3. Daily Sales Report where it shows all receipts then grand total like:
Transaction 1
-subtotal
Transaction 2
-subtotal
and so on then,
GRAND TOTAL
4. Inventory Report where it shows the Items Available before the Selling, Items Sold, and Items Available after Selling in table format.
Below is the code for a simple cash register for only one product that I made but I need to upgrade it for it to work for 5 products. That code will serve as the basis for this program.make the switch or if-else statement for the main menu first and if I got it right I try doing the rest.
int userQty1 = Integer.parseInt(JOptionPane.showInputDialog( "Product ID Product Name Product Quantity Product Price" +prodID1 + " " +prodName1 + " " + prodQty1 + " " +prodPrice1 " " + and so on until prod5));
I am trying to make a calculator using Java GUI. I've managed to make an ActionListener and add it to a button, but I've made an error in my code that I'm unsure of how to solve. Because of how I've written the code, only one number can be placed in the text field. For example, the an ActionListener for the three button on the calculator was added to the button, but no matter how many times the user presses the button, only one 3 will appear in the text field. The code is below:
import javax.swing.*;//import the packages needed for gui import java.awt.*; import java.awt.event.*; public class Calculator { public static void main(String[] args) { JFrame window = new JFrame("Window");//makes a JFrame window.setSize(300,350);
[code].....
As you can see, because the compiler forces the String variable to be final, so when the user presses the button, the code simply shows how a space character and three character would look like, because the String variable can't change. How do I write my code so that every time the user presses the button, a character is added to the text field?
i have a similar problem but what i need to do is to detect an exused absent of which in my notepad is represented by 00 and 0 being an unexcused absent, anyway if a student has an excused absent example a quiz for that day will be deducted from the total quizzes example if i was the teacher and had 2 quizzes of 10 items each and she was absent in one of the quizes instead of let say her score was 9 on the first quiz it should go 9/10 and if it was an unexcused absent 9+0/20 anyway this is my java code and notepad example
import java.io.*; import java.util.*; import java.lang.*; public class GradingSystem { public static void main (String[] args) throws FileNotFoundException
I am having problems with my code I have added the multiplication and division but they will not display also how can I correct any error when dividing by zero?
import java.awt.*; import java.awt.event.*; public class calculator2 extends java.applet.Applet implements ActionListener { TextField txtTotal = new TextField(""); Button button[] = new Button[10];
So I was making a Java Calculator that only adds. The problem is that the numbers are not adding. I think it is because whatever has been clicked is not being saved to be added.
I am a beginner with Java. I have never used SWING before but I have to use it now and I am clueless. I don't know if what I am doing is right.I need to create a simple calculator. My problem is getting the buttons the user clicks to appear in a text field. I know I haven't added the =/*- buttons yet.
I have left actionPerformed practically blank, what to put in ?
import javax.swing.*; import java.awt.*; import java.awt.event.*; /** * Created by IntelliJ IDEA. * Date: 11/12/2014 * Changing Face Program. */ public class Calc extends JFrame implements ActionListener
My assignment is to design a simple GUI calculator using the stack data structure to perform additions, subtractions, multiplications and divisions. But i having error while i press the action there.
import java.awt.*; import java.awt.event.*; import javax.swing.*; import java.util.*; import java.util.Stack; public class JCalculator implements ActionListener {
I need to do a simple while loop pay calculator. I am very new and not sure what I need to do to put all the requirements in the new code from another code. Here is my code that doesn't work yet.
1.Place the wage calculation routines in a while loop. 2.Allow the user to input an individual's hours worked. 3.Accumulate the total regular hours worked, the overtime hours worked, the amount of the regular pay, the amount of overtime pay, and the total payroll, for all of the employees entered. 4.Allow the user to enter a zero (0) as the Boolean expression to end the loop. 5.When the loop ends print out all of the accumulated totals with appropriate labels, each on a separate line.
import java.util.Scanner; public class WhileLoopPayCalc { public static void main(String [] args) { final double REGULAR_HOURS = 40f; final double HOURLY_WAGE = 12.5f; final double OVERTIME = 1.5f; double wage = 0f;
package name;swing library found in javax called to use the graphical contents.
import javax.swing.*; //creating the contents for the calculator public class calc { JButton btn1= new JButton("1 "); JButton btn2= new JButton("2"); JButton btn3= new JButton("3");
[code]....
I have tried different sizes for the 'TextField' but when I change the size, the position changes instead of the size itself.
How can I make the numbers to stay at the textfield of my calculator instead of disappear like when I type 1 then hit the + sign the number 1 disappears from the textfield I would like to have this (1+1) showing in the text field and also if try to press only + , * , - , / to show error.
Our goal is to write a pretty simple program, one that takes the 12 digit UPC code entered by a user and to not only spit it back out in a format with dashes using toString, and also returns the first digit, a 2 more groups of digits numbering 2-6 and 7-11, and finally display the 12th digit. It then performs an equation to check the last digit and make sure the UPC code is correct.
However, being so new to java (I only learned visual basic before), with this I was introduced to two new concepts that for some reason I simply cannot grasp for the life of me: Using and calling the toString method, and calling on methods that are created in a completely different class file.
The first section of code is my UPC class, which is meant to contain all my methods as well as the toString to be called on:
public class UPC { // Instance variables private int itemType; // digit 1 private int manufacturer; // digits 2,3,4,5,6 private int product; // digits 7,8,9,10,11 private int checkDigit; // digit 12
How can i write a java program that simulate a simple calculator that performs the basic arithmetic operations of JAVA. (JOption Pane and Repeat control structure)
Example : Addition, Subtraction, Multiplication, Division.
The program will prompt to input two floating point numbers and a character that represents the operations presented above. In the event that the operator input is valid, prompt the user to input the operator again.
I had to make a chart where it took miles 1-10 and convert it to kilometers and then on the other side it needs to show 25-65 (in 5's) kilometers to miles and I dont know how to switch the sides...
import java.util.Scanner; public class MilesAndKilos { public static void main(String[] args) { int miles; double kilometers=1.60934; System.out.println(" Miles Kilometers Kilometers Miles"); for(miles=1;miles<10;miles++){ kilometers = miles * 1.60934; System.out.printf(" %2d %8.3f | ", miles,kilometers); } }//end of main method }
Basically the problem is I've been trying to loop my switch (if this is even possible) until the user enters a correct number between 1 and 4. But for some reason when the user enters a correct number (1,2,3,4) the loop runs again. Even when the user enters a wrong number the switch ignores the default and repeats what is in the do.
Am I just trying to loop something that cannot be looped or have I gone?
I needed to make a switch with a string ,but eclipse told met there was an error and that the fix was to switch to 1.7 compliant. I did so and now when i run my program errors come back.
Here are the errors :
Exception in thread "main" java.lang.UnsupportedClassVersionerror: start : Unsupported major.minor version 51.0 at java.lang.ClassLoader.defineClass1(Native Method) at java.lang.ClassLoader.defineClassCond(ClassLoader.java:637) at java.lang.ClassLoader.defineClass(ClassLoader.java:621) at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:141) at java.net.URLClassLoader.defineClass(URLClassLoader.java:283) at java.net.URLClassLoader.access$000(URLClassLoader.java:58)
this is what code i have so far i want to try and get the computer to output a String type result rather than a number and i wonder if there is a way to output the score after the user is done with the game. I couldn't really see if there was a way to incorporate a switch statement.
import java.util.Scanner; import java.util.Random; public class RPSLS { public static void main(String[] args) {