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
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...
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...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT