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


ADVERTISEMENT

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

Display Lowest And Then Next Lowest Number From Array

Jan 5, 2015

I am not getting the result I am looking for, but I'm sure I'm on the right track. I have an array, names + times of marathon runners, and should end up with a program that displays the slowest runner, and the next-slowest runner.

Currently, I get this:
The lowest time is 273.
The lowest time is 243.

Changing names.length to times.length changes nothing.
for (i = 1;... ) changes nothing.

The displayed number should currently only be 243. Why is it displaying 273 first, and at all?

The code:

class Marathon {
public static void main (String[] arguments) {
String[] names = {"Elena", "Thomas", "Hamilton", "Suzie", "Phil", "Matt", "Alex", "Emma", "John", "James", "Jane", "Emily", "Daniel", "Neda", "Aaron", "Kate"};
  int[] times = {341, 273, 278, 329, 445, 402, 388, 275, 243, 334, 412, 393, 299, 343, 317, 265};
  int min = times [0];
  for (int i = 0; i < times.length; i++) {
if (times[i] < min){
min = times[i];
System.out.println("The lowest time is " + min +".");
}

View Replies View Related

Return Lowest Value From Array

Aug 12, 2014

I am trying to return the lowest value from the array. having trouble trying to capture the return value by placing it into the variable ..

int myLowest = getLowest(yourNumbers); and then printing out myLowest

import java.util.*;
public class numArrays
{
public static void main(String[] args){
int numbers;
int[]yourNumbers;

[code]....

View Replies View Related

Finding Lowest Value In Array Using Linear Search?

Apr 5, 2014

I am attempting to find the element that holds the lowest time ( i have used System.currentMillisTime ) in the array using a linear search and to then print the times held by the array in lowest to highest order . While i understand how to do a linear search using user input as the key i am not to sure how to do it by initializing a search key in the program to the lowest number and have little experience in using a search in a program that is not a simply linear search. i have attempted to code this, as seen below, but i know i am definitely wrong and i have tried another of different ways even Array.sort and then a binary search .

static long store_MAX[]; // Now an ‘array’ of ints
static int deptSize; // Holds the length of the buffer
private int shopper_MAX; // Holds the number of items in the buffer

[Code].....

View Replies View Related

Recursion Method With 2d Array To Find A Column With Lowest Sum

Jan 28, 2015

i have to write a method, The method receives a parameter of two-dimensional array of integers. The method returns the number of the column which has the lowest sum of the integers.I'm allowed to use only recursion! no loops allowed!-of course i need to make a private method that will sum a column as a single array and then i have to do another private method that compares the column , but it doesn't really work .

View Replies View Related

Create Array / Store 5 Objects And Calculate Total Price - VAT Rate

May 6, 2014

How can I do the work below in Java

In this main class, create 5 objects of the class Menu, as defined in the table below.

Name amount of calories cooking time price per person number of drinks

Fufu and Groundnut Soup 564.65 2515.572
Red Red 345 12 9.980
Rice and Beef Stew 560.4 1512.651
Ga Kenkey and Fish 780 10 10.15 1
Banku and Tilapia 450.4 35 25.17 2

Exercise d
In your main class create an array of length 5, and store the 5 objects (Exercise c) into the array. You can use any name for your array.

From the array, use a loop to: Print the details of all the objects using the method you defined in Exercise b.

Exercise e
Use another loop to:
-Print only the name and cooking time of all the dishes that take less than 30 minutes to cook. Hint: you may use the getter methods for the name and cooking time attributes, and then, print these values (name, cooking time).

Exercise f
Use another loop to :
-Calculate and print the total price of all the objects (in the array).
-Calculate the total price of all the objects with VAT included for each dish (VAT rate is 17.5%).

Submission
-Create a folder with your index number as its name.
-Copy your Java Project folder into the created folder.
-Print a hard copy of your classes.
-Submit both soft copy and hard copy of your project

View Replies View Related

Checking If Int Is Lowest Out Of 4?

Apr 30, 2014

I'm trying to find the int with the lowest value, and I only know how to set it up like this:

Let's say x1 is the lowest.

int x1, x2, x3, x4;
 
if (x1 < x2 && x1 < x3 && x1 < x4) System.put.println("x1 is the lowest value out of those 4");

Is there a way to shorten this at all? (It's alright if there isn't, just looking for shortcuts)

View Replies View Related

Find The Lowest Number?

Apr 12, 2014

I have to find the average, highest, and lowest numbers in an array. I already have the average and highest, and I thought I could find the lowest number the same way I found the highest, but it's not working. It just keeps coming out to 0. I've tried out different ways, but I want to see if there are better ways than doing MAX_VALUE for the lowest, then looping it through.

import java.util.Scanner; 
public class Test_Scores {
public static void main(String[] args) {
//array,scanner,values

[Code].....

View Replies View Related

How To Return 2 Lowest Scores

Mar 19, 2015

If this method returns the lowest score, how do I return the 2 lowest scores.

For example If I input 1, 2, 3, 4, 5 this code will return 1.

How do i return the two lowest scores, for example if I input 1, 2, 3, 4, 5, I want to return 1, 2

public double getLowestScore() {
smallest = testScores[0];
double sum = 0.0;
double total = 0.0;
double Average = 0.0;

[Code] ....

View Replies View Related

Sorting From Lowest To Highest

Feb 23, 2014

I'm very new to Java and ran into a problem. My results are not in order and I'm not sure what I'm doing wrong.

My results come out like this instead of being in order from lowest to highest: "77 99 44 55 22 88 11 0 66 33"

Here's what I have:

class ArrayIns {
private long[] a; // ref to array a
private int nElems; // number of data items
//--------------------------------------------------------------
public ArrayIns(int max) // constructor
{
a = new long[max]; // create the array
nElems = 0; // no items yet

[Code] .....

View Replies View Related

Printing Highest And Lowest Of Three Numbers Using Java?

Feb 23, 2014

I am working on an assignment but I am not getting any out put and I couldn't fix it?The class HighLow below asks for three integers and prints the highest and lowest of them on screen. Your task is to write the missing methods high and low, which receives the integers user inputs as parameters and return the highest and lowest integers respectively.

import java.util.Scanner;
public class HighLow {
public static void main(String[] args) {
int number1, number 2, number 3, high, low;
Scanner reader = new Scanner(System.in);

[code]......

View Replies View Related

Printing Highest And Lowest Of Three Numbers Using Java

Feb 23, 2014

The class HighLow below asks for three integers and prints the highest and lowest of them on screen. Your task is to write the missing methods high and low, which receives the integers user inputs as parameters and return the highest and lowest integers respectively.

import java.util.Scanner;
public class HighLow {
public static void main(String[] args) {
int number1, number 2, number 3, high, low;
Scanner reader = new Scanner(System.in);

[code]....

View Replies View Related

Unable To Pull Out Lowest Week Number In Program

Apr 29, 2014

This program reads off of a text file that I have attached to my post. It is supposed to:

display the total sales for each week
the average daily sales for each week
the total sales for all of the weeks
the average weekly sales
the week number that had the highest amount of sales
the week number that had the lowest amount of sales

I can get everything but the very last one. In my code you will see that I tried to use a really large number so it would pull out the lowest amount, but it still didn't work: low = 100000000;

 SalesData.txt (173bytes)
Number of downloads: 29
import javax.swing.JOptionPane;
import java.io.*;
import java.text.DecimalFormat;
import java.util.Scanner;

[code]....

View Replies View Related

Display All Student With Their Grade Sorted From Highest To Lowest

Oct 22, 2014

Write a program that promts a professor to input grades for five different courses for 10 students. Prompt the professor to enter only A,B,C,D, or F for grades(A is the highest grade, F fail). use variables for student number(1 through 10) and grade numbers(1 through 5). create a menu for Search. if the user select search it will prompt a letter correspond to grade. display all student with selected grade. if the user just enter nothing, display all student with their grade sorted from highest to lowest.

View Replies View Related

Reading Lowest / Highest / Average Grades And Reporting Them From For Loops?

May 3, 2014

import java.util.*;
import java.text.*;
public class Quiz {
public static void main(String[] args){
Scanner s= new Scanner(System.in);
int quests = 0;
String input ="";

[code]....

I'm not getting any errors anymore.

View Replies View Related

Java Program - Find Next Highest Or Lowest Prime Number

May 2, 2014

Java program takes positive int from user and determine if prime. Next the program finds next highest or next lowest prime number.

import java.io.*;
import java.util.*;
public class pa2take2 {
public static void main (String[]args){
int menus; //menu selection

[Code] ......

View Replies View Related

Write A JAVA Program That Will Input 10 Scores And Output Highest And Lowest Score

Jan 9, 2015

1.Write a JAVA program that will input 10 scores and output the Highest and Lowest score.

2.Write a JAVA program that will input the base and power and display the result: Example: Base is 4 Power is 2 the answer is 16 (Note: Math.pow( ) method is not allowed)

3.Write a JAVA program that will input an integer number, and then will output the sum of all inputted numbers. The program will stop in accepting inputs if the user entered 0.

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

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







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