Question

In: Computer Science

open up a new Java project on Eclipse named Review and create a new class called...

  • open up a new Java project on Eclipse named Review and create a new class called Review.java.
  • Copy and paste the below starter code into your file:

/**

* @author

* @author

* CIS 36B
*/

//write your two import statements here

public class Review {
  
    public static void main(String[] args) { //don't forget IOException
        File infile = new File("scores.txt");
        //declare scores array
        //Use a for or while loop to read in data from scores.txt to the array
        //call method
        //Use a for loop to write data from array into extraCredit.txt
      
    }
    
        
    /**
     * Write complete Javadoc comment here
     */
    //write your addExtraCredit method here   
  
}

  • Next, create a new text file named scores.txt
    • Rick-click the project. Go to New->File.
    • Name your file scores.txt
    • Make sure the text file gets saved inside the overall project folder (Review), not in the src folder
  • Now, copy and paste the following data (exam scores) into your scores.txt file:

90
95
86
41
79
56
90
83
74
98
56
81
64
99
12

  • Your program must declare an array of integers, and populate the array with the contents of the file.
    • You may assume that the length of the array is known to be 15 elements.
  • Next, write a method called addExtraCredit:
    • The addExtraCredit method takes in one parameter - an array of integers
    • It adds 2 to each element in the array (hint: think for loop)
    • It returns nothing
  • Inside of main, call the addExtraCredit method, passing it the array of exam scores.
  • Next, write the contents of the array to a file named extraCredit.txt.
    • Use PrintWriter to write out to the file (see lesson notes above).
  • When you are finished, extraCredit.txt should contain the following:
    • Don't forget the title!

Scores with Extra Credit:
92
97
88
43
81
58
92
85
76
100
58
83
66
101
14

  • Hint: Your program should include either 3 for loops or 2 for loops and a while loop.
  • If you get stuck, review today's lesson notes.
  • When extraCredit.txt contains the above data, submit your program to Canvas.
  • Both partners must submit to receive credit.

Solutions

Expert Solution

If you have any doubts, please give me comment...

/**

* @author

* @author CIS 36B

*/

// write your two import statements here

import java.io.*;

import java.util.*;

public class Review {

    public static void main(String[] args) throws IOException{ // don't forget IOException

        File infile = new File("scores.txt");

        Scanner fileScnr =new Scanner(infile);

        // declare scores array

        int scores[] = new int[15];

        // Use a for or while loop to read in data from scores.txt to the array

        int n=0;

        while(fileScnr.hasNextInt()){

            scores[n] = fileScnr.nextInt();

            n++;

        }

        fileScnr.close();

        // call method

        addExtraCredit(scores);

        // Use a for loop to write data from array into extraCredit.txt

        PrintWriter pw = new PrintWriter(new File("extraCredit.txt"));

        for(int i=0; i<n; i++){

            pw.println(scores[i]);

        }

        pw.close();

    }

    /**

     * Write complete Javadoc comment here

     */

    // write your addExtraCredit method here

    public static void addExtraCredit(int scores[]){

        for(int i=0; i<scores.length; i++){

            scores[i] += 2;

        }

    }

}


Related Solutions

Create a Java project called Lab3B and a class named Lab3B. Create a second new class...
Create a Java project called Lab3B and a class named Lab3B. Create a second new class named Book. In the Book class: Add the following private instance variables: title (String) author (String) rating (int) Add a constructor that receives 3 parameters (one for each instance variable) and sets each instance variable equal to the corresponding variable. Add a second constructor that receives only 2 String parameters, inTitle and inAuthor. This constructor should only assign input parameter values to title and...
Create a Java project called Lab3A and a class named Lab3A. Create a second new class...
Create a Java project called Lab3A and a class named Lab3A. Create a second new class named Employee. In the Employee class: Add the following private instance variables: name (String) job (String) salary (double) Add a constructor that receives 3 parameters (one for each instance variable) and sets each instance variable equal to the corresponding variable. (Refer to the Tutorial3 program constructor if needed to remember how to do this.) Add a public String method named getName (no parameter) that...
Create a Java project called 5 and a class named 5 Create a second new class...
Create a Java project called 5 and a class named 5 Create a second new class named CoinFlipper Add 2 int instance variables named headsCount and tailsCount Add a constructor with no parameters that sets both instance variables to 0; Add a public int method named flipCoin (no parameters). It should generate a random number between 0 & 1 and return that number. (Important note: put the Random randomNumbers = new Random(); statement before all the methods, just under the...
Create a new Java project called lab1 and a class named Lab1 Create a second class...
Create a new Java project called lab1 and a class named Lab1 Create a second class called VolumeCalculator. Add a static field named PI which = 1415 Add the following static methods: double static method named sphere that receives 1 double parameter (radius) and returns the volume of a sphere. double static method named cylinder that receives 2 double parameters (radius & height) and returns the volume of a cylinder. double static method named cube that receives 1 double parameter...
1. Create a new Java project called L2 and a class named L2 2. Create a...
1. Create a new Java project called L2 and a class named L2 2. Create a second class called ArrayExaminer. 3. In the ArrayExaminer class declare the following instance variables: a. String named textFileName b. Array of 20 integers named numArray (Only do the 1st half of the declaration here: int [] numArray; ) c. Integer variable named largest d. Integer value named largestIndex 4. Add the following methods to this class: a. A constructor with one String parameter that...
OOPDA in java project. in eclipse Instructions: Create a class called Person with the properties listed:...
OOPDA in java project. in eclipse Instructions: Create a class called Person with the properties listed: int id, String firstName, String middleName, String lastName, String email, String ssn, int age. The Person class should have getters and setters for all properties other than id. (You may use Eclipse to help you auto-generate these.) Person class should also have a getter for id Create a no-arg constructor for Person In addition to these getters and setters, Person should have the following...
Create a new Java Project named “Packages” from within Eclipse. Following the example in the Week...
Create a new Java Project named “Packages” from within Eclipse. Following the example in the Week 6 lecture, create six packages: Main, add, subtract, multiply, divide, and modulo. ALL of these packages should be within the “src” folder in the Eclipse package Explorer. ALL of the packages should be on the same “level” in the file hierarchy. In the “Main” package, create the “Lab04.java” file and add the needed boilerplate (“Hello, World!” style) code to create the main method for...
JAVA LANGUAGE Create a new project named BankAccount in Eclipse. Then, implement the following requirements. You...
JAVA LANGUAGE Create a new project named BankAccount in Eclipse. Then, implement the following requirements. You need to create two classes, one for BankAccount (BankAccount.java) and the other for the tester (BankAccountTest.java). Make sure your program compile without errors before submitting. Submit .java files to eCampus by the end of next Thursday, 10/15/2020. Part 1: Create the BankAccount class (template is attached after the project description) in the project. You must add the following to the BankAccount class: An instance...
JAVA Programming ECLIPSE IDE 1. Create an abstract class called Book. The class should declare the...
JAVA Programming ECLIPSE IDE 1. Create an abstract class called Book. The class should declare the following variables: an instance variable that describes the title - String an instance variable that describes the ISBN - String an instance variable that describes the publisher - String an instance variable that describes the price - double an instance variable that describes the year – integer Provide a toString() method that returns the information stored in the above variables. Create the getter and...
JAVA Programming ECLIPSE IDE 1. Create an abstract class called Book. The class should declare the...
JAVA Programming ECLIPSE IDE 1. Create an abstract class called Book. The class should declare the following variables: an instance variable that describes the title - String an instance variable that describes the ISBN - String an instance variable that describes the publisher - String an instance variable that describes the price - double an instance variable that describes the year – integer Provide a toString() method that returns the information stored in the above variables. Create the getter and...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT