stringformatter
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revision | Last revisionBoth sides next revision | ||
stringformatter [2022/05/23 15:29] – frchris | stringformatter [2022/05/23 16:40] – frchris | ||
---|---|---|---|
Line 1: | Line 1: | ||
**StringFormatter** | **StringFormatter** | ||
[[https:// | [[https:// | ||
+ | < | ||
+ | import java.util.ArrayList; | ||
+ | import java.util.List; | ||
+ | /** | ||
+ | * AP 2016 FRQ 4 | ||
+ | * | ||
+ | */ | ||
+ | public class StringFormatter | ||
+ | { | ||
+ | public static int totalLetters( List< | ||
+ | { | ||
+ | // add code here for part (a) | ||
+ | } | ||
+ | |||
+ | public static int basicGapWidth( List< | ||
+ | { | ||
+ | // add code here for part (b) | ||
+ | |||
+ | } | ||
+ | |||
+ | |||
+ | public static String format( List< | ||
+ | { | ||
+ | // add code here for part (c) | ||
+ | } | ||
+ | /** | ||
+ | * Implementation of leftoverSpaces | ||
+ | */ | ||
+ | public static int leftoverSpaces(List< | ||
+ | { | ||
+ | int spaces = formattedLen-totalLetters(wordList); | ||
+ | int gaps = wordList.size()-1; | ||
+ | int gapWidth = basicGapWidth(wordList, | ||
+ | return spaces - gaps*gapWidth; | ||
+ | } | ||
+ | |||
+ | public static void main(String[] args) | ||
+ | { | ||
+ | String[] words1 = {" | ||
+ | String[] words2 = {" | ||
+ | String[] words3 = {" | ||
+ | String[] words4 = {" | ||
+ | testItWith(words1, | ||
+ | testItWith(words2, | ||
+ | testItWith(words3, | ||
+ | testItWith(words4, | ||
+ | } | ||
+ | public static void testItWith(String[] words, int wordCount, int gaps, int leftOvers) | ||
+ | { | ||
+ | ArrayList< | ||
+ | |||
+ | for (String str: | ||
+ | list.add(str); | ||
+ | System.out.print(str+ " "); | ||
+ | } | ||
+ | System.out.print(" | ||
+ | System.out.println(totalLetters(list)); | ||
+ | System.out.print(" | ||
+ | System.out.println(basicGapWidth(list, | ||
+ | System.out.print(" | ||
+ | System.out.println(leftoverSpaces(list, | ||
+ | String f = format(list, | ||
+ | System.out.print(" | ||
+ | System.out.println(f.length()); | ||
+ | System.out.println(" | ||
+ | |||
+ | } | ||
+ | } | ||
+ | </ | ||
[[https:// | [[https:// | ||
stringformatter.txt · Last modified: 2022/05/23 16:42 by frchris