Rounding Average To The Nearest Tenth

Sep 19, 2014

I am trying to get this code to round up the average after the user inputs all 3 grades but i cant seem to get printf to work.

import java.util.Scanner;
import java.text.DecimalFormat;
public class Average {
static Scanner console = new Scanner (System.in);
public static void main(String[] args) {
String studentName;

[Code] ....

View Replies


ADVERTISEMENT

Rounding Integers To Nearest Tens Place

Feb 7, 2015

I need to round my variables to the nearest "tens" place and I'm having trouble doing so. Every time I run the program it comes back with a number ending in .0 even if its something like 11 / 3. How can I fix this?

public static void results(int game, int totalGuess, int best) {
double avg = Math.round((totalGuess / game) * 10.0) / 10.0;

View Replies View Related

Rounding Integer Type In Program

Mar 8, 2014

I have this code line:

String sectionText = String.valueOf((int)percents.getYellowPercent());

And I want the integer value to be displayed, instead of double. This works, but when the program rounds the double into integer, if the number is for example 75,56 (this is %) or 3,5 I would like it to be rounded in 76 (or 3,6 for the other example) since as it is at this moment, when all the calculated integers are summed, the result is not 100%, but 99%.

View Replies View Related

How To Round The Result To Nearest Integer

Jan 11, 2015

My program is attempting to:

1. ask user to input a decimal
2. output 1 - confirms the input
3. output 2 rounds the input value to the nearest integer.

Here is what I have so far:

/*
* 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.
*/
import java.util.Scanner;
public class IT145Exercise13 {
static Scanner console = new Scanner(System.in);
 
[Code] .....

Results with input of 5.25:
run:
Enter a decimal:
5.25
You entered 5.25

The integer value is 5 YES however,

BUILD SUCCESSFUL (total time: 6 second)

However, if the input is 5.95 here are the run results:

run:
Enter a decimal:
5.95
You entered 5.95
The integer value is 5 Here I expect 6
BUILD SUCCESSFUL (total time: 6 second

Not sure how to ask the output of the variable integerOut to be rounded to the nearest integer?

View Replies View Related

Find Date Of Monday Which Comes After Third Friday Of Nearest Month

Sep 10, 2014

Write a program to find the date of the monday which comes after the third friday of the nearest month.

Input : yyyy,mm,dd,Day
Output : yyyy,mm,dd,Monday

suppose the input is 29/1/2014
the output should be 24/2/2014

View Replies View Related

Find Date Of Monday Which Comes After Third Friday Of Nearest Month

Sep 10, 2014

Write a program to find the date of the monday which comes after the third friday of the nearest month.

Input : yyyy,mm,dd,Day
Output : yyyy,mm,dd,Monday

Honestly, I don't know how to start......

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

Compute Average Of The Sum

Dec 30, 2014

I'm having trouble compiling this program. It is supposed to compute the average of the sum:

import java.util.Scanner;
public class ComputeAverage
{
public static void main(String[] args) {
Scanner bucky = new Scanner(System.in);
double fnum;
double snum;

[Code] ......

View Replies View Related

Java Odd And Even Average

Apr 22, 2014

In the class, you will have three instance variables,

1) array to hold the numbers,
2) the odd average, and
3) the even average.

The constructor should accept as input the array from the tester class and assign it to the instance variable. You should then have a method, findAverage, that will read the array and then calculate the average of the even input values and the average of the odd input values. (Hint: You can use % (mod) to determine if a number is even or odd). Your program will need a getOddAverage and a getEvenAverage method.

public class oddEvenAverage {
int [] myArray = new int[10];
public double oddAverage;
public double evenAverage;
public oddEvenAverage(int number){
int myArray = number;

[Code] .....

What am i doing wrong here? I can't get it working!

View Replies View Related

How To Get Average Of Strings Using Array

Apr 21, 2014

I'm trying to calculate the average of grades that a user puts in. Here is my code so far:

public static void main(String[] args) {
Scanner input = new Scanner (System.in); 
System.out.println("Please enter an array of grades seperated bt a comma.");
input.nextLine();
String arrayOfGrades = "100,50,100";
String[] grades = arrayOfGrades.split(",");
 
[Code] .....

I think I'm on the right track, the only big error I'm really getting is the line: sum += grades[i]. It's saying string can not be converted into a double.

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

High / Low / Average Temperature

Nov 19, 2014

I am trying to write a code that asks the user to enter a temperature for each day of the week and then it prints out the high temperature, the low temperature, and the average temperature. This is the code I have so far:

import java.util.*;
import java.text.DecimalFormat;
public class Lab10 {
public static void main(String[] args) {
java.util.Scanner input = new java.util.Scanner(System.in);
int high, low, i, sum;
double avg;
[Code] ....

There are a few issues that I am having.

1. I can't for the life of me figure out how to make it print the low temperature
2. I had it running perfectly until I changed one thing and now I get a compile error saying that the last 5 statements are unreachable. (lines 32-37)

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 Return Method

Dec 7, 2014

For my project, I am trying to return the method average so the program can calculate the average after grades are enter. I'm not sure what I am doing wrong and how I should improve it. My code is below. This is my error message: "Project.java:71: error: '.class' expected".
 
import java.util.Scanner;
public class Project
{
public static void main(String[] args)

[code]....

View Replies View Related

Grade Average Project

Dec 7, 2014

I have make a simple grade average project and can't figure out how to ask the user if they want to enter more grades to average and run the app again.Here's what I have so far.

import java.util.Scanner;
public class Average {
private static Scanner kb;
public static void main(String[] args) {
kb = new Scanner(System.in);
 
[code]...

How many grades do you wish to average?

View Replies View Related

Will Not Average For High Temperature

Apr 21, 2014

This program will not give me the average high temperature for the week and I cannot figure out why! Every time it only spits out "0" whereas the average low temperature works great..

import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class Temps_Grid_Keenan extends JFrame
{
private static final long serialVersionUID = 1L;
private static final int WIDTH = 400;
private static final int HEIGHT = 500;
 
private JTextField high1Field, low1Field, high2Field, low2Field;
private JTextField high3Field, low3Field, high4Field, low4Field;
private JTextField high5Field, low5Field, high6Field, low6Field;
private JTextField high7Field, low7Field, ave_highField, ave_lowField;
 
[code]....

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

Finding Average Of Multidimensional Array

Mar 2, 2015

public class StuTest {
private static Scanner keyboard = new Scanner(System.in);
public static void main(String[] args){
int[][] testScores; // [students][tests]
String[] stuNames;

[Code] ....

The method I am having issues with is the "printStudentReport" method. I am trying to calculate the average of a randomly generated number of students and tests. For my "printTestReport" method, I have to calculate the average of the test by test number.

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

Number Closest To Average Sum For Given Array

Oct 19, 2014

Find the numbers which is closest to the average sum for a given array of N (1<=N<=50) of natural numbers. If there are two numbers who meet the requirement, return the smaller of the two.

For example for the array of: 1,2,3,4,5,6 the average sum is 3.5, so both 3 and 4 are the closest to that, but the program has to return 3, because it's smaller than 4.

The array can also contain duplicates. First we type the number of elements in the array, then in each line we add the numbers. Name of the class: Array

**Note**: Create a data structure array and use it.

And this is what they have given to me, I just need to type the code:

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class Array<E> {
public static int closestNumber( ) {

[Code] .....

View Replies View Related

Overload Methods Returning Average?

Oct 8, 2014

I am stuck on this part of my assignment. When the answer prints out at the end, the calculation of average is incorrect. This is what the assignment wants:

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.

public class Week7Arrays2 {
public static int average(int[] array) {
int sum = 0;
int average = 0;
for (int i = 0; i < array.length; i++) {
sum = sum + array[i];

[code]....

View Replies View Related

Java Arrays - Count Above / Below Average

May 7, 2014

I have to write a program that takes an array of grades and calculate the average and then count the number of grades that are above average and also count the number of grades that are below average. This is what I have so far, it calculate the average and tells me how many are above average... where and how do I get to count how many are below average

public class arrays{
public static void main(String[] args) {
final int grades = 5;
double[] numbers = new double[grades];
double sum = 0;

[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

Grade Input And Final Average

Sep 15, 2014

For this assignment you will be writing a grade book program. The program will work for one student. It will need to take as input the students name. The user will then be asked to input grades into three categories in this order:

1) homework;
2) quizzes;
3) tests.

The grades in a given category will be averaged to one number that is the average of all grades in that category. The final average will be the weighted average of each category, where homework is worth 25% quizzes are worth 25%, and test are worth 50%. Like this:

Homework Grades: 65, 70, 75, 80, 80 Homework Average: 74
Quiz Grades: 75, 80, 85, 80. Quiz Average: 80
Test Grades: 75, 80, 85, 75 Test Average: 78.75
Final Average = 0.25*HomeworkAvg + 0.25*QuizAvg + 0.50*TestAvg = 77.87

But i only have the average and i dont know how to move past that..

Heres my average code :

import java.util.Scanner;
public class Homework3 {
public static void main(String[] args) {
Scanner myScanner = new Scanner(System.in);
int gradeCount = 0;
int grades = 0;
int holder = 0;

[Code] .....

View Replies View Related

Error On Grade Average Calculator

Jul 15, 2014

I've been learning about Swing and I'm working on a Grade Average Calculator, but the problem is after the user types in the the grades, the average is supposed to appear, but for some reason in my code, nothing appears, I can only type in the grades. Here's my code so far :

package gradecalculator;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.text.JTextComponent;
import java.awt.*;
public class Gradecalculator extends JFrame implements FocusListener {
JTextField grade1, grade2, grade3, grade4, grade5, grade6, grade7, grade8;

[Code] .....

View Replies View Related

Max / Min / Average Stats With Error Handling

May 8, 2014

I'm making a program that finds the maximum, minimum, and average values in an integer input ended with a negative number. For example, 4 5 6 -1 is min:4, max:6, and average:5.

It's supposed to handle faulty input in two situations:

1.When an input other than integers is given, the user is given a second chance to give a proper input.

2.When no numbers are given (which is only possible by giving nothing but the negative number end mark), an error message is given because diving by zero integers is impossible.

All the math works fine, but for some reason a proper input in the second chance doesn't. Failing the second chance works, and giving proper input all the way through works. If I fail the first input and then give a proper integer input on the second chance, the program skips over the calculation and gives the divide by zero error. All I could understand from the debugger is that the program is recognizing whatever the first number in that input is, but still keeps the number of numbers as zero (so it's not looping to compare all the numbers in the line either).

import java.util.Scanner;
public class FindNumbers implements FindNumbersInterface
{
double average;
double sum;
int numberOfNumbers;
int total;

[Code] .....

I have a few bits of //old stuff that I've been keeping in case I want to go back.

View Replies View Related







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