Question: In java please Objective Note: This homework does not use polymorphism. We are going to do a math problem instead Find the set of smallest

In java please

Objective

Note: This homework does not use polymorphism. We are going to do a math problem instead

Find the set of smallest factors that compose a number

  • Example: n = 90
    • Factors = {1, 2, 3, 5, 6, 9, 10, 15, 18, 30, 45, 90 }
    • Least Factors = {2,3,3,5}
  • That is, 2 * 3 * 3 * 5 = 90
  • Notice these are the smallest of the factors?

Part 1

Write a method that returns a List of all factors for a variable n

What are the factors of n?

  • They are the numbers from 1 to n that divide evenly into n
    • Note: No number greater than n can divide evenly into it
  • You can test if something divides evenly with Modulus (%)
    • Returns the remainder of the division

Part 2

Write a Method that takes a List of factors and the number n and returns the List of smallest factors

Follow this algorithm (written in pseudocode)

  • while(n != 1)
    • i = 1
    • nextDivFound = false
    • while(nextDivFound == false)
      • if factors[i] divides evenly into n
        • nextDivFound = true
        • returnList.add(factors[i])
        • n = n / factors[i]
      • else i++

Note that the factor[0] is skipped. This will contain the number 1 and will lead to an infinite loop.

Main Function

Read in the value n from the console using any method you prefer.

  • Example is Scanner from java.util.*
  • Scanner scan = new Scanner(System.in);
  • int n = scan.nextInt();

Call your first method to find the factors then output the List it returns. Next call the second method to find the smallest factors and output the List it returns.

In java please Objective Note: This homework doesIn java please Objective Note: This homework doesIn java please Objective Note: This homework does

In java please Objective Note: This homework does

(6) Ford Focus ST/RS parts for salx Homework 5 X D 2015 Ford Focus Stereos|CD IX D Dorm ollege.edu/courses/64547/assignments/1416011?module_item_id3416578 VIORICOVICIU CLICCICGUROSTALMOLOGICAL WIRINGWAY Set the JLabel to the string you built Call.pack() on your base frame to resize it automatically To try selecting multiple items in the list, hold down control or shift. By default the list will allow you to select mu o Choose Selection Mode: Multiple Choose Selection Mode: Single Choose Selection Mode: Single Bahamas Costa Rica Canada Cuba Bahar Costa Rica Can Bahamas Costa Rica Canada Cuba Haiti Jamaica Mexico United States of America Selected items will appear here Cuba Haiti Jamaica Mexico United States of America Selected items: Canada Jamaica Mexico Mexico United States of America Selected items: Haiti My Layout If you want the same layout Fused, it was a combination of a Panel with FlowLayout and Border Layout: Component panel = new JPanel(); panel.setLayout(new FlowLayout(); panel.add(new JLabel("Choose Selection Mode:")); (6) Ford Focus ST/RS parts for salx Homework 5 X D 2015 Ford Focus Stereos|CD IX D Dorm ollege.edu/courses/64547/assignments/1416011?module_item_id3416578 VIORICOVICIU CLICCICGUROSTALMOLOGICAL WIRINGWAY Set the JLabel to the string you built Call.pack() on your base frame to resize it automatically To try selecting multiple items in the list, hold down control or shift. By default the list will allow you to select mu o Choose Selection Mode: Multiple Choose Selection Mode: Single Choose Selection Mode: Single Bahamas Costa Rica Canada Cuba Bahar Costa Rica Can Bahamas Costa Rica Canada Cuba Haiti Jamaica Mexico United States of America Selected items will appear here Cuba Haiti Jamaica Mexico United States of America Selected items: Canada Jamaica Mexico Mexico United States of America Selected items: Haiti My Layout If you want the same layout Fused, it was a combination of a Panel with FlowLayout and Border Layout: Component panel = new JPanel(); panel.setLayout(new FlowLayout(); panel.add(new JLabel("Choose Selection Mode:"))

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!