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.
Assignment: Given an array of scores sorted in increasing order, return true if the array contains 3 adjacent scores that differ from each other by at most 2, such as with {3, 4, 5} or {3, 5, 5}.
public boolean scoresClump(int[] scores) { for (int i = 0; i < scores.length; i++) { int a = scores[i]; int b = scores[i + 1]; int c = scores[i + 2]; if (Math.abs(b-a) + Math.abs (c-b) <=2) return true; } return false; }
I got it right for some of the input, but not one of them. I tried to use the for loop and if statement on a specific input that I got wrong:
I suspect it has something to do with the for loop, but I don't see the problem with it. It should work, shouldn't it? But anyway, here is the error for {4,5,8} :
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 +"."); }
I want to use a method, which takes for example an int and also returns an integer. For example, if the the given integer is strong return a, if it is notstrong return b. How would you write that in a Code?
I want to use that in a more general way. I want to give a method mlong the value X of the type date and let it return an int. Type date consists of 3 int, one of them is the int month.
mlong should return an int depending on the X.moth. at the moment my code looks like this:
// File1: public class date { public int day; public int month; public int year; }
// File 2: public class monthlength { public int mlong(date X) { int t; t = X.month; if (t == 1 || t == 3 || t == 5 || t == 7 || t == 8 || t == 10 || t == 12) { return 31; } if(t == 4 || t == 6 || t == 9 || t == 11) {return 30;} } }
How do i take input values for TwoDPoint (which are objects) and return it back in numerical values also print them.
When i create an object in main method and pass values to my function of return type TwoDPoint,it gives error:- found int,int need TwoDPoiint,TwoDPoint.
// Here is what i tried to do:
Created class TwoDPoint that contains two fields x, y which are of type int. Defined another class TestTwoDPoint, where a main method is defined.In the main method created two TwoDPoint objects.
Then I modified the class TestTwoDPoint and add another function to it. This function takes two TwoDPoints as input and returns the TwoDPoint that is farthest from the point (0,0).
Then I added another function to TestTwoDPoint. This function takes two TwoDPoints as input and returns a new TwoDPoint whose x value is the sum of x values of the input TwoDPoint's and whose y value is the sum of the y values of the input TwoDPoint's.
class TwoDPoint { int x = 2; int y = 4; } class TestTwoDPoint { public static void main(String args[]) { TwoDPoint obj1 = new TwoDPoint(); System.out.println(obj1.x); System.out.println(obj1.y);
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.
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
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
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);
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
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);
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 .
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;
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.
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 ="";
So for this project I'm going to take in some quiz scores, then eventually get the total number, the range, the mean, and others... Here's the instructions for the two methods I need to create but am completely stuck on:
2. public boolean inputData(Scanner in) 2.1.takes in a Scanner object passed in from main() 2.2. asks the user for a number in the range of 0 through 100. 2.3.It must read a number into an integer variable unless a non-number value is entered, in which case the method will return false. You may use try/catch or an if statement for this. 2.4.If the datum/score seems acceptable, the addGrade method must be called. 2.5.If addGrade returns false, then inputData should throw an IllegalArgumentException or return false Otherwise, inputData should return true. See section 11.4 for exceptions.
3. public boolean addGrade 3.1.takes in an integer grade. If grade is not in the range of 0 through 100 the method should return false. Otherwise, it should appropriately change the values of numberOfQuizzes, highValue, lowValue, 3.2.totalQuizScore , sumOfSquares (used in variance calculation), and add one to the count of the proper variable for A's, B's, C's, D's or F's. The method should then call calculate and return true
Now I have done very little with booleans in class at all, so this is all very confusing for me. I've tried to do a lot of research on my own and so far I came up with the following for the two methods above:
public boolean inputData() { int score = 0; System.out.println("Please enter values, Q to quit:"); Scanner in = new Scanner(System.in); while (in.hasNextInt())
[Code] ....
Honestly I'm not really sure what I'm doing wrong at all, and I have done a lot of research but can't really find anything too similar to what the instructions want so I'm not sure what's right/wrong.
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;
Design and write a Java program that will generate a set of test scores between 0-100, inconclusive. The exact umber of scores is determined either randomly or by the user input. There should be a minimum of 5 test scores. The program calculates the average of all test score in this data set. Then it asks the user how many scores are to be dropped and drops that number of low scores. The average is recalculated.
Output of this program:
The original test scores printed in rows of 10 scores The average before low scores are dropped The number of low scores to be dropped The list of low scores dropped The new average
I'm writing a program that is about rolling "dice" and getting the scores to add up to 100. There are two players in the game and each must take turns rolling dice choosing whether or not to keep rolling dice and accumulating more points during their turn while risking their points being lost by rolling a 1 or to add their turn points to their total points. The question I have is how would I exit the do while loop if the player chooses to add their turn score, thus adding their score and ending their turn?
Here is the coding so far.
Java Code:
import java.util.Scanner; import java.util.Random; public class Pig { public static void main(String[] args) { int die; int userTotalScore; int userTurnScore; int compTotalScore; int compTurnScore;