Calculate Coupon Discount In Java?

Feb 9, 2015

i finished up a project here and seem to be running into some issues. I figured its my notation, when i ask a user to enter a number, if its below 10, it should *only* print "No Coupon." but what appears to happen is that the program prints "No Coupon" Plus the "discount coupon and % of purchase."

import java.util.Scanner;
public class assign1c { /* Start of Class 1c */
static double cost;
static double coupon = 0;
static String x = "No coupon";
public static void main(String[] args) {
// TODO Auto-generated method stub

[code]...

View Replies


ADVERTISEMENT

Calculate Price And Quantity With Or Without Discount?

Oct 24, 2014

double price;
String PriceStr;
int quantity;
String QuantityStr;
PriceStr = JOptionPane.showInputDialog("Enter the price: ");
price = Double.parseDouble(PriceStr);
QuantityStr = JOptionPane.showInputDialog("Enter the quantity: ");

[code]....

So i tried to make it allows the user can continue pick the option and calculate the total of every time they select the option, mine is only 2 times.

View Replies View Related

Applet Won't Calculate Discount For Matinee Movies

Feb 21, 2014

I have an applet program here that allows the user to choose a movie then a number of tickets from a drop-down list. A check box should display for users to click so they can receive a discount for matinee movies. The user should be able to click a calculate price button to display the total cost and a clear button to clear each drop-down list and the check box. The program compiled but when I clicked the calculate button, it generated so many error codes like java.lang.nullPointerException and a lot more. I just wanted the program to work properly. Code below:

import java.awt.*;
import java.awt.event.*;
import java.applet.*;
public class Proj4exe2 extends Applet implements ItemListener, ActionListener {
Choice movieChoice = new Choice();
Button calcButton = new Button("CALCULATE");

[Code] .....

The applet code:

<html>
<applet code = "Proj4exe2.java" height = "450" width = "450">
</applet code>
</html>

View Replies View Related

Where To Find Percentage Discount On Item Without Hardcoding

Feb 12, 2014

I'm trying to code an if-else statement where I need to find the percentage discount on an item without hardcoding it.

double Item1=30.50;
double Item2=40.50;
double discount=.07;

These are the values I have. Basically I just need an explanation of how to code a statement so I receive the calculated discount of a Full or Compact.

Here is the excerpt from the code, I can copy the whole code in too if needed.

Java Code:

System.out.println("You selected Item1.");
System.out.print("Have coupon? [Y or N]");
answer = kb.next();
if (answer.equalsIgnoreCase("n"))
System.out.print("Price is 30.50 per day.");
if (answer.equalsIgnoreCase("y"))
>This is what I'm looking for< mh_sh_highlight_all('java');

View Replies View Related

Calculate Percent In Java

Jan 3, 2014

I would like to change the precent from *1.17 (17%) to calc of precent like this :

3% + 5% + 5$

For example :

The resault is 10$ - i want to get :

10$ +3%(0.3$) + 0.5% (0.51$) + 5$ = 15.81$

How i change this line to this calc

if(results[i].getSite()=='Xxx'&&XPrice==0)
{
XPrice =(results[i].getPrice() *1.17);
}
}

View Replies View Related

Java Program To Calculate Diameter?

May 6, 2014

Assume the tanker is a cylinder of length 19.35 feet and volume 1320 gallons. What is the diameter in feet of the tanker truck? To solve this problem, write a Java program to calculate the diameter. For full credit, your Java application must follow these specifications.

1. The program must interactively input the capacity of the tanker in gallons and its length in feet. This should be done in the main method of your Tester class.

2. The input data should then be used to construct a TankerTruck object. You will need to write the TankerTruck class.

3. A TankerTruck method should be used by main to calculate the resulting diameter of the truck in feet.

4. Your program should use the standard Java constant for the math constant PI.

5. The output should be displayed using fixed-point notation, rounding to one decimal place of precision

View Replies View Related

Java Program Method To Calculate Distance

Feb 20, 2015

Write method distance, which calculates the distance between two points (x1, y1) and (x2, y2). All numbers and returned values should be of type double. Incorporate this method into an program that enable the user to enter the coordinates of the points, then calculate and display the distance by calling the method –distance.

I've tried numerous times to make it work and I'm on the right path, however I'm missing some things in the code to make my results look like this later on, which I've attached onto this post.

View Replies View Related

Calculate Sum Of Two Squares - Java And Exception Handling

Jun 19, 2014

I know I can calculate the sum of squares as such:

// SumSquares.java: calculate the sum of two squares
class SumSquares {
static int sumSquares(int a, int B)/>/> {
int asquare;
int bsquare;

[Code] ....

But how can I modify the code so that it inputs a list of integer values in the range of -100 to 100 from the keyboard and computes the sum of the squares input values. And how would I go about using exception handling to ensure that the input values are in range and are legal integers.

View Replies View Related

Java Code To Calculate Variance Of A Set Of Number?

May 2, 2014

I'm trying to write a java code that calculates the varince of a set of number and I wanted to know if this is the proper way to do it.

for (int i = 0; i <= (myArray.length - 1); i++){
variance = Math.pow((myArray[i] - average), 2);

}

View Replies View Related

Calculate Time For Loan Payment - Writing Java From Pseudocode

Nov 26, 2014

calculate how long it would take to pay off a loan of 500 pounds if there was 10% interest monthly, and 100 pounds was paid each month. This code is in a pseudocode,

set months = 1
set balance = 500
set totalpaid = 0;
while balance > 100
balance = balance - 100;
set interest = balance * 0.1
balance = balance + interest
totalpaid = totalpaid + 100
months = months + 1
endwhile
totalpaid = totalpaid+balance
display "you paid "+totalpaid
display "It took you "+months+" months"

View Replies View Related

Java And Exception Handling - Calculate Sum Of Squares (Input Values)

Jun 19, 2014

I know I can calculate the sum of squares as such:

// SumSquares.java: calculate the sum of two squares
class SumSquares {
static int sumSquares(int a, int B)/>/> {
int asquare;
int bsquare;

[Code] .....

But how can I modify the code so that it inputs a list of integer values in the range of -100 to 100 from the keyboard and computes the sum of the squares input values. And how would I go about using exception handling to ensure that the input values are in range and are legal integers.

View Replies View Related

Java Program That Calculate And Print Bill For Cellular Telephone Company

Nov 6, 2014

package p6;

import java.util.Scanner;
public class Bill {
public static void main(String[] args) {
Scanner console = new Scanner(System.in);
//final variables Premium Service
final double monthlyChargeP = 25.00;
final double FordayminutesP = 0.10;

[Code] ....

I can't find the syntax on {} my block is highlighted red in my application

View Replies View Related

Loop That Calculate Distance Traveled - Why Java Not Printing Method Results

Apr 13, 2014

I am trying to write a loop that calculates the distance traveled (distance = speed * time). It should use the loop to calc how far the vehicle traveled for each hour of time. My program asks for hours and then mph but its not calculating time * speed. Here is my code.

public static void main(String[] args) {
 Scanner input = new Scanner(System.in);
System.out.println("Enter Hours Traveled ");
int hoursTraveled = input.nextInt();
System.out.println("Enter MPH ");
int mph = input.nextInt();
 
[Code] .....

View Replies View Related

Java GUI - Calculate And Display Total Cost For Certain Automotive Maintenance Services

May 12, 2014

I'm trying to create a GUI application that calculates and displays the total cost for certain automotive maintenance services. The application should contain hree classes: 1) the main class that creates and displays the window; 2) a panel for the routine services and 3) a panel for the non-routine services. 2 and 3 are instantiated in 1. I'm pretty positive the error lies in the NonRoutinePanel class because when I comment it out of the main class the program runs fine. But I can't quite figure out which lines of code or methods are causing the problem.

When I try running the program I get these error messages:

Exception in thread "main" java.lang.NullPointerException
at java.awt.Container.addImpl(Container.java:1040)
at java.awt.Container.add(Container.java:958)
at javax.swing.JFrame.addImpl(JFrame.java:540)
at java.awt.Container.add(Container.java:926)
at JoesAutomotiveGUI.<init>(JoesAutomotiveGUI.java:38)
at JoesAutomotiveGUI.main(JoesAutomotiveGUI.java:111)

Here's my code for the three classes:

import javax.swing.*; // Needed for Swing class
import java.awt.*; // Needed for BorderLayout class
public class RoutineMaintenancePanel extends JPanel
{
public final double oilChange = 26.00;// cost of oil change
public final double lubeJob = 18.00;// cost of lube job

[Code] .....

View Replies View Related

Calling Methods For Java GradeBook - Calculate Highest And Lowest Grades In Array

Apr 15, 2015

In this project each individual will create a data analysis program that will at a minimum,

1) read data in from a text file,
2) sort data in some way,
3) search the data in some way,
4) perform at least three mathematical manipulations of the data,
5) display results of the data analysis in numeric/textual form, and
6) display graphs of the data. In addition,
7) your program should handle invalid input appropriately and
8) your program should use some "new" feature that you have not been taught explicitly in class.

(Note: this is to give you practice learning new material on your own - a critical skill of today's programmer.) If you do not have a specific plan in mind for your project, below is a specific project that meets all of the qualifications as long as 7) and 8) are addressed in the implementation.

Everything is done except I need to call my methods in my GradeTester.

GradeBook:

/**
*This class creates an array called scores.
*This class determines the length of the array scores and determines the last grade in the array scores.
*This class sorts the array using a bubble sort, and searches the array.
*This class calculates the mean, standard deviation, and the median of the grades in the array scores.
*Once the grades in the array is sorted, the class then calculates the highest and lowest grades in the array.
*/

public class GradeBook {
public final int MAXARRAY_SZ = 20;
double [] scores = new double [MAXARRAY_SZ];
int lastGrade = 0;
double mean = 0;

[Code] ....

View Replies View Related

MVC Calculator - How To Get It To Actually Calculate

Sep 28, 2014

I made a MVC calculator. I was wondering if you could take a look at my design and if I was on track. I am still working on getting it to actually calculate something. All the buttons respond and print text on the JTextField but it is not calculating.

package calculator.MVC;
import javax.swing.JButton;
import javax.swing.JTextField;
public class CalculatorModel {
private int sum;
private int number;
private char opt;

[code]....

View Replies View Related

Calculate (C) How Is The Result 3

Apr 3, 2013

public class NewClass4 {
public static void main(String[] args) {
int a = 1;
int b = 2;
int c = 3;
a += 5;
b *= 4;
c += a * b;
c %= 6;
System.out.println("a = " + a);
System.out.println("b = " + b);
System.out.println("c = " + c);

View Replies View Related

Calculate Radius Of A Pond?

May 31, 2014

This is the code

public class PondRadius {
public static void main (string[] args) {
//Calculate the radius of a pond
//which can hold 20 fish averaging 10 inches long
int fishCount = 20;//number of fish in pond
int fishLength = 10;// Average fish length
int inchesPerFoot = 12;//number of inches in one foot

[Code] ....

And here is the error or exceptions i received

C:javaLesson1>javac PondRadius.java
PondRadius.java:23: error: ')' expected
System.out.println("To hold" + fishCount + fish averaging " + fishLength +" inch
es long you need a pond with an area of
" +

[Code] .....

View Replies View Related

Calculate Lowest Value Of Array

Feb 13, 2015

So I have this code to calculate the lowest value of an array:

public class Exercise1 {
public static void main(String[] args) {
int[] theArray = {1/*/,2,3,4,5,6,7,8,9,10/*/};
int result = Exercise1.min(theArray);
System.out.println("The minimum value is: " +result);

[code].....

and I need to write an exception class that should be thrown if the array does not hold any elements.

View Replies View Related

How To Calculate Difference Between Two Dates

Oct 19, 2014

I have been tasked with creating an invoice (school assignment). Part of the calculations is creating an interest depending on the amount of days between the current date entered, and invoice date entered (The program prompts the user to enter both the current and invoice dates by asking for the day, month and year).

We are also supposed to set the contructor to a default date of 1/1/1900.. but I don't know how or where to code that.

How to calculate the difference between the CurrentDate and Invoice. I have displayed the dates to the user as follows.

public void displayDate() {
System.out.println("
Today's Date: " + month + "/" + day + "/" + year);
}
public void displayInvDate() {
System.out.println("
Invoice Date: " + invMonth + "/" + invDay + "/" + invYear);

View Replies View Related

How Does Program Know To Calculate For Only One Year

Mar 26, 2015

how does the program know to calculate for only one year?

public class Interest2 {
public static void main(String[] args) {
double principal; // The value of the investment.
double rate; // The annual interest rate.
double interest; // The interest earned during the year.

[code]....

View Replies View Related

Calculate Minimum And The Maximum

Nov 21, 2014

i need to calculate the minimum and the maximum, actually it seems to be easy but, the minimum should be the smallest number but 0..this is my code

Java Code:

Scanner s = new Scanner (System.in);
int max = 0 ;
int min = 0 ;
System.out.println(" Please enter 3-5 numbers");
int a = s.nextInt();
int b = s.nextInt();
int c = s.nextInt();
int d = s.nextInt();
int e = s.nextInt();

[code]....

View Replies View Related

How To Calculate Parking Rates

Mar 31, 2015

there are the normal parking rates with two condition using two difference code and two difference calculator method. the fees for the two code also different.i need to display the code, enter time. enter out, and parking charge. i have a problem with the processor method.

View Replies View Related

Calculate Sum Of All Integers Between 1 And Given Integer N

Aug 3, 2014

So I wrote a method that simply calculates the sum of all integers between 1 and a given integer n. The method works fine however, as n gets big the solution will have time and space problems. Some I'm just curious if there is a better method than my iterative one that would produce a better Big O value.

public static int sum(int n)
{
int total = 0;
for (int i = 1; i <=n; i++)
total += i;
return total;
}

View Replies View Related

Using For Loop To Calculate Power?

Oct 16, 2014

I'm new to java and i'm trying to figure out how to calculate power in java using the for loop.

The geometric sequence is (d*c^(n-1)).

So it goes d, d*c^1, d*c^2,......., d*c^(n-1)

??????for (i=1; i<=n; i++){

result

}????????

How to program this. how do i write this using for loop?

View Replies View Related

Calculate Value Of PI Using Series Expansion

Jun 18, 2014

Write a program called ComputePi to compute the value of pi using the following series expansion. you have to decide on the termination criterion used in the computation(such as number of terms used or the magnitude of an additional term). Is this series suitable for compute pi?

PI=4*(1-(1/3)+(1/5)-(1/7)+(1/9)-(1/11)+(1/13)-(1/15)+.......)

View Replies View Related







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