Since we haven't covered arrays and lists yet, he said to stick to loops and if statements.
I can't seem to figure out how to make it display the names of the two highest scores from the text file. Also I can't figure out how to make it display two scores that are identical. Here is what I've done so far:
package lab06;
import java.util.*;
import java.io.*;
public class Lab06 {
public static void main(String[] args) throws Exception {
Scanner lab06txt = new Scanner(new File("Lab06.txt"));
Scanner duplicateScanner = new Scanner(new File("Lab06.txt"));
int totalstudents = 0;
int grade = 0;
int grade2 = 0;
int record = 0;
int Highest = 0;
int Highest2 = 0;
int ACounter = 0;
int BCounter = 0;
int CCounter = 0;
int DCounter = 0;
int FCounter = 0;
double average = 0;
String lastName = "";
String lastNameHigh = "";
String lastNameHigh2 = "";
String firstName = "";
String firstNameHigh = "";
String firstNameHigh2 = "";
while (lab06txt.hasNext()){
record ++;
totalstudents++;
lastName = lab06txt.next();
firstName = lab06txt.next();
grade = lab06txt.nextInt();
{
average += grade;
if (grade >= Highest){
Highest = grade;
firstNameHigh = firstName;
lastNameHigh = lastName;
}
}
{
if ((grade >= 90) && (grade <= 100))
{
ACounter++;
}
if ((grade >= 80) && (grade <= 89))
{
BCounter++;
}
if ((grade >= 70) && (grade <= 79))
{
CCounter++;
}
if ((grade >= 60) && (grade <= 69))
{
DCounter++;
}
if ((grade < 60))
{
FCounter++;
}
if ((grade < 0) || (grade > 100))
{
System.out.print("Score is out of bounds in record " + record + ": " + lastName + " "+ firstName + " " + grade + ".\nProgram ending\n");
return;
}
}
}
while(lab06txt.hasNext())
{
lastName = lab06txt.next();
firstName = lab06txt.next();
grade2 = lab06txt.nextInt();
if(grade2 > Highest2 && grade2 < Highest){
Highest2 = grade2;
firstNameHigh2 = firstName;
lastNameHigh2 = lastName;
}
}
System.out.println("Total students in class: " +totalstudents);
System.out.println("Class average: " + average/totalstudents);
System.out.println("Grade Counters: ");
System.out.println("A's B's C's D's F's");
System.out.printf(ACounter + "%7d %7d %8d %7d\n", BCounter,CCounter,DCounter,FCounter);
System.out.println("");
System.out.println("Top Two Students: \n");
System.out.printf(lastNameHigh + " " + firstNameHigh + "%15d \n", Highest);
System.out.printf(lastNameHigh2 + " " + firstNameHigh2 + "%15d\n", Highest2);
}
}
The two parts of your code where you have:
firstName = firstNameHigh;
lastName = lastNameHigh;
should be:
firstNameHigh = firstName;
lastNameHigh = lastName;
Related
Can someone please tell me why my code is not providing the correct output? Here aare the instructions "
I need to write a program that reads student scores, gets the best
score, and then assigns grades based on the following scheme:
1) Grade is A if score is >= best - 10
2) Grade is B if score is >= best - 20;
3) Grade is C if score is >= best - 30;
4) Grade is D if score is >= best - 40;
5) Grade is F otherwise.
The program prompts the user to enter the total number of students, then prompts the user to enter all of the scores, and concludes by displaying the grades. My problem comes from pulling the grades from an array, this is what I have so far:
// Here is my code. Thank You
import java.util.Scanner; // imports the scanner function
public class NBpractice { //class is formed
public static void main(String []args) { // main method
// user input is asked for the number of students
Scanner input = new Scanner(System.in);
System.out.print("Enter the number of students: ");
int studentNum = input.nextInt();
//user input is asked for students scores
Scanner input2 = new Scanner(System.in);
System.out.print("Enter " + studentNum + " scores: ");
int scores = input2.nextInt();
int best = 80;
char letterGrade;
int scoresArray[] = new int[studentNum]; // array is created and holds the # of place values as students
for (int i = 0; i < scoresArray.length; i++) { // for loop created
scoresArray[i] = input2.nextInt(); //array values are assigned to user's input
best = scoresArray[0];
if (best < scoresArray[i]) {
best = scoresArray[i];
}
//-----------------------------------------------------------------------------
if (scores >= (best - 10)) {
letterGrade = 'A';
}
else if (scores >= (best - 20)) {
letterGrade = 'B';
}
else if (scores
>= (best - 30)) {
letterGrade = 'C';
}
else if (scores >= (best - 30)) {
letterGrade = 'D';
}
else {
letterGrade = 'F';
}
System.out.println("Student " + i + " Score is " + scoresArray[i] + " and grade is: " + letterGrade );
}
//------------------------------------------------------------
}
}
Some pointers...
This: System.out.print("Enter " + studentNum + " scores: "); and int scores = input2.nextInt(); need to go in the for loop body.
Use the for loop to populate the array.
Once that the for loop is executed, find the best (highest) score in the array.
Use another for loop to sort out the grades.
As is, your program will only ask for the grades and pretty much assumes that the best grade is 80, which might not always be the case.
You'll need two separate for loops. One to read the grades, and get the best, and the second for loop to normalize the grades.
int[] scores = new int[amount];
int best = -1;
for(int i = 0; i < amount; i++)
{
scores[i] = in.nextInt();
if(scores[i] > best)
best = scores[i];
}
System.out.println(Arrays.toString(scores));
// Now that we have the best, we can normalize
// the rest of the scores based on the best
// and assign the corresponding letter grade.
String[] grades = new String[amount];
for(int i = 0; i < amount; i++)
{
int score = scores[i] * 100 / best;
if(score >= 90)
grades[i] = "A";
else if(score >= 80)
grades[i] = "B";
else if(score >= 70)
grades[i] = "C";
else if(score >= 60)
grades[i] = "D";
else
grades[i] = "F";
scores[i] = score;
}
System.out.println(Arrays.toString(scores));
System.out.println(Arrays.toString(grades));
Test input 80 60 75 83 67 outputs:
[80, 60, 75, 83, 67]
[96, 72, 90, 100, 80]
[A, C, A, A, B]
I would recommend using a Student class and not work with parallel lists or arrays. A Student class can for example look like this:
class Student {
int score;
String grade; // could also be an Enum
public int getScore() {
return this.score;
}
public void setScore(int score) {
this.score = score;
}
public String getGrade() {
return this.grade;
}
public void setGrade(String grade) {
this.grade = grade;
}
#Override
public String toString() {
return "Student{" + "score=" + score + ", grade='" + grade + '\'' + '}';
}
}
You can then make instance of the Students and add them to an ArrayList in you public static void main.
I think you have to use two loops because you cannot know beforehand what the best grade will be. In your main you can make enter the students add them to a List and compare their grades;
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
System.out.print("Enter the number of students: ");
int highScore = 0;
int numOfStudent = input.nextInt();
List<Student> studentList = new ArrayList<>();
for (int i = 1; i <= numOfStudent; i++) { // you might want to add Exception handling here, by surrounding it with a try / catch or do more checks than only i <= numOfStudent
System.out.printf("please fill in the score of student no %d \n", i);
int score = input.nextInt();
Student student = new Student();
student.setScore(score);
if (score > highScore) {
highScore = score;
}
studentList.add(student);
}
System.out.println("these are the scores and grades of the Students");
for (Student s : studentList) {
if (s.getScore() >= highScore - 10) {
s.setGrade("A");
}
else if (s.getScore() >= highScore - 20) {
s.setGrade("B");
}
else if (s.getScore() >= highScore - 30) {
s.setGrade("C");
}
else if (s.getScore() >= highScore - 40) {
s.setGrade("D");
}
else {
s.setGrade("F");
}
System.out.println(s);
}
}
package Chapter7;
import java.util.Scanner;
public class Exercise7_1 {
public static void main(String[] args) {
// Assign grades
Scanner input = new Scanner(System.in);
int numStudents;
int[] scores;
int best;
System.out.println("Enter the number of students: ");
numStudents = input.nextInt();
scores = new int[numStudents];
System.out.println("Enter " + numStudents + " scores: ");
for (int i = 0; i < numStudents; i++) {
scores[i] = input.nextInt();
}
displayGrades(findBestScore(scores), scores);
}
public static int findBestScore(int[] scores) {
int best = scores[0];
for (int i = 1; i < scores.length-1; i++) {
if (scores[i] > best)
best = scores[i];
}
return best;
}
public static void displayGrades(int best, int[] scores ) {
char grade = ' ';
for (int i = 0; i < scores.length; i++) {
if (scores[i] >= best-10)
grade = 'A';
else if (best - 10 > scores[i] && scores[i] >= best - 20)
grade = 'B';
else if (best - 20 > scores[i] && scores[i] >= best -30)
grade = 'C';
else if (best - 30 > scores[i] && scores[i] >= best -40)
grade = 'D';
else if (best - 40 > scores[i])
grade = 'F';
System.out.println("Student " + i + " score is " + scores[i] + " and grade is " + grade);
}
}
}
This program is supposed to find the maximum, minimum, and average of grades. User inputs int inputGrade and the program displays letter it is. It's supposed to do this how however many students are needed. I'm having trouble writing the method where it finds the max and min. (yes I've talked to my teacher if anyone's wondering...) I pasted the methods below (they don't work). Just like IN GENERAL, does anyone know how to find the maximum and minimum of a set of entered numbers? (not using arrays, lists, or any unusual imports other than scanner) ** note I've updated this a lot...
import java.util.Scanner;
public class GetLetterGrade
{
static int inputGrade; // input grade
public static void main(String [] args)
{
Scanner reader = new Scanner(System.in);
int classAverage;
int classMin; // class's minimum grade
int classMax; // class's maximum grade
while (inputGrade != -1) // while user is entering grades
{
System.out.println("Welcome to the grade calculator. \nPlease enter a
numeric grade. After the last student in the class, enter a grade of
-1.");
inputGrade = reader.nextInt();
letterGrade(inputGrade); // calls letter grade method
findMaxAndMin();
result();
}
}
// find letter grade
public static String letterGrade(int numGrade)
{
String gradeMessage = "";
{
if (numGrade >= 96 && numGrade <= 100) // if numeric grade is 96-100 then
it's A+
{
gradeMessage = "That's an A+.";
result();
// DOES THIS FOR GRADES A+ TO F, NOT SHOWN, too much to paste!
}
}
}
return gradeMessage;
}
public static int findCharGrade(int numGrade)
{
char letter;
if (numGrade >= 90 && numGrade <= 100) // A
{
letter = 'A';
}
else if (numGrade >= 80 && numGrade < 90) // B
{
letter = 'B';
}
else if (numGrade >= 70 && numGrade < 80) // C
{
letter = 'C';
}
else if (numGrade >= 60 && numGrade < 70) // D
{
letter = 'D';
}
else if (numGrade < 60) // F
{
letter = 'F';
}
}
// finds maximum and minimum grades
public static int findMaxAndMin(int inputGrade)
{
int max = Math.max(inputGrade, max);
int min = Math.min(inputGrade, min);
if (inputGrade < max)
{
inputGrade = max;
findCharGrade(inputGrade);
}
else if (inputGrade > min)
{
inputGrade = min;
findCharGrade(inputGrade);
}
}
public static void calcAverage(int sumOfGrades, int numOfStudents)
{
// something goes here
}
// finds results
public static void result()
{
int min = findMaxAndMin(inputGrade);
int max = findMaxAndMin(inputGrade);
System.out.println("Please enter a numeric grade");
int inputGrade = reader.nextInt();
letterGrade(inputGrade);
if (inputGrade == -1)
{
System.out.println("You entered " + numOfStudents + " students. Class
Average: " + average + " Class Minimum: " + min + " Class maximum: " + max
+ " \nThanks for using the class grade calculator!");
}
}
here is a more simplistic way of doing it not using Lists or arrays
double sum = 0; // use double so that you do not do integer arithmetic
int count = 0;
int min = Integer.MAX_VALUE; // set to very high value
int max = Integer.MIN_VALUE; // set to bery low value
Scanner scan1 = new Scanner(System.in);
System.out.println("enter numbers (-1 to quit");
while (scan1.hasNextInt()) {
int i = scan1.nextInt(); // get the number (assuming only int value)
if (i == -1) break;
min = Math.min(i, min);
max = Math.max(i, max);
sum += i;
count++;
}
if (count > 0) {
System.out.println("min " + min);
System.out.println("max " + max);
System.out.println("avg " + sum / count);
}
disclaimer
This code will not handle wrong type of input e.g. Strings
edit
If you want the average to be calculated in a separate method you can have a method like
double calcAvg (double sum, int count) {
return sum / count;
}
this can then be called as
if (count > 0) {
System.out.println("min " + min);
System.out.println("max " + max);
System.out.println("avg " + calcAvg (sum, count));
}
You can (and should) divide your problem into the smaller methods.
I'll drop the code, and you read and study it.
I admit I haven't pay to much attention of this simple quest, but still...
Here you are:
import java.util.List;
public class Answer {
public static void main(String[] args) {
//test with some grades (integers)
Answer answer = new Answer();
List<Integer> someGrades = List.of(12, 66, 34, 96, 3, 77, 2);
System.out.println("max = " + answer.findMaxGrade(someGrades));
System.out.println("min = " + answer.findMinGrade(someGrades));
System.out.println("avg = " + answer.findAverageGrade(someGrades));
}
private int findMaxGrade(List<Integer> grades) {
int max = Integer.MIN_VALUE;
for (int grade : grades) {
if (grade > max) max = grade;
}
return max;
}
private int findMinGrade(List<Integer> grades) {
int min = Integer.MAX_VALUE;
for (int grade : grades) {
if (grade < min) min = grade;
}
return min;
}
private double findAverageGrade(List<Integer> grades) {
double average = 0;
for (int grade : grades) {
average += grade;
}
return average / grades.size();
}
}
package example;
import java.util.Scanner;
class Example {
public static void main(String[] args) {
Scanner r = new Scanner(System.in);
int m = 1, total = 0, max = 0, min = 100;
double avg = 0;
while (m <= 5) {
System.out.print("Input marks " + m + " = ");
int inp = r.nextInt();
total += inp;
m++;
min=min<inp?min:inp;
max=max<inp?inp:max;
}
avg = (double)(total) / 5;
System.out.println("Total : " + total);
System.out.println("Max : " + max);
System.out.println("Min : " + min);
System.out.println("Average : " + avg);
}
}
import java.util.Scanner;
public class BA4 {
public static void main(String[] args) {
Scanner keyboard = new Scanner(System.in);
System.out.println("Hello Drews, how many total grades do you want to process?");
int numberOfGrades = keyboard.nextInt();
int[] storeGrades = new int[numberOfGrades];
for (int i = 0; i < numberOfGrades; i++) {
System.out.println("Please enter grade " + (i + 1) + ": ");
storeGrades[i] = keyboard.nextInt();
}
System.out.println("Total score is: " + (getTotalScore(storeGrades)));
System.out.println("Lowest score is: " + (getLowestScore(storeGrades)));
System.out.println("Highest score is: " + (getHighestScore(storeGrades)));
System.out.println("Average score is: " + (averageScore(String.format("%.2f", storeGrades))));
}
public static int getTotalScore(int[] storeGrades) {
int sum = 0;
for (int i = 0; i < storeGrades.length; i++) {
sum += storeGrades[i];
}
return sum;
}
public static int getLowestScore(int[] storeGrades) {
int getLowestScore = 0;
for (int i = 0; i > storeGrades.length; i++) {
getLowestScore = storeGrades[i];
}
return getLowestScore;
}
public static int getHighestScore(int[] storeGrades) {
int getHighestScore = 0;
for (int i = 0; i < storeGrades.length; i++) {
getHighestScore = storeGrades[i];
}
return getHighestScore;
}
public static double averageScore(double[] storeGrades) {
double averageScore = 0;
for (int i = 0; i < storeGrades.length; i++) {
averageScore = (double) storeGrades[i];
}
return averageScore;
}
public static int printGrade(int[] storeGrades) {
int printGrade;
if (printGrade > 89) {
String gradeSoFar = "A";
System.out.println("Your grade so far is an " + gradeSoFar);
}
else if ((printGrade > 79) && (printGrade < 90)) {
String gradeSoFar = "B";
System.out.println("Your grade so far is a " + gradeSoFar);
}
else if ((printGrade > 69) && (printGrade < 80)) {
String gradeSoFar = "C";
System.out.println("Your grade so far is a " + gradeSoFar);
}
else if ((printGrade > 59) && (printGrade < 70)) {
String gradeSoFar = "D";
System.out.println("Your grade so far is a " + gradeSoFar);
}
else if ((printGrade > 0) && (printGrade < 60)) {
String gradeSoFar = "F";
System.out.println("Your grade so far is an " + gradeSoFar);
}
return printGrade;
}
}
I am trying to figure out where I am going wrong. I have a couple of errors which leads me to believe I really just don't understand methods as well as I thought I did.
The goal is to create 5 methods displaying to the user the total, lowest, highest and average scores, and then to print the letter grade. Thank you for your assistance to this noobie java coder! :)
You are passing in a String when you should be passing in a Double[] into averageScore function in this line:
System.out.println("Average score is: " + (averageScore(String.format("%.2f", storeGrades))));
and you did not initialize the printGrade variable inside the printGrade function, you need to give it an initial value if you are going to use it in a comparison.
That's all the errors that
I am having trouble calling a getter from an imported class.
I have created a working class (Students) and an action class (ProgressReport). The main class reads a text file and writes the data to an array. The data is then manipulated in the working class. Last, ProgressReport.generateReport will create a report giving the students name, their grade average and the letter grade associate with that average.
I am having trouble using the Students getters from the Progress Report class. Eclipse is saying the method is undefined. I am not exactly sure what I have done wrong or how to go about fixing it. Any help would be very much appreciated.NOTE: I added some println to make sure parts of the code were being executed. Thank you all in advance.
Code to follow:
Progress Report
package Lab1A;
import java.util.*;
import Lab1A.Students;
import java.io.*;
public class ProgressReport {
public Students section[][];
public static void main(String[] args) throws IOException
{
Students tmpStudent;
ProgressReport progressReport = new ProgressReport();
progressReport.readInputFile();
progressReport.generateReport();
System.out.println("\nSEARCH TEST");
tmpStudent = null;
tmpStudent = progressReport.sequentialSearch(0, "Cooper");
if (tmpStudent != null)
System.out.println("Found " + tmpStudent.getName() +
"\tAverage = " + tmpStudent.getAverage() +
"\tGrade = " + tmpStudent.getGrade());
else System.out.println("Fail to find the student");
tmpStudent = null;
tmpStudent = progressReport.sequentialSearch(0, "Bronson");
if (tmpStudent != null)
System.out.println("Found " + tmpStudent.getName() +
"\tAverage = " + tmpStudent.getAverage() +
"\tGrade = " + tmpStudent.getGrade());
else System.out.println("Fail to find the student");
tmpStudent = null;
tmpStudent = progressReport.sequentialSearch(1, "Diana");
if (tmpStudent != null)
System.out.println("Found " + tmpStudent.getName() +
"\tAverage = " + tmpStudent.getAverage() +
"\tGrade = " + tmpStudent.getGrade());
else System.out.println("Fail to find the student");
}
public ProgressReport()
{
section = new Students [2][];
}
public void readInputFile() throws FileNotFoundException
{
System.out.println("in readInputFile method");
//Open file
File input = new File("Lab1A.in");
Scanner inputFile = new Scanner(input);
System.out.println("file is open");
//Read file data
int currentStudent = 0;
while (inputFile.hasNext())
{
System.out.println("In while loop");
//Get Student count
int rows = inputFile.nextInt();
//Read student data
section[currentStudent] = new Students[rows];
System.out.println("array initiated");
for(int i = 0; i < rows; i++)
{
System.out.println("In for loop");
//read in a students info
String sName = inputFile.next();
//Read in grades
int grade1 = inputFile.nextInt();
int grade2 = inputFile.nextInt();
int grade3 = inputFile.nextInt();
int grade4 = inputFile.nextInt();
int grade5 = inputFile.nextInt();
//Send to Students Array
section[currentStudent][i] = new Students(sName, grade1, grade2, grade3, grade4, grade5);
}
//Next Student Line
currentStudent++;
}
inputFile.close();
}
public void generateReport()
{
System.out.println("Progress Report");
double average = Students.class.getAverage();
//String section = "Section\n";
}
public Students sequentialSearch(int section, String searchName)
{
return null;
}
}
Students Class
package Lab1A;
import java.lang.reflect.Array;
public class Students {
private String name;
private char grade;
private double average;
private int scores[];
public Students(String sName, int grade1, int grade2, int grade3, int grade4, int grade5)
{
//CONSTRUCTOR load data from ProgressReport
name = sName;
int newScores[] = {grade1, grade2, grade3, grade4, grade5};
scores = newScores;
}
//Getters and Setters
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public char getGrade() {
if(average >= 90 && average <= 100)
{
grade = 'A';
}
if(average >= 80 && average < 90)
{
grade = 'B';
}
if(average >= 70 && average < 80)
{
grade = 'C';
}
if(average >= 60 && average < 70)
{
grade = 'D';
}
if(average >= 0 && average < 60)
{
grade = 'F';
}
return grade;
}
public void setGrade(char grade) {
this.grade = grade;
}
public double getAverage() {
return average;
}
public void setAverage(double average) {
this.average = average;
}
public int[] getScores() {
return scores;
}
public void setScores(int[] scores) {
this.scores = scores;
}
//Calculate average score
public void calculateAverage()
{
int total = 0;
for (int i = 0; i < scores.length; i++)
{
total += scores[i];
}
average = total*1.0/scores.length;
}
//calculate letter grade based on average score (calulateAverage.average)
public void calculateGrade()
{
if(average >= 90 && average <= 100)
{
grade = 'A';
}
if(average >= 80 && average < 90)
{
grade = 'B';
}
if(average >= 70 && average < 80)
{
grade = 'C';
}
if(average >= 60 && average < 70)
{
grade = 'D';
}
if(average >= 0 && average < 60)
{
grade = 'F';
}
}
}
Your not specifying which Student you want the average of (Not sure why you named your class students with an s). It needs to look something like this:
section[1][1].getAverage()
I am doing my Java homework for a class. I wrote the below store program that the user inputs a 4 digit id and what money they had for that store id. This information get's put in an array. totals and store id's are retrieved.
in the next part of my program I am to retrieve min and max values from each data group:even and odd store id numbers. I have tried to do this by retrieving the origonal data and putting them into a new array. even data into an even array and odd data into an odd array. in the following code I am testing the even part. Once it works I will replicate in the odd section.
Right now the following code skips my request. I don't know how to fix this.
Any insight would be greatly appreciated!
import java.util.Scanner;
import java.util.ArrayList;
import java.util.Collections;
public class Bonus
{
public static void main (String[] arg)
{
Scanner in = new Scanner(System.in);
String storeID, highID;
double grandTotalSales = 0;
double evenGrandTotal = 0;
double oddGrandTotal = 0;
double evenTotalSale;
double oddTotalSale;
double largestYet = 0;
double maxValue = 0;
int numPenn, numNick, numDime, numQuar, numHalf, numDol;
boolean more = true;
boolean report = true;
String input;
int inputopt;
char cont;
char check1, highStoreID;
Store myStore;
ArrayList<Store> storeList = new ArrayList<Store>();
ArrayList<Store> evenStoreList = new ArrayList<Store>();
while(more)
{
in = new Scanner(System.in);
System.out.println("Enter 4 digit store ID");
storeID = in.nextLine();
System.out.println("Enter num of Penny");
numPenn = in.nextInt();
System.out.println("Enter num of Nickel");
numNick = in.nextInt();
System.out.println("Enter num of Dime");
numDime = in.nextInt();
System.out.println("Enter num of Quarter");
numQuar = in.nextInt();
System.out.println("Enter num of Half dollars");
numHalf = in.nextInt();
System.out.println("Enter num of Dollar bills");
numDol = in.nextInt();
myStore = new Store(storeID, numPenn, numNick, numDime, numQuar, numHalf, numDol);
storeList.add(myStore);
in = new Scanner(System.in);
System.out.println("More stores: Yes or No");
input = in.nextLine();
cont = input.charAt(0);
if((cont == 'N')||(cont == 'n'))
more = false;
}
while(report)
{
in = new Scanner(System.in);
System.out.println("What would you like to do? \nEnter: \n1 print Odd Store ID's report \n2 print Even Store ID's report \n3 to Exit");
inputopt = in.nextInt();
if(inputopt == 2)
{
System.out.println("\nEven Store ID's Report:");
System.out.println("Store ID" + " | " + " Total Sales" + " | " + "Even Total Sales");
for(int i = 0; i < storeList.size(); ++i)
{
myStore = (Store)(storeList.get(i));
storeID = myStore.getStoreID();
check1 = storeID.charAt(3);
if(check1 == '0' || check1 == '2' || check1 == '4'|| check1 == '6' || check1 =='8')
{
myStore.findEvenValue();
evenTotalSale = myStore.getEvenValue();
evenGrandTotal = evenGrandTotal + Store.getEvenValue();
System.out.println((storeList.get(i)).getStoreID() + " | " + (storeList.get(i)).getEvenValue() + " | " + (storeList.get(i)).getEvenGrandValue());
}
}
in = new Scanner(System.in);
System.out.println("Do want to print the highest and lowest sales? \nEnter yes or no");
input = in.nextLine();
cont = input.charAt(0);
if((cont == 'Y')||(cont == 'y'))
{
evenTotalSale = 0;
for(int i = 1; i < evenStoreList.size(); ++i)
{
myStore = (Store)(evenStoreList.get(i));
highID = myStore.getStoreID();
myStore.findEvenValue();
largestYet = myStore.getEvenValue();
if(largestYet > evenTotalSale)
{
Collections.copy(storeList, evenStoreList);
System.out.println("Store ID with highest sales is: ");
System.out.println((evenStoreList.get(i)).getStoreID() + " | " + largestYet);
}
}
}
else if((cont == 'N')||(cont == 'n'))
report = true;
}
else
if(inputopt == 1)
{
System.out.println("\nOdd Store ID's Report:");
System.out.println("Store ID" + " | " + " Total Sales" + " | " + " Odd Total Sales");
for(int i = 0; i < storeList.size(); ++i)
{
myStore = (Store)(storeList.get(i));
storeID = myStore.getStoreID();
check1 = storeID.charAt(3);
if(check1 == '1' || check1 == '3' || check1 == '5'|| check1 == '7' || check1 =='9')
{
myStore.findOddValue();
oddTotalSale = myStore.getOddValue();
oddGrandTotal = oddGrandTotal + Store.getOddValue();
System.out.println((storeList.get(i)).getStoreID() + " | " + (storeList.get(i)).getOddValue() + " | " + (storeList.get(i)).getOddGrandValue());
}
}
}
else
if(inputopt == 3)
report = false;
} // close while report
}// close of main
} // close class
class store:
public class Store
{
private String storeID;
private int numPenn, numNick, numDime, numQuar, numHalf, numDol;
Coin penn = new Coin("Penn", 0.01);
Coin nick = new Coin("Nickel", 0.05);
Coin dime = new Coin("Dime", 0.10);
Coin quar = new Coin("Quar", 0.25);
Coin half = new Coin("Half", 0.50);
Coin dol = new Coin("Dollar", 1.00);
private static double evenTotalSale;
private static double oddTotalSale;
static double evenGrandTotal = 0;
static double oddGrandTotal = 0;
public Store (String storeID, int numPenn, int numNick, int numDime, int numQuar, int numHalf, int numDol)
{
this.storeID = storeID;
this.numPenn = numPenn;
this.numNick = numNick;
this.numDime = numDime;
this.numQuar = numQuar;
this.numHalf = numHalf;
this.numDol = numDol;
}
public void findEvenValue()
{ evenTotalSale = numPenn * penn.getValue() + numNick * nick.getValue() + numDime * dime.getValue()
+ numQuar * quar.getValue() + numHalf * half.getValue() + numDol * dol.getValue();
evenGrandTotal = evenGrandTotal + evenTotalSale;
}
public static double getEvenValue()
{
return evenTotalSale;
}
public void findOddValue()
{ oddTotalSale = numPenn * penn.getValue() + numNick * nick.getValue() + numDime * dime.getValue()
+ numQuar * quar.getValue() + numHalf * half.getValue() + numDol * dol.getValue();
oddGrandTotal = oddGrandTotal + oddTotalSale;
}
public static double getOddValue()
{
return oddTotalSale;
}
public static double getOddGrandValue()
{
return oddGrandTotal;
}
public static double getEvenGrandValue()
{
return evenGrandTotal;
}
public String getStoreID()
{
return storeID;
}
}
your evenStoreList is empty.