Hi, I need help writing the following Java Program, Thanks Write an application
ID: 3614052 • Letter: H
Question
Hi,
I need help writing the following Java Program,
Thanks
Write an application program that declares one OneNumber objectand one TwoNumber object. (You will also need to declareother variables.) The program should ask the user to enterthe input filename and the output filename (use the Scanner classor JOptionPane). The main method should contain a while loopthat reads data from an input file. The loop should terminatewhen there is no more data in the file. The OneNumber objectshould call appropriate accessor/mutator methods and each of theadditional methods required for this particular class. TheTwoNumber object should call appropriate accessor/mutator methodsand each of the additional methods required for this particularclass. The program should output to a file all of theappropriate information for each object. Make sure that eachpart of the output is properly labeled and easy to read.
About the first class
Write a class named OneNumber that has one integer field. The class should contain at least one for loop and one while loopand have the following methods:
· Twoconstructors: the default constructor and one constructorwith one parameter,
· Standardmutator and accessor methods,
· isPrime– This method should determine if the number read from thefile is a prime number, (A prime number is a number divisibleby itself and 1.)
· sumOfDigits – This method should find the sum of the digitsof the number read from the file. (For example: the number 123 would add 1 + 2 + 3 to get 6).
· divisibleByNine – This method should determine if the numberread from the file is divisible by 9. (Use the fact that anumber is divisible by nine when the sum of the digits is divisibleby nine.)
About the second class
Write a class named TwoNumber.that has two integer fields. The class should contain at least one for loop and one while loopand have the following methods:
· Twoconstructors: the default constructor and one constructorwith two parameters,
· Standardaccessor and mutator methods.
· greatestCommonFactor – This method should find the largestnumber that can be divided into the two numbers read from thefile.
· sumBetweenNumbers – This method should add all of the numbersbetween the two numbers read from the file (include the numbersread). For example: if the numbers were 5 and 9 thenthe method would add 5 + 6 + 7 + 8 + 9 to get 35.
Explanation / Answer
Helloo I am glad to answer you question but it is really biganswer you should have asked one at a time... 1) one number class... public class OneNumber{ private int integer; public OneNumber() { } public OneNumber(int num){ this.integer=num; } public int getInteger() { return integer; } public void setInt(int newInt) { integer=newInt; } public void isPrime(int prime) { if (prime%1==0 && prime%prime==0) { System.out.println("It is a prime number"); }else { System.out.println("It is not a prime number"); } } public void sumOfDigits(String num) { // i dont know this method.. } public void divisibleByNine(int some) { if (some%9==0) { System.out.println("The number is divisible bynine"); }else { System.out.println("The number is not divisible bynine"); } Thank you this is the first class... i hope this help.. please rate..Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.