본문 바로가기
자바(Java)/자바 AP

AP Computer Science A [FRQ] Practice (2)

by 긱펀 2024. 4. 4.
반응형

AP Computer Science A [FRQ] Practice (2)

 

FRQ  Question 1 notice

To succeed on the FRQ Question 2 on Classes, you must know how to:

-Create a class using public class Classname { }
-Write a constructor with the same name as the class and no return type. This constructor will probably have a parameter that is assigned to an instance variable and will need to assign default values to the other instance variables.
Write public methods in the class that use the instance variables as well as parameters and return values. These methods will probably use if statements but not more complex coding. One of these methods will probably be an accessor(getter) method that returns an instance variable or a calculated value that is dependent on the instance variables, and one will probably be a mutator(setter) method that changes the value of an instance variable.

 

*Java Quick Reference(아래 "더보기")

 

 

*2019 FRQ  출시문제

 

 

위 2019 문제의 Question 2 부분을 풀어보세요.

 


 

[정답은 아래 "더보기" 클릭]

더보기

2019 FRQ Question 2 모범답안

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
public class StepTracker {
    private int minSteps;
    private int numActiveDays;
    private int totalSteps;
    private int numDays;
    
    // "A StepTracker object is created with a parameter that defines 
    //the minimum number of steps that must be taken for a day 
    //to be considered active."
    public StepTracker(int minSteps) {
        this.minSteps = minSteps;
        numActiveDays = 0;
        totalSteps = 0;
        numDays = 0;
    }
    
    // accessor(getter)
    // returns the number of active days
    public int activeDays() {
        return numActiveDays;
    }
    
    // mutator(setter)
    // accumulates information about steps, per day
    public void addDailySteps(int mySteps) {
        totalSteps += mySteps;
        if(mySteps >= minSteps) { // >= 10,000 (minSteps)
            numActiveDays++;
        }
        numDays++;
    }
    
    public double averageSteps() {
        if(numDays == 0return 0.0;
        else return (double) totalSteps / numDays;
    }
}
cs

 

 

*Scoring Guidelines

 

 


 

 

 

*2010 FRQ 2번 출시문제

 

 

 

위 2010 문제의 Question 2 부분을 풀어보세요.

 


 

[정답은 아래 "더보기" 클릭]

더보기

2010 FRQ Question 2 모범답안

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
public class APLine {
    private int a;
    private int b;
    private int c;
    /*
    private double a;
    private double b;
    private double c;
    */
    
    public APLine(int a, int b, int c) {
        this.a = a;
        this.b = b;
        this.c = c;
    }
    
    public double getSlope() {
        return -1*((double)a / b);
        // (x) (double) -1*(a/b)
        // if private double a,b,c => return -1*(a/b);
    }
    
    public boolean isOnLine(int a, int b) {
        int result = this.a * a + this.b * b + this.c;
        if(result == 0return true;
        else return false;
        
        // short code
        // return ( (this.a*a+this.b*b+this.c) == 0)
    }
    
    // Test main code for lecture
    /*
    public static void main(String[] args) {
        APLine line1 = new APLine(5,4,-17);
        System.out.println(line1.getSlope());
        System.out.println(line1.isOnLine(5,-2));
    }
    */
    
}
cs

 

728x90
반응형

'자바(Java) > 자바 AP' 카테고리의 다른 글

AP Computer Science A [FRQ] Practice (4)  (0) 2024.04.04
AP Computer Science A [FRQ] Practice (3)  (0) 2024.04.04
AP Computer Science A [FRQ] Practice (1)  (0) 2024.04.04
APCSA Mock Test  (0) 2024.03.29
[자바AP연습문제] 10.Recursion  (0) 2024.03.29

댓글