stringformatter
Differences
This shows you the differences between two versions of the page.
| Next revision | Previous revision | ||
| stringformatter [2022/05/23 15:19] – created frchris | stringformatter [2022/05/23 16:42] (current) – frchris | ||
|---|---|---|---|
| Line 1: | Line 1: | ||
| **StringFormatter** | **StringFormatter** | ||
| [[https:// | [[https:// | ||
| + | <code java> | ||
| + | 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 testItWith(String[] words, int wordCount, int gaps, int leftOvers) | ||
| + | { | ||
| + | ArrayList< | ||
| + | | ||
| + | for (String str:words){ | ||
| + | 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(" | ||
| + | | ||
| + | } | ||
| + | | ||
| + | | ||
| + | public static void main(String[] args) | ||
| + | { | ||
| + | String[] words1 = {" | ||
| + | String[] words2 = {" | ||
| + | String[] words3 = {" | ||
| + | String[] words4 = {" | ||
| + | testItWith(words1, | ||
| + | testItWith(words2, | ||
| + | testItWith(words3, | ||
| + | testItWith(words4, | ||
| + | } | ||
| + | } | ||
| + | |||
| + | |||
| + | </ | ||
| + | |||
| + | [[https:// | ||
stringformatter.1653333541.txt.gz · Last modified: 2022/05/23 15:19 by frchris