My homework assignment is: Using a do-while statement, write a Java program that continuously requests a grade to be entered. If the grade is less than 0 or greater than 100, your program should display an appropriate message informing the user that an invalid grade has been entered; a valid grade should be added to a total. When a grade of 999 is entered, the program should exit the repetition loop and compute and display the average of the valid grades entered. Run the program on your computer and verify the program using appropriate test data.
When I run it, I don't get the correct average. I know that i'm supposed to enter 999 to exit the loop and to display the average, but 999 is being added with the loop. I'm not sure how to make it not do that.
//stephanie import java.util.Scanner; public class gradeAverage { public static void main(String[] args)
Four experiments are performed, each consisting of six tests. The number of test results for each experiment is entered by the user. Write a Java program using a nested loop to compute and display the average of the test results for each experiment.
You can run the program by entering the following test results:
Allow the user to specify the number of terms (5 terms are shown) to use in the computation. Each time around the loop only one extra term should be added to the estimate for PI.
Alter your solution from part one so that the user is allowed to specify the precision required between 1 and 8 digits (i.e. the number of digits which are correct; e.g. to 5 digits PI is 3.14159), rather than the number of terms. The condition on the loop should be altered so that it continues until the required precision is obtained. Note that you need only submit this second version of the program (assuming you have it working).
My output for part 1 is :
Enter number of wanted terms for value of PI 100 PI = 3.1666666666666665 Number of Term = 2 PI = 3.1333333333333333 Number of Term = 3 PI = 3.145238095238095 Number of Term = 4 PI = 3.1396825396825396 Number of Term = 5 PI = 3.1427128427128426 Number of Term = 6 PI = 3.1408813408813407 Number of Term = 7 PI = 3.142071817071817 Number of Term = 8 PI = 3.1412548236077646 Number of Term = 9 PI = 3.141839618929402 Number of Term = 10 ................ and so on
I know you have to compare value of current Pi to the previous one but I'm stuck.
This is what I have so far, but I don't know how to continue:
import java.util.Scanner; public class ArithmeticComputation{ public static void main(String[] args) { Scanner stdin = new Scanner(System.in); int num1 = stdin.nextInt();
[Code] ....
I'm looking for a method that allows me to assign char into actual operators, so that I can loop through all the computation.
This is what I need to do: Write a method called scientific that accepts two real numbers as parameters for a base and an exponent and computes the base times 10 to the exponent, as seen in scientific notation. For example, the call of scientific(6.23, 5.0) would return 623000.0 and the call of scientific(1.9, -2.0) would return 0.019.
This is the method I have written:
public double scientific(double num1, double num2); { double base = num1; double exp = num2; double scientific = base * Math.pow(10, exp); System.out.println(scientific); return scientific; }
These are the following error messages I received when trying to compile the code:
Line 4 missing method body, or declare abstract missing method body, or declare abstract public double scientific(double num1, double num2);
My verify method also always returns false. So I'm given three classes to begin with. Calculator, Expression, and InfixExpression and they are listed below.
The goal is to create a class called PostfixExpression that extends Expression and can read and calculate postfix expressions.
My evaluate() method works for most calculations but when it needs to return a negative value it just returns the positive equivalent.
Also, my verify method always returns false and I can't pinpoint why.
Here's my current code. Some things are commented out for debugging purposes.
import java.util.Scanner; /** * Simple calculator that reads infix expressions and evaluates them. */ public class Calculator { public static void main(String[] args) { Scanner input = new Scanner(System.in);
<import javax.swing.JOptionPane; public class TempCalc {
public static void main(String[] args) {
//Confirming which conversion to compute. String FarOrCel = (JOptionPane.showInputDialog("Would you like to calculate a Farenheit value or a Celsius value? (Enter Farenheit or Celsius)");
[Code] ....
So I've been trying to come up with a Farenheit to Celsius converter and back. However, whenever I run the program in JCreator it never recognizes the string "Farenheit". Even if I put that exact thing (I copy/pasted from the if (FarOrCel == "Farenheit")) it keeps asking me for a Celsius value.
[quote name='INNOCENTREAPER##!' date='28 September 2014 - 07:40 PM' timestamp='1411958437' post='2057072']
<import javax.swing.JOptionPane; public class TempCalc { public static void main(String[] args) {
//Confirming which conversion to compute. String FarOrCel = JOptionPane.showInputDialog("Would you like to calculate a Farenheit value or a Celsius value? (Enter Farenheit or Celsius)";
Basically I'm trying to compute the standard deviation for a set of numbers and I'm using previously know data to compute this. The data I'm working with is here (note all of this is fake as its for an assignment):
Next this is the code that I know is producing the error:
/** * Pass in original data from files, and pass in computed grades as arraylist. this returns all of the standard deviations to be printed */ public static ArrayList calcStandDev(String data1[], ArrayList<Double> grades, ArrayList<Integer> averages) { double standDev = 0; int j = 0; //gets rid of first element in string array, makes processing MUCH easier String[] data = Arrays.copyOfRange(data1, 1, data1.length);
[Code] ....
Look for the line with all the ***'s, it is producing the "java.lang.ClassCastException: java.lang.Double cannot be cast to java.lang.Integer".
The reason I dont undersand why its producing this error is because temp.get(i) should be a integer - averages.get(i) (is type double), I do believe automatic up casting is present here making them both a double then I multiply it by itself producing a double? I dont understand where the casing is occurring. And just incase you want the formula I'm using for standard deviation here it is:
Write a program that computes the cost of painting and installing carpet in a room. Assume that the room has one door, two windows, and one bookshelf. Your program must do the following:a. Prompts the user to enter, in feet, the length, width, and height of a room.
A. Read the dimensions of the room.
b. Prompts the user to enter the width and heights, in feet, of the door, each window, and the bookshelf. Read these quantities.
c. Prompts the user to enter the cost, per square foot, of painting the walls. Read these quantities.
d. Prompts the user to enter of cost, per square foot, of installing carpet. Read these quantities.
e. Output the cost of painting the walls and installing the carpet.
We have triangle made of blocks. The topmost row has 1 block, the next row down has 2 blocks, the next row has 3 blocks, and so on. Compute recursively (no loops or multiplication) the total number of blocks in such a triangle with the given number of rows.
1)A factorial of a number X is equal to X*(X-1)*(X-2)*...*1.For example,3! is equal 3*2*1=6.Create a class called Factorial Algorithm which will compute and print the factorial of an integer number on the screen
2)Write a Java program to accept eight integers and a search element from the user and display whether the element is found or not.(Hint:use bubble sorting and binary search)
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;
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!
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.
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)
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 ______,
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)
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);
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;
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;
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.
(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
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( ) {