Average Program - Divisible Numbers Not Calculating Correctly

May 21, 2015

For some reason, the averages aren't calculating correctly. I'm aware I need to convert to double if I'm dividing by an odd amount but that itself isn't the issue. It's just simple easy divisible numbers that are not being calculated correctly. For instance, (10 + 10 + 10 + 50) / 4 = should be 2 but I get 10.

Here is the code:

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

[Code] ....

View Replies


ADVERTISEMENT

Code Not Calculating Annual Sales Rate Correctly

Jul 19, 2014

My java code complies correctly runs and displays correctly but it is not calculating the annualSales * rate correctly.

/*
* The program will calculate annual salary and commission for a sales person.
* The user shall input the annual sales to calculate.
*/

package salescommission;

import java.util.Scanner;
public class SalesCommission {

[Code] ....

run:

The Salesperson earns a fixed annual salary of $10000.0.

Enter annual sales: 100000.00

The annual sales of the salesperson is $10000.0 using a 10% commission. (the is incorrect)

The total annual compensation of the salesperson is: $20000.0.

BUILD SUCCESSFUL (total time: 13 seconds)

View Replies View Related

Finding Divisible Numbers And Replace With String

Jul 13, 2014

My interest in Java leads me to try and print numbers from 1-100. The output should show all numbers from 1-100 and each number that is divisible by by 13 should be replaced with a string "Fuzzy".

public class Fuzzy {
public static void main (String[]args){
for(int i = 0; i < 100; i++)
if(i % 13==0)
System.out.print(i + "fuzzy");
}
}

View Replies View Related

Numbers Divisible By 6 - Code Is Giving Different Result Then Expected

Aug 22, 2014

I am having problems with writing a simple program to see if a number is divisible by 6.

public void run() {
println("This program will display all numbers divisible by");
println(" 6 between 1 and 100.");
int x =1;
boolean divide =(x%6==0);

[Code] ....

It is telling that every number is not divisable by 6?

View Replies View Related

Calculating Average Of Values

Apr 21, 2014

I'm struggling with this assignment I was given:

Given list of positive integer values, write a program to calculate average of the values. List terminates with -1.

View Replies View Related

Java Calculating Mean Average

Feb 21, 2014

I am trying to do the following java assignment and every thing seems to work fine except when I put a number<4 or >10 it prints both "Invalid grade!"

"You didn't enter any data!" what I wanted is to print only "Invalid grade!" I tried to fix it but I couldn't.

Create a program that asks for results of exams and calculates the mean average of the grades. Grades are floating point numbers between 4 and 10. Program asks for grades until a negative number is typed. If user gives a grade other than a number between 4 and 10, the text "Invalid grade!" will be printed on screen and program asks for another grade. Finally the program prints the number of inputted grades and their mean average on screen as shown in the example print. If no grades were inputted, the notice "You did not input any grades." is the only thing printed on screen.

A double type variable is to be used to store the value of the average.

Program is written to a class called Average.

Example output

Program calculates the average of inputted grades.

Finish with a negative integer.

Input a grade (4-10): 5
Input a grade (4-10): 6,5
Input a grade (4-10): 7,5
Input a grade (4-10): 7
Input a grade (4-10): 0
Invalid grade!
Input a grade (4-10): -4
4 grades inputted.
Average of the grades: 6.5

Java Code:

import java.util.Scanner;
public class apples {
public static void main(String[] args)
int inputNumber=0;
int sum;
int count;
double average;

[Code] .....

View Replies View Related

Calculating Average Of Two Ints And Converting To A Double

Oct 31, 2014

I have been asked to construct an application that will read in the exam mark and coursework mark and then print out to 1 decimal place the average of the coursework and exam mark. When I submit it it says it's incorrect.

class Main
{
public static void main( String args[] )
{
int ExamMark=71;
int CourseworkMark=40;
double mark = (double)(ExamMark + CourseworkMark) / 2;

[Code] ....

View Replies View Related

Calculating Average Of Two Ints And Converting To Double In Java?

Oct 31, 2014

how to use Java and for my coursework I have been asked to construct an application that will read in the exam mark and coursework mark and then print out to 1 decimal place the average of the coursework and exam mark. When I submit it to the coursework submission system it says it's incorrect.

The answer that it's asking for is the answer that my code produces (ex = 71 cw = 40 mark = 55.5) But for some reason it says this when I submit it:

-#### << Differences between expected (<) your answer (>) >> ------------
1c1
< ex= 91 cw = 80 mark = 85.5
---
> ex = 71 cw = 40 mark = 55.5
-------------------------------------------------------------------------

Check the above output for why this attempt failed And when I change the ex to 91 and cw to 80 it asks for > ex = 71 cw = 40 mark = 55.5 again.

class Main
{
public static void main( String args[] ) {
int ExamMark=71;
int CourseworkMark=40; 
double cost = (double)(ExamMark + CourseworkMark) / 2;
  System.out.printf("ex = " + ExamMark + " cw = " + CourseworkMark + " mark = " + cost);
System.out.println();
  }
 }

View Replies View Related

Calculating Average Of Two Arrays - Calculation Coming Out Incorrect

Oct 8, 2014

I am working on an assignment, and I have come up with a program that runs, but it does not run correctly. This is the assignment:

Write two overloaded methods that return the average of an array with the following headers:

public static int average(int[] array)
public static double average(double[] array)

Write a test program that prompts the user to enter ten double values, invokes this method and displays the average value.

When I run it my averages are coming out incorrect, and I am not sure why. I have tried moving and rearranging things and nothing is working.

Java Code:
public static int average(int[] array) {
int sum = 0;
int average = 0;

[Code].....

View Replies View Related

Calculating Total And Average Of Price Of Items - Not Getting Correct Output

Jun 27, 2014

Why is my program not calculating the total and average of the price of the items and not printing it out?

Java Code:
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package assignment4;

[code]...

It prints out everything but the total of the items and I dont know why. :(

View Replies View Related

If Number Is Even - Divisible 3 Or Divisible By 4

Apr 7, 2014

I have to make a program that determines whether an integer put in by the user is odd, divisble by 3 or divisble by 4..

import java.text.DecimalFormat;
import java.util.Scanner;
public class numbers {
public static void main (String[] args)

[Code] ....

I'm getting the error that div3 hasn't been initialized ... How do I even implement code to determine whether the number is divisible by 4 or 3?

View Replies View Related

Swing/AWT/SWT :: Getting Numbers And Calculating Them In JTable

May 26, 2014

What I am trying to do on jtable is when a user enters values of numbers in the table, by click of button, those numbers are calculated and display in another column. For example, 4 = 2 + 2 in a table.This means getting inputs from user and summing them up. My getRowCount() and getValueAt() methods don't seem to work for me recently.

View Replies View Related

Fraction Class - Calculating Less Than Percentage GCD On Negative Numbers

Feb 15, 2014

I've been writing a fraction class code below that does a number of arithmetic calcs and when I run it these are the results I get. My gcd doesn't work when it comes to negative fractions and I'm not quite sure how to print.out the boolean methods ((greaterthan)), ((equals))and ((negative)). I'm also not sure if I have implemented those 3 methods properly. I'm still learning how to do unit testing.

Enter numerator; then denominator.
-5
10
-5/10
Enter numerator; then denominator.
3
9
1/3
Sum:
-5/30
-0.16666666666666666
Product:
-5/30
-0.16666666666666666
Devide:
-15/30
-0.5
subtract:
-45/90
-0.5
negative:
1/6
0.16666666666666666
Lessthan:
1/6
0.16666666666666666
greaterthan:
1/6
0.16666666666666666

FRACTION CLASS

import java.util.Scanner;
public class Fraction
{
private int numerator; //numerator
private int denominator; //denominator

[Code] ....

View Replies View Related

Adding Fractions - Loop For Calculating Total Of Series Of Numbers

Mar 8, 2014

I'm just not noticing why it won't display the answer. I'm trying to solve this book problem......

"Write a for loop that calculates the total of the follower series of numbers:

1/30 + 2/29 + 3/28......+30/1"

Here is what I have..

public static void main(String[] args) {
double total = 0;
for (double a = 1, b = 30; b < 1; a++, b--) {
total += (a / b);
}
System.out.println(total);
}
}

When launched, the output is 0.0. I tried changing the variables a and b to doubles but didn't change anything...

View Replies View Related

Sum And Average Of Input Numbers

Jan 25, 2014

How to create a simple program that can input number from 1 to n. and display the numbers which input by the user and also display the sum and average of it.

Ex.
Please input a number:
1 2 3 4 5 6 7 8 9 10

the sum numbers of 12345678910 is 55
the average number of 12345678910 is ______,

View Replies View Related

Average Of Numbers With Sentinel Value Equals To 0

Mar 27, 2014

(Count positive and negative numbers and compute the average of numbers). Write a program that reads an unspecified number of integers, determines how many positive and negative values have been read, and computes the total and average of the input values (not counting zeros). Your program ends with the input 0. Display the average as a floating-point number.

I moved the different boolean statements around, but I'm not getting the sentinel value to end the run. It continues to let me add integers endlessly. The code I wrote is below:

package exerciseFourOne;
import java.util.Scanner;
public class AverageOfIntergers {
public static void main(String[] args) {
// TODO Auto-generated method stub
int positive = 0; // number of positive integers
int negative = 0; // number of negative integers
int sum = 0; // value of sum of integers

[Code] .....

View Replies View Related

Array Of Numbers Not Able To Get Correct Average Value

May 26, 2015

I have the following methods:

public static int getSum(int[] data) {
int sum = 0;
for (int i = 0; i < data.length; i++) {
sum += data[i];
}
return sum;

[code]....

The input is the following arary (Its from the Junit test that fails this): [Integer.MIN_VALUE, -1, 0, 1, Integer.MAX_VALUE].I get an average of 0.0 when it should be -0.2.

View Replies View Related

Math On Three Numbers - Get Average / Sum And Number Entered By User

Feb 25, 2015

Java program : For this assignment you are going to write code for the following class:

MathOnThreeNumbers

Here are the specifications of class MathOnThreeNumbers:

Methods of class MathOnThreeNumbers:

1. inputThreeNumbers
2. getAverage
3. getSum
4. getNumberOne
5. getNumberTwo
6. getNumberThree

Constructor of class MathOnThreeNumbers

write a constructor that initializes the first, second, and three numbers to 1, 2, and 3 respectively.

Specs for the methods methods:

1.
name: inputThreeNumbers
accessibilty: public
arguments: none
what it does: asks the user for three numbers of type double

2.
name: getAverage
accessibilty: public
arguments: none
what it does: returns average of the three numbers

3.
name: getSum
accessibilty: public
arguments: none
what it does: returns sum of the three numbers

4.
name: getNumberOne
accessibilty: public
arguments: none
what it does: returns the first number entered by the user

5.
name: getNumberTwo
accessibilty: public
arguments: none
what it does: returns the second number entered by the user

6.
name: getNumberThree
accessibilty: public
arguments: none
what it does: returns the third number entered by the user

Here is an example of how the class MathOnThreeNumbers works. The following code produces the output displayed after the code.

MathOnThreeNumbers mm = new MathOnThreeNumbers();
System.out.println("first: " + mm.getNumberOne());
System.out.println("second: " + mm.getNumberTwo());
System.out.println("third: " + mm.getNumberThree());
mm.inputThreeNumbers();

[Code] .....

View Replies View Related

Read Unspecified Numbers Of Scores And Output Average

Sep 5, 2014

Write a program that will read unspecified numbers of scores . The program will output the average of these scores and the scores that are below and above the average.

Example..
1
2
3
4
5
Average is 3
Below 1
2
Above
4
5

View Replies View Related

Loop That Calculates Maximum / Minimum And Average Of 10 Input Numbers?

Feb 26, 2014

It does not calculate the maximum, minimum or average of the 10 numbers that the user is prompted to input.

My code:

import java.util.Scanner;
public class moretest {
public static void main( String [ ] args ) {
int total = 0;
int number;
int minGrade = 101;

[code]...

View Replies View Related

Pair Of Two Numbers - Return Average / Distance / Maximum And Minimum Value

Sep 27, 2013

I have been having difficulty with the weeks concepts in my online Java class, the program is to be as followed:

For this exercise you will implement a class called Pair, that represents a pair of two numbers.The Pair class should include the following constructor and methods:

CONSTRUCTORS
public Pair(double num1, double num2) -- Creates an object that represents a pair of double values

METHODS

public double getAverage() -- Returns the average value of the two numbers
public double getDistance() -- Returns the absolute vale of the distance between the two numbers
public double getMaximum() -- Returns the maximum value of the two numbers
public double getMinimum() -- Returns the minimum vale of the two numbers

Write a class called PairTest that tests your Pair implementation. The PairTest should prompt the user for the two values, create a Pair object with the values and then print the average, distance, maximum, and minimum of the pair. The input / output should look like the following:

Enter the first number: 5.5
Enter the second number: 3.0

Average: 4.25
Distance: 2.5
Maximum: 5.5
Minimum: 3.0

NOTE: For this exercise, your solution should not use any conditional statements. Instead you should use the methods provided by thejava.util.Math.

So far I have:

import java.lang.Math;
import java.util.Scanner;
public class Main
{
public static void main(String args[]) {
Scanner in = new Scanner(System.in);
{
System.out.println("Please enter a value for the first number");

[Code] ....

View Replies View Related

Program For Calculating Circumference And Area Not Working

Jul 15, 2014

Here is the program I wrote for calculating the circumference of a circle.

//circumference.java
//program that calculates the area and circumference of a circle
import java.util.Scanner; //program uses class scanner
public class circumference{
//main method begins execution of Java application
public static void main(String args[]){

[Code] .....

Even though my code compiles and runs without any errors, the program doesn't calculate the circumference.

View Replies View Related

GPA And Average Program

Mar 25, 2014

I am new on this and I will be working in a gpa and average program. This is my code so far: Every time that I try to add the gpa part it gives me errors or just duplicates whatever I've in average and displays it in gpa

/**
* This program shows a database of students in a school.
* It gathers information as name, classes, grades, and calculates average and gpa average.
*
*/
import javax.swing.JOptionPane;
 
[code]....

View Replies View Related

Program That Has Weighted Average Code

Sep 28, 2014

I am doing a program that has a weighted average calculation and everything compiles and runs. It is just that my weighted average seems to be calculating incorrectly.This is the type of output I should see:

Homework:
Number of assignments? 3
Assignment 1 score and max? 14 15
Assignment 2 score and max? 16 20
Assignment 3 score and max? 19 25
Sections attended? 4
Total points = 65 / 80
Weighted score = 40.63
Exam 1:
Score? 81
Curve? 0
Total points = 81 / 100
Weighted score = 16.2
Exam 2:
Score? 95
Curve? 10
Total points = 100 / 100
Weighted score = 30.0
Course grade = 86.83

Below is my code and I think even after getting up this morning and looking at it, I have an error in the calculations, but I can;t pinpoint it.This program is supposed to receive input from user, and calculated the grades of a student with a weighted average
 
import java.util.Scanner;
public class Grades{
private double weightExam;
private double score;
private double curveAmount;
private double scoreTotal;

[code]...

View Replies View Related

Cannot Get Average Program To Calculate Properly

May 9, 2010

I am having a problem with my program. I can't get my program to calculate properly. Everything compiles and run but its just giving me a wrong answer. I am suposse to get 115.50 but instead I am getting .30...

order.java
public class Order
{
double salesTaxRate; //initializing a variable for the sales tax rate.
double subTotal; //initializing a varliable for the sub total.
double shippingCost; //initializing a variable for shipping cost.
double salesTax; //initializing a variable for sales tax.
double totalCost; // initializing a variable for totale cost.

[Code] ....

View Replies View Related

Student Grade Average Program?

Mar 27, 2015

I just have not got the chance to spend much time on it lately I know a bit but I'm not an expert or even intermediate with Java so I'm trying to make a program where the teacher enters the grade of each student and its stored in a variable the only problem is if I use a for loop the variable in which the result will be stired will be overwrite by the last repetition of the loop,I think the idea would be a nested loop but how I would go about using it in this situation,

here is my java code.

import java.util.Scanner;
class maths{
public static void main(String[] args)

[Code].....

View Replies View Related







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