Calculating Commission With Loops / If Else Statements And JOptionPane

Mar 8, 2015

SalesMan receives 200$ a week plus 9% of commission on the items he had sold that week

item 1 = 5.00
item 2 = 10.00
item 3 = 1.00
item 4 = 25.00

My code : (((I honestly dont know how to loop it... it must ask "What item did you purchase, and have the user input the number of item they purchased THAN looped back to ask again what item did they purchase untill they hit -1 to exit the loop))

import javax.swing.JOptionPane;
public class ControlStructure{
public static void main(String [] args){
double item1 = 5.00;//item 1 price
int quan1 = 0;
double total1 = 0;

[Code] .....

View Replies


ADVERTISEMENT

Calculating Area With JOptionPane?

Sep 9, 2014

I am supposed to be doing a class assignment that calculates the area of a triangle and outputs with JOptionPane. I was able to fix some errors, but it's uncovering more errors.Here is my code:

import javax.swing.JOptionPane;
import java.util.*;
import java.text.DecimalFormat;
import java.util.StringTokenizer;

public class Area {
public static void main (String [] args) {
double a, b, c; //Input sides of triangle
double x; //Perimeter of triangle
double area; //Area of triangle
StringTokenizer st;

[code]....

View Replies View Related

While Loops Within If Else Statements?

Dec 19, 2014

What I'm trying to do below is to say if (adultTickets > 0) I want to bypass the studentOAP tickets question and go straight to the question about dinner. But if (adultTickets ==0) I want to go to the studentOAP question and then if the (studentOAPTickets >0) to go to the question about dinner. But if the (studentOAPTickets ==0) I want to go straight to the question about the contact number.

System.out.print("How many adult tickets do you require? ");
int adultTickets = 0;
boolean validAdultValue = false;
while (validAdultValue == false) {
if(aScanner.hasNextInt())

[Code] ....

View Replies View Related

For Loops Inside Of Switch Statements

Mar 30, 2014

This is what I'm trying to do;

Java Code:

import java.util.Scanner;
class test{
public static void main ( String[] args ) {
Scanner scan = new Scanner ( System.in );
int choice = scan.nextInt();

[Code] ....

How is this doable?

View Replies View Related

Iterative Statements / Writing To Files / Nested Loops

Dec 2, 2014

So basically i have to read from a text file and get some information back from that and print to screen. Im quite confused and im not sure what loop i should use first to scan the text and receive certain information back?

View Replies View Related

Creating A Commission Calculator

Mar 19, 2014

I need to create a simple Java program for a commission calculator with the following requirements: I need to ask the user to enter their total sales (as a double) in at the keyboard and I need to use "if" statements to tell them their commission (sales * commission rate) using the following criteria:

o < $8000 in sales – Commission rate = 10%
o $8000 to $12000 in sales – Commission rate = 12%
o $12000.01 to $18000 in sales – Commission rate = 15%
o $18000.01 to $20000 in sales – Commission rate = 18%
o > $20000 in sales – Commission rate = 20%

Then for the output the user’s Commission in a well formatted way (use the DecimalFormat class) .In comment blocks have a description of what the program does.

import java.util.Scanner;
public class CommissionCalculator
//This program calculates the commission of sales
{
public static void main(Strings[] args)
{
// create a scanner
Scanner input = new Scanner(System.in);
//define variable
double sales; //inputted sales amount
double commission = 0; //commission pay amount
 
[code]....

View Replies View Related

Payroll System For Hourly / Fixed Monthly And Commission Paid Workers Of Company

Dec 21, 2014

I am doing a program where i have to implement a payroll system into a company for hourly, fixed monthly and commission paid workers. I also have to put the method which i did. the problem is I cant tell if my calculation is wrong or if i am missing a codes some where. The output is not giving me the answer that I was at least expected,

Here is my method:

{
< double total_deduction;>
< total_deduction = gross_pay - deduction;>
< return total_deduction;>
}
< public static double calGrossH(double hours_worked, double pay_rate)>

[Code] .....

I have done a lot researching and have come up with some search with almost the same calculation and I have also asked employees of a company on how they calculated hourly rate, commissions rate and fixed rate for all workers and gotten the same response but for some reason the output is not what it is supposed to output. here is my output.

<
un:>
<please enter the number of employees to be processed 31>
<please enter employee id number 3669>
<please enter employee first name>

[Code] ....

I dont know if I am missing some calculation somewhere or codes been researching and bussing my brains to figure out where is the missing codes or calculation.

View Replies View Related

Basic GUI Calculator - Display Amount Of Commission And Total Annual Salary In Dollar Format

Apr 28, 2014

So, I am supposed to write a program that calculates the total annual compensation for a salesman using user input for the salary, sales, and commission rate (list of 3 predefined commission rates. have to display in dollar format the amount of commission and total annual salary.

CommCalc class

public class CommCalc
{
//attributes of class, stored data
private double sales;
private double salary;
private double rate;
//and a total field? beware stale data.
//store sales argument from sales field
public void setSales(double sal)

[Code] ....

I know that i have to fix some of the semantics . I have this code that I made earlier, is there an easy way to make it into a GUI interface? Or will I have to go throughthe code lines to add the JOptionPane? And I am a little confused on how to make a list (array) for the commission rate.

View Replies View Related

Do While And JOptionPane

Feb 25, 2014

Is there anyway I can write a do while statement for this program. I haven't seen anyway to do it anywhere.

Java Code:

import javax.swing.JOptionPane;
public class History {
public static void main(String[] args)
{
//First Question: What is the capital of Mexico?
String[] question1 = {"Mexico City", "Paris" //The choseable answers are made using String
,"Washington D.C", "Tokyo"};

[Code] .....

View Replies View Related

JOptionPane Cannot Be Resolved

Aug 27, 2014

I Can't run this simple program

import java.util.Scanner;
import javax.swing.JOptionpane;
public class Project {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);

[code]...

This is the Error that i get in console!"Exception in thread "main" java.lang.Error: Unresolved compilation problem: JOptionPane cannot be resolved at Project.main(Project.java:10)"

View Replies View Related

JOptionPane With Multiple JTextFields?

May 27, 2014

Here's My code to create multiple JTextfields in a Single Option Pane.

My goal is simple.

Take some input from the user and then store it a TEXT File.

package printer;
import java.awt.Toolkit;
import java.io.BufferedWriter;
import java.io.FileWriter;
import java.io.IOException;
import javax.swing.*;
 public class Database {
 JTextField name = new JTextField();
JTextField roll = new JTextField();

[code].....

View Replies View Related

JOptionPane Printing From A For Loop?

Feb 13, 2015

I am writing a program that has to do with ciphers and cipher shifts. The program itself works fine, but I am having trouble printing out the answers to JOptionPane. I know the basics of JOptionPane, but my problem is this:

Majority of my program takes place in a for loop, and resolves the cipher (it is a basic cipher program) 1 digit at a time. So, only the last DIGIT (I don't know how to convert a digit to a CHAR in JOptionPane) is printed to JOptionPane. Here is my code:

public static void main(String[] args) {
String cipher = JOptionPane.showInputDialog(null,
"Please enter a sentence or word that you wish to encode or decode. This program uses " + " a basic cipher shift.");
int answer = 0;
String upperCase = cipher.toUpperCase();
char[] cipherArray = cipher.toCharArray();

[Code] .......

View Replies View Related

JOptionPane Hover Effects?

Jul 14, 2014

Just wondering if there was a way to change a JOptionPane's display message dependent on the button the user is hovering over. I.e.: Hover option1, shows one message; hover option2, shows a different message, etc.. but within the same JOptionPane (not showing a new one).

View Replies View Related

Custom Image On JOptionPane

Dec 24, 2014

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import javax.swing.ImageIcon;
import javax.swing.JOptionPane;
public class Main

[Code] ....

I cant custom my own icon. There is no error. But the image that I tried to show in the joptionpane is not showing. What should i do?

View Replies View Related

Decimal Values - JOptionPane

Jul 1, 2014

I am a beginner in Java and I am currently learning about JOption pane.Using Strings I am accepting an input from the user and by using the Interer.ParseInt(variable) option I am able to multiply this two strings using the code below.

String Length;
Length = JOptionPane.showInputDialog("Enter the Length");
String Breadth;
Breadth = JOptionPane.showInputDialog("Enter the Breadth");
System.out.println(" Area is " + (Integer.parseInt(Breadth) * Integer.parseInt(Length)));
System.exit(0);

How Do I make my code accept Decimal values. E.g. My Code should accept 10.02 as Length and 20.42 as Breadth and give the product a Decimal.

View Replies View Related

JOptionPane - Popup Box While Browsing

May 8, 2014

Is it possible to make it so that when the popup box comes up I will only be able to click on the box? For example, I would be browsing the internet while the program is running and then the box pops up and I am forced to answer the question before I can click on anything else. If it is possible, how do I do it?

View Replies View Related

Nested If Statements

Sep 11, 2014

I am in the process of creating a calculator GUI that calculates different answers based on inputs two main comboboxes and numbers in the appropriate textfields. The first one allows the user to choose from 18 different materials, while the second has the user choose between two different shapes. In a brief word explanation, here's how it's set up:

User chooses material.
User chooses shape.
User types in appropriate values.
'Calculate' button clicked.
If shape = rectangle, execute rectangle calculation.
Else if shape = cylinder, execute cylinder calculation.

Everything works just fine with zero errors on all 18 materials and all kinds of decimal numbers when the second shape is selected. So the math and layout is solid. However, when the first shape is selected, it returns a $0.00 answer regardless of the input values (still no red-line errors). In efforts to troubleshoot, when I have /* Cylinder section */, the rectangle section works to a 'T'. This, I believe is caused by poor formatting in the syntax of the 'if' 'else if' in regards to the shape combobox.

//If 'Rectangle' is selected:
if(shapeDropDown.getSelectedIndex()==1) {
//6061
if(materialDropDown.getSelectedIndex()==0) {
String msg0 = "The price is: $"
+ currencyFormat.format((0.098*(number2*number3*number4)*3.06));
totalPrice.setText(msg0);

[code]....

View Replies View Related

Trying To Add Values Under Different If Statements

May 1, 2014

My initial question had to do with looping but now I'm having trouble adding certain variables.

The original thread is here: [URL] ....

If you look at the end of the code it won't recognize the "overtime" and "hourDiff". I have to use it for each level the
user chooses and am not sure how to do so. Even if I put it under the if{ statement it won't calculate. I assume it's due to it being cut off from other blocks but I'm not sure how to combine them.

My code is:

import javax.swing.JOptionPane;
public class Pay {
public static void main(String[] args) {
double salary2 = 20.00;
double salary3 = 22.00;

[Code] ....

View Replies View Related

Tic Tac Toe Game Using While Statements

Oct 23, 2014

import java.util.Scanner;
public class TicTacToe {
public static void main(String[] args) {
//Create scanner
Scanner in = new Scanner(System.in);
//Declare variables to hold the board

[Code] ....

I need to create a while statement for random computer moves.

View Replies View Related

If Statements Without Braces

Nov 2, 2014

I'm doing some revision for my OCAJ atm, & I came across this code in a mock question which takes two int arguments & simply returns the larger.

public int max(int x, int y){
if (x > y)
return x;
return y;
}

When evaluating it I thought this would be invalid code as would always return x. But it transpires I was way off & that this actually works! In playing around with it, it seems like the first return statement is treated as:

if {// this bit } & the second return is treated as: else{ //this bit}.

What baffles me though is that you can put any amount of additional statements before the second return and it continues to work, however if you put even a single statement before the first return, the whole thing falls over.

I guess my two questions are - Am I right in my discovery above ( that statements preceeding the first return will always break it)? & secondly is this a good way of coding? for readability, I would always do it as:

public int max(int x, int y){
if (x > y){
return x;
}
else{
return y;
}
}

View Replies View Related

If Else - How To Not Execute Both Statements

Oct 4, 2014

I am making a program, where the user answers 3 questions and then I add the number of correct answers in to the (int) numberofcorrect variable, then I want to print the results, and no matter how many correct, the program executes first the correct if statement, then the else statement.

Eg: I have 2 correct it will print:

"Grade B, 2 of 3 "

"You failed the test"

Why does it do that? How can I change my code so the else statement dosent print if one of the if statments is allready printed?I want to know how to not execute the else statement, if one of the if statements have allready been executed.Below is my current code for this problem:

if (numberofcorrect == 3){
System.out.println("Grade A, full score");}
if (numberofcorrect == 2){
System.out.println("Grade B, 2 of 3 ");}
if (numberofcorrect ==1) {
System.out.println("Grade C, 1 of 3");}
else {
System.out.println("You failed the test"); }

View Replies View Related

Swing/AWT/SWT :: How To Change Font For JOptionPane

Apr 21, 2014

I am quite familiar with using JOptionPane and its various displayXDialog() methods and reasonably familiar with changing fonts.

I have a JOptionPane.displayMessageDialog() that is working fine but I decided to make the font larger.

I found an example from which I coded:

Font font = UIManager.getFont("OptionPane.font");
UIManager.put("OptionPane.font", new Font(font.getName(), font.getStyle(), 24));
font = UIManager.getFont("OptionPane.font");
JOptionPane.showMessageDialog(this, "Welcome to Mover", "About Mover", -1); // no icon

After the UIManager.getFont() call after the UIManager.put() call, font shows the new font size of 24, but the showMessageDialog() dialog still has the default font.

And yes I understand that, when this works, it will affect every JOptionPane in my program.

I also tried:

Font font = UIManager.getFont("OptionPane.font");
JOptionPane message = new JOptionPane("Welcome to Mover", JOptionPane.INFORMATION_MESSAGE);
JDialog dlg = message.createDialog("About Mover");

[Code] ....

This gave me a dialog with the default font and an unwanted icon.

So I tried

// both
Font font = UIManager.getFont("Dialog.font");
// and
Font font = UIManager.getFont("JDialog.font");

and planned to use that font in my setFont() call but font was null.

View Replies View Related

Convert Buffered Reader To Joptionpane?

Feb 16, 2015

I have to make an application called miles to meters that converts miles to meters that asks for user input through joption pane and the output can be eather system.out.println or joption pane, I found the code i need but it uses buffered reader for input not joption pane. Here is the source code

import java.io.*;
import java.util.*;
class MetersToMiles{
public static void main (String[] args)throws
Exception{
// 1 meters = 0.00062137119 miles;

[Code] ....

View Replies View Related

Simple Password Checker Into JOptionPane?

Sep 1, 2014

i have this source code...

import java.util.Scanner;
//I had to use scanner in this program because I had to create objects that were in the Scanner class, such as in row 16.
* This program confirms a password typed into a *
* console window *
*/
 public class Homework1 {
public static void main(String[] args) {
//Needs to add a scanner to the program to continue on
Scanner keyboard = new Scanner(System.in);

[code]....

Now I need to create a second version of this program that uses JOptionPane to get the inputs from the user and show the output!

View Replies View Related

Java JOptionPane Text Unreadable

May 17, 2014

When I use this code

import javax.swing.*;
public class Swag {
public static void main ( String[] args) {
String name = JOptionPane.showInputDialog("What is your name?");
  String input = JOptionPane.showInputDialog("How old are you?");
int age = Integer.parseInt(input);
  System.out.print(" Hello, " +name);
System.out.println("Next year you'll be " +(age+1));
}
}

And run it, it ends up looking like thisH1765.png I'm running windows 8, the latest x64 JDK, no type of custom font or anything that I know of. I've run this through eclipse, CMD, and uninstalled and reinstalled Java. I tried using another example of JOptionPane usage from a site and running it, still looks the same.

View Replies View Related

JOptionPane Message Boxes Not Opening?

Nov 25, 2014

For some reason the two JOptionPane message boxes at the end of my code don't seem to open when I run the program.

package assg2.kevin;
 import java.awt.HeadlessException;
import javax.swing.*;
import java.util.Arrays;
import java.util.Random;
 public class Assg2Kevin {
 
[Code] ....

View Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved