Results 1 to 3 of 3
  1. #1
    clemsontigers is offline Member
    Join Date
    Oct 2010
    Posts
    44
    Rep Power
    0

    Default help w/ storing/scanning numbers in arrays

    im kinda stuck on what to do on this assignment and tried to email my instructor but he didnt respond(were on spring break btw)

    but here are my instructions

    Enhance / modify the program you created in the previous assignment. Create a class ScanArray. This class should have two methods FindMax and FindMin. Class ScanArray should have a constructor. main should call the constructor, next should use / call the two methods of the object to identify the min and max. Next, main informs the instructor of the minimum grade and maximum grade.

    and here is my code from the previous assignment
    Java Code:
    import java.util.Scanner;
    import java.util.Arrays;
    
    public class Array
    { public static void main(String[] args)
    {
    //input scanner
    Scanner input = new Scanner(System.in);
    
    //Prompt User for midterm1 grades
    double[]midTerm1= new double [10];
    for (int A = 0; A <midTerm1.length; A++){
    System.out.println("Please enter MidTerm1 grade:");
    midTerm1[A] = input.nextDouble();
    }
    System.out.println("Now");
    
    //Prompt User for midterm2 grades
    double[]midTerm2=new double[10];
    for(int B=0; B<midTerm2.length;B++){
    System.out.println("Please enter a MidTerm2 grade:");
    midTerm2[B] = input.nextDouble();
    }
    System.out.println("Now");
    
    //Prompt User for Final Exam grades
    double[]finalExam = new double[10];
    for(int C = 0; C<finalExam.length; C++){
    System.out.println("Please enter a Final Exam grade:");
    finalExam[C] = input.nextDouble();
    }
    double [] grades = new double [10];
    
    for (int i = 0; i < grades.length;i ++){
    grades[i] = midTerm1[i] +midTerm2[i]+finalExam[i];
    }
    
    
    double max = 0;
    double min = 0;
    
    max = grades[0]; 
    for (int i=1; i<grades.length; i++) {
    if (grades[i] > max) {
    max = grades[i]; 
    }
    }
    
    min = grades[0]; 
    for (int i=1; i<grades.length; i++) {
    if (grades[i] < min) {
    min = grades[i]; 
    }
    }
    
    
    System.out.print("Your highest test score is: " + max);
    System.out.print("Your lowest test score is: " + min);
    System.out.print("You have entered following grades for midTerm1: ");
    System.out.println(Arrays.toString(mid…
    System.out.print("You have entered following grades for midTerm2: ");
    System.out.println(Arrays.toString(mid…
    System.out.print("You have entered following grades for Final Exam: ");
    System.out.println(Arrays.toString(fin…
    
    
    
    }
    }

  2. #2
    Zack's Avatar
    Zack is offline Senior Member
    Join Date
    Jun 2010
    Location
    Destiny Islands
    Posts
    692
    Rep Power
    5

    Default

    Did you have a specific question? We're not here to do your homework for you.

  3. #3
    sibernewf is offline Member
    Join Date
    Mar 2011
    Posts
    48
    Rep Power
    0

    Default

    Ok, I wont solve the problem for you.
    But read the requirements and start with that:

    1. This class should have two methods FindMax and FindMin.
    2. Class ScanArray should have a constructor. main should call the constructor, next should use / call the two methods of the object to identify the min and max.
    3. Next, main informs the instructor of the minimum grade and maximum grade.

    So...I'll help a little but wont cover everything here.
    1. Create a class called ScanArray
    2. Create a method called findMax
    3. Create a method called findMin
    **Now think about if these methods need to pass any parameters or not, if not, why not, and if so, why.
    **Also think about how to loop through an array and find the smallest number.
    **Also think about how to loop through an array to find the largest number.

    From your previous assignment, it looks like you pretty much have some of this already covered, but you need to figure out which parts and how to write them in the new class and how to use them.

    I dunno if this is useful, but I find it easier to break down the specification document (what the instructor wants you to do) into basic steps. Just remember verbs in the specification would make great methods, and nouns would make great fields in a class.

    Good Luck

Similar Threads

  1. Replies: 4
    Last Post: 03-15-2011, 03:58 AM
  2. Storing Inputs in Two Linked Arrays
    By essence388 in forum New To Java
    Replies: 1
    Last Post: 12-26-2010, 02:21 PM
  3. help w/ storing/scanning numbers in two dimensional arrays
    By clemsontigers in forum New To Java
    Replies: 15
    Last Post: 12-02-2010, 02:08 AM
  4. help w/ storing/scanning numbers in arrays
    By clemsontigers in forum New To Java
    Replies: 15
    Last Post: 11-18-2010, 05:12 AM
  5. Need help storing arrays from a file
    By arson09 in forum New To Java
    Replies: 4
    Last Post: 03-08-2010, 04:11 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •