Print Inputted Data - Name / Score And Average Using Array
Aug 22, 2014
Conditions : Need to print all the inputted data(name,score) and the average.
import java.util.Scanner;
public class Case2 {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
int[] score = new int[5];
String[] name = new String[5];
int ave = 0;
[Code] .....
View Replies
ADVERTISEMENT
Sep 27, 2014
I've been working on this same assignment using netbeans. I've completed the exercise and when I run it, it works. However, netbeans still had errors listed in the left hand numerical column and it asks me if I still want to run the program with errors when I hit run?
package TestScores;
import java.util.Scanner;
// Name: Joe
// Date: ........
// Desc: Test Score Averages
[code].....
I found this thread while doing a google search trying to find out the error in my code.
View Replies
View Related
Jun 16, 2014
I'm working on a homework assignment and I keep getting a compiler message this is the message
GradesAverage.java:44: error: variable totalgrade might not have been initialized
System.out.println("Over all you have " + totalgrade);
^
1 error
The homework is this Write a program that has variables to hold three test scores. The program should ask the user to enter three test scores and then assign the values entered to the variables. The program should display the average of the test stores and the letter grade that is assigned for the test score average. Use the grading scheme in the following table:
Test Score Average Letter Grade
90-100 A
80-89 B
70-79 C
60-69 D
Below 60 F
This is my code
import javax.swing.JOptionPane; // Needed for JOptionPane class
import java.util.Scanner; // Needed for the scanner class
public class GradesAverage
{
public static void main (String[] args)
[code]....
View Replies
View Related
Jul 26, 2014
import java.util.Scanner;
public class CountPosAndNegNumbers {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
[code]...
find the average of the integers that are input but can't manage to solve the problem.
View Replies
View Related
May 25, 2014
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class DisplayFinal_Panel extends JPanel {
private JLabel label1, label2, label3;
private JTextField box;
[code]....
I only want Listener 1 to work right now. Also, user input is in TextField.
View Replies
View Related
Oct 21, 2014
I'm having some trouble with my project. I have filled the getters using an array and what I now need to do is get the user to type in a day and print the corresponding getters to the lines the day is on in my text file.
{
File file = new File("DailyJobs.txt");
Job newJob = new Job();
try (Scanner scanner = new Scanner(file);)/>
{
while(scanner.hasNextLine()) {
String line = scanner.nextLine();
[Code] ....
This is what I've attempted in terms of entering the day. It recognises the number of lines that has the inputted day but prints out only the very last job ID in the text file.
90301,14304,ITGURU,11/11/2014,Tuesday,735.75,1204,1205
90302,14314,ROK5TR,12/11/2014,Wednesday,335.75,1205
90303,14318,HRTBRK,13/11/2014,Thursday,125.5,1200
90304,14310,EVOH8R,14/11/2014,Friday,1207.95,1211
90305,14300,G4MER,11/11/2014,Tuesday,500,1204,1202
[Code] ....
This is the text file, the first number on each line is the Job ID and always prints the last line regardless of the day I enter.
View Replies
View Related
May 30, 2014
I am using Eclipse programming for android. I have a game working fine but looking to add a little flare to it. Currently more scoring system just displays the current sore so if your score is 3,000 and you score 300 more it just changes to 3,300.
My question is how can I get the score to count from 3,000 to 3,300 really fast giving it the arcade feel of your score counting up? I tried timers with delays but it gets slowed down and buggy.
View Replies
View Related
Mar 13, 2015
I want to write a program that accepts user input and then prints its average in a serial way.
Suppose i enter 5. I should get result 5 first time then i input 10 then it should return the average of (5 and 10) and then i enter say 20 it should return average of (5,10 and 20) and so on.
View Replies
View Related
Mar 8, 2014
Given an array of scores, return true if each score is equal or greater than the one before. The array will be length 2 or more.
scoresIncreasing({1, 3, 4}) → true
scoresIncreasing({1, 3, 2}) → false
scoresIncreasing({1, 1, 4}) → true
Java Code:
public boolean scoresIncreasing(int[] scores)
{
for (int i = 0; i< scores.length-1; i++) {
if (scores[i] < scores[i+1] || scores[i] == scores [i+1]) {
return true;
} else {
return false;
}
}
return false;
}
Unsure what the problem is, it will always return True for some reason...
View Replies
View Related
Jul 14, 2014
New to programming. Am supposed to create a program that reads a text file (of integers) and computes a series of computations on these integers. I don't have the code for the integers in my code yet, (i know how to do those), but am struggling getting the array to simply print in the print writer. I have the user select a text file, read the file with a scanner, and then save the computations done from my code into another file. specifically, the problem is as follows: Write a program that uses a file chooser dialog to select a file containing some integers. The file contains an integer N followed by N integers. The program then uses a file chooser dialog to let the user specify the name and location of an output file to write results to.The data written to the output file will be as follows
(1) The original list of N numbers from the input file,
(2) The original list of N numbers printed in reverse order of how they appear
in the input file.
(3) The sum and average of these numbers,
(4) The minimum of all the numbers,
(5) The maximum of all the numbers.
[import java.io.File;
import java.io.IOException;
import java.io.PrintWriter;
import java.io.Writer;
[Code]....
View Replies
View Related
Sep 25, 2014
In my account driver I am trying to get the user inputted account number to get the account by account number. In my code
System.out.println("Which Account number: "); int account = scan.nextInt();
ac.get(account-1);
This works if my accounts are numbered incrementally starting with one, I want it to match the inputted account number
System.out.println("Account number: "); int num = scan.nextInt();
I am thinking a for loop is probably needed. Here is my code:
public class AccountDriver {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
ArrayList<Account> ac = new ArrayList<>();
boolean more=true;
boolean again=false;
[code]....
View Replies
View Related
Jan 7, 2015
I am creating a program called "Mad Math Machine". This program is to generate random arithmetic questions, with integers ranging from -12 to 12, for the user to answer. The user has three lives. Once they get more than three questions wrong, they run out of lives, and their "score" (the number of questions they answered correctly) is taken.
I have the large chunk of the program (the arithmetic questions and answers) completed. The only part I am stuck on is the scoring system. I believe that arrays would be useful for this task, but I have little idea of where to start. Here is what the scoring list should be able to do:
- It should print out the top ten recent players and their scores.
- A separate list should show the top-two highest scores of all time.
*I didn't think it was relevant, but I can include the program code. Up until this point, I have created methods to keep track of the score, but I have simply left them commented out so I could build the rest of the program.*
View Replies
View Related
May 2, 2014
So I'm trying to write a program that will take in 5 numbers, store them in an array and then print out the array and the average of the array. Problem is that every time I run my program I get a "ArrayIndexOutOfBoundsException: 5" error and I don't know who to fix it.
public class ConstructorHomework {
final static int size = 5;
static double[] myArray = new double[size];
public static double average;
public void printArray(){
[code]...
View Replies
View Related
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
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
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
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
May 13, 2014
public class Apples{
public static void main (String args[]){
int array[]={21,16,86,21,3};
int sum=0;
int average;
[Code] .....
Eclipse: Exception in thread "main" java.lang.Error: Unresolved compilation problem:
The local variable average may not have been initialized
at Apples.main(Apples.java:11)
View Replies
View Related
Apr 8, 2014
How can I find out the simple moving average by just using the numbers stored in an array?
View Replies
View Related
Apr 19, 2015
Trying to convert 2D array to String using toString() to be able to print the array but when I try to use it I just get the memory location
public class Forest
{
private int h;
private int w;
private double p = 0.7;
private int[][] f;
Forest(int w, int h)
[code]....
View Replies
View Related
Feb 13, 2014
I have double checked this code over and over and I just can't find the problem.
What I'm trying to do is take a file and input it into an 2D array.
Ultimately, I should convert the array of integers to an array of characters, then print it out. The file contains a set of ASCII values.
After printing it out, I should then create methods to manipulate the image produced.
Using 2D arrays is a requirement for this exercise.
I think that somehow I'm overcomplicating this and the solution is a lot more simple than I think, but I can't think of what to change.
The error I am getting is:
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 40
at main.main(main.java:17)
Java Code:
import java.util.*;
import java.io.*;
public class main {
public static void main(String[] args)
throws FileNotFoundException {
String[][] data = new String[22][40];
[Code] .....
View Replies
View Related
May 7, 2014
I cannot get the data file to print out correctly when I go to the display case. It only prints one name three times.
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.lang.*;
import java.util.Scanner;
import java.io.*;
import java.text.*;
import java.math.*;
import java.util.StringTokenizer;
[Code] ....
Output when I choose Case 1:
Minia
Minia Jane
Minia Jane
View Replies
View Related
Feb 20, 2014
I just tried to fill an array with some numbers, calculated by a other function.I just tried to print this array as array, but it doesnt work. Maybe its just about the main method.
public static void main(String[] args) {
ggT(5);
}
public static int ggT(int a, int b) {
while(a!=b){
if(a>b) {
a=a-b;
} else {
b=b-a;
}
}
return a;
[code]....
View Replies
View Related
Jan 1, 2015
AddItemToFront(Item p) : This method will create a new Node with the Item object as its data value and then add the newly created node to the front of the linked list.
DisplayItems(): This method will traverse the linked list from first node to last node and print data value ( i.e., id, name, type and price of the Item object) of each node.
RemoveItemAtPosition(int n): This method will remove the node at position n in the linked list. Assume that the first node of the linked list has a position number of 1 and the second node has a position number of 2 and so on.
This is my Code
AddItemToFront
public void AddItemtoFront(Item p)
{
Node newNode = new Node(p);
newNode.setLink(head);
head = newNode;
[Code] ....
I don't know what am I suppose to do inside the remove method
View Replies
View Related
Apr 23, 2015
I am trying out solving the question but i am stuck.The problem is to write a method that print data of single linked list backward using stack.The question is as follow
public class Stack{
public boolean isEmpty(){};
public void push(int n){};
public int peek(){};
public int pop(){};
}
public class node{
int data;
node next;
}
public class list{
node first;
}
View Replies
View Related
Sep 22, 2014
Designed to store a first name (string), last name (string), and zip (int). Assume each line will contain two strings followed by integer each separated by tab. Then print.
I have my two class files (one for the individual and one for the array) and then my driver below. I think my only problem is my driver. I think I'm reading the data file wrong but not sure how exactly.
test in .txt file:
JohnSmith12345
JohnDoe12346
SueSmith09877
VeronicaVarguez67890
MuhammadMaliki54321
public class Person
{
private String firstName;
private String lastName;
private int zipCode;
public Person(String fName, String lName, int zCode)
[Code] ....
View Replies
View Related