Question

Download the replacement CPS150_Lab10.java file into the project source folder (e.g., Documents\NetBeansProjects\CPS150_Lab10\src\cps150_lab10) In the Project explorer,...

Download the replacement CPS150_Lab10.java file into the project source folder (e.g., Documents\NetBeansProjects\CPS150_Lab10\src\cps150_lab10)

In the Project explorer, right-click on the downloaded CPS150_Lab7.java and select the Refactor > Move... menu option
When the confirmation dialog appears, click the Refactor button

Then:
  Type your name after the @author tag in the comment block before the class definition; i.e.:
  

/**
* CPS 150, Section add your section number here
*
* Lab Project 10

*
* @author add your name here
*/

Complete the program (main method) definition by adding the required code, incidated by the tag *** ADD CODE HERE ***

Complete the definition for the addTwoInts method, indicated by the tag *** ADD METHOD DEFINITION HERE ***, so that the method consumes two integers and calculates and produces their integer sum

Compile and run the program, making sure that a random sum is generated each time.
You can also confirm the program execution by navigating to your project folder in the Windows Explorer (or the Mac OS Finder) and opening the file with a text editor (NotePad, NotePad++, WordPad, etc.) to see the two random numbers generated by the last execution.

Homework Answers

Answer #1

import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.util.Random;

/**
* CPS 150, Section add your section number here
*
* Lab Project 10
*
* @author Chirag Tagadiya
*/


public class CPS150_lab10 {
   private static final String FILENAME = "C:\\Users\\cr\\Desktop\\random.txt";
   public static int addTwoInt(int num1,int num2){
       return num1+num2;
   }
public static void main(String[] args) {
   int c;
   Random t=new Random();
  
   int number1=t.nextInt(100);
   int number2=t.nextInt(100);
   System.out.println(number1);
   System.out.println(number2);
   int sum=addTwoInt(number1,number2);
   BufferedWriter bw = null;
   FileWriter fw = null;

   try {

       File f=new File(FILENAME);

       fw = new FileWriter(f.getAbsoluteFile(),true);
       bw = new BufferedWriter(fw);
      
       bw.write(number1+" "+number2+" "+sum);
       bw.newLine();

       System.out.println("Done");

   } catch (IOException e) {

       e.printStackTrace();

   } finally {

       try {

           if (bw != null)
               bw.close();

           if (fw != null)
               fw.close();

       } catch (IOException ex) {

           ex.printStackTrace();

       }

   }


  
  
}
}

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
Download the ProductUpTo3.java file, and open it in jGrasp (or a text editor of your choice)....
Download the ProductUpTo3.java file, and open it in jGrasp (or a text editor of your choice). This program will read in three integers with Scanner, put the values in an array of int, and then print the product of the three values. Example output of the program is shown below, with user input shown in bold: Enter first integer: 3 Enter second integer: 4 Enter third integer: 5 Product: 60 More details about the method you need to write are...
I need this before the end of the day please :) In Java 10.13 Lab 10...
I need this before the end of the day please :) In Java 10.13 Lab 10 Lab 10 This program reads times of runners in a race from a file and puts them into an array. It then displays how many people ran the race, it lists all of the times, and if finds the average time and the fastest time. In BlueJ create a project called Lab10 Create a class called Main Delete what is in the class you...
Project 2 statement Please write this in JAVA. Please read this entire statement carefully before you...
Project 2 statement Please write this in JAVA. Please read this entire statement carefully before you start doing anything… This project involves implementing a simple university personnel management program. The program contains two different kinds of objects: students and faculty. For each object, the program stores relevant information such as university ID, name, etc. Different information is stored depending on the type of the object. For example, a student has a GPA, while a faculty has a title and department...
Program Behavior Each time your program is run, it will prompt the user to enter the...
Program Behavior Each time your program is run, it will prompt the user to enter the name of an input file to analyze. It will then read and analyze the contents of the input file, then print the results. Here is a sample run of the program. User input is shown in red. Let's analyze some text! Enter file name: sample.txt Number of lines: 21 Number of words: 184 Number of long words: 49 Number of sentences: 14 Number of...
Finish the CustomerAccountTransactions program that reads customer accounts receivable data from a file and then applies...
Finish the CustomerAccountTransactions program that reads customer accounts receivable data from a file and then applies a series of transactions to the accounts. Its main() method uses the CustomerAccounts class to manage a collection of CustomerAccount objects: reading customer accounts data & transactions, and obtaining a String showing the customer accounts data after the operations are complete. You will need to complete the readCustomerAccounts () and applyTransactions() methods in the CustomerAccounts class. First, please fill in your name in the...
Complete a Java program named ARMgr that maintains customer accounts receivable in a database. The code...
Complete a Java program named ARMgr that maintains customer accounts receivable in a database. The code to initialize the CustomerAccountsDB database table and add a set of customer accounts is provided. Finish the code in these 3 methods in CustomerAccountDB.java to update or query the database: -purchase(double amountOfPurchase) -payment(double amountOfPayment) -getCustomerName() Hint: For getCustomerName(), look at the getAccountBalance() method to see an example of querying data from the database. For the purchase() and payment() methods, look at the addCustomerAccount() method...
this is the book name. Data Structures and Abstractions with Java 1) Description: The sample programs...
this is the book name. Data Structures and Abstractions with Java 1) Description: The sample programs in Chapter 1 of your textbook are not complete. They are used for illustration purpose only. The implementation of Listing 1-1 on page 39 is explained in Chapter 2. And, in order to see the result of using it, we will need the following set of files: i. BagInteface.java – the specification only. ii. ArrayBag.java – the implementation of BagInerface.java. iii. ArrayBagDemo.java – a...