Skip to content

Commit dd6cb52

Browse files
Completed Ch10 Find the Errors 1-4
1 parent 0a45cd3 commit dd6cb52

File tree

4 files changed

+118
-0
lines changed

4 files changed

+118
-0
lines changed
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
/*
2+
* This program was written by Kyle Martin on 7/8/2021 for Java Programming Principles 2 during Summer Session 2
3+
* at Southwestern College, Kansas.
4+
*
5+
* IMPORTANT: Normally I would not place a bunch of comments in my code describing what my code is doing as I like to
6+
* have code that is written in a manner to be understandable while reading it. Though, do to the grading rubric I will
7+
* explain my code.
8+
*
9+
* This program was created to fix the errors in question 4
10+
* See Chapter 10 Find the Error Question 4.
11+
*/
12+
13+
public class QuestionFour {
14+
// Superclass
15+
public abstract class Vehicle // Made class abstract
16+
{
17+
public abstract double getMilesPerGallon();
18+
}
19+
// Subclass
20+
public class Car extends Vehicle
21+
{
22+
private double mpg; // double
23+
public double getMilesPerGallon() // removed semicolon & turned into double
24+
{
25+
return mpg;
26+
}
27+
}
28+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
/*
2+
* This program was written by Kyle Martin on 7/8/2021 for Java Programming Principles 2 during Summer Session 2
3+
* at Southwestern College, Kansas.
4+
*
5+
* IMPORTANT: Normally I would not place a bunch of comments in my code describing what my code is doing as I like to
6+
* have code that is written in a manner to be understandable while reading it. Though, do to the grading rubric I will
7+
* explain my code.
8+
*
9+
* This program was created to fix the errors in question 1
10+
* See Chapter 10 Find the Error Question 1.
11+
*/
12+
13+
public class QuestionOne {
14+
/* Question 1 */
15+
16+
// Superclass
17+
public class Vehicle
18+
{
19+
// Declarations & Methods
20+
}
21+
// Subclass
22+
public class Car extends Vehicle // changed expands keyword to extends
23+
{
24+
// Declarations & Methods
25+
}
26+
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
/*
2+
* This program was written by Kyle Martin on 7/8/2021 for Java Programming Principles 2 during Summer Session 2
3+
* at Southwestern College, Kansas.
4+
*
5+
* IMPORTANT: Normally I would not place a bunch of comments in my code describing what my code is doing as I like to
6+
* have code that is written in a manner to be understandable while reading it. Though, do to the grading rubric I will
7+
* explain my code.
8+
*
9+
* This program was created to fix the errors in question 3
10+
* See Chapter 10 Find the Error Question 3.
11+
*/
12+
13+
public class QuestionThree {
14+
/* Question 3 */
15+
// Superclass
16+
public class Vehicle
17+
{
18+
private double cost;
19+
public Vehicle(double c)
20+
{
21+
cost = c;
22+
}
23+
24+
public Vehicle() {
25+
// added constructor to fix errors on line 20
26+
}
27+
}
28+
// Subclass
29+
public class Car extends Vehicle
30+
{
31+
private int passengers;
32+
public Car(int p) // added Vehicle constructor above
33+
{
34+
passengers = p; // changed c to p
35+
}
36+
}
37+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
/*
2+
* This program was written by Kyle Martin on 7/8/2021 for Java Programming Principles 2 during Summer Session 2
3+
* at Southwestern College, Kansas.
4+
*
5+
* IMPORTANT: Normally I would not place a bunch of comments in my code describing what my code is doing as I like to
6+
* have code that is written in a manner to be understandable while reading it. Though, do to the grading rubric I will
7+
* explain my code.
8+
*
9+
* This program was created to fix the errors in question 2
10+
* See Chapter 10 Find the Error Question 2.
11+
*/
12+
13+
public class QuestionTwo {
14+
// Superclass
15+
public class Vehicle
16+
{
17+
public double cost; // changed to public as private variables can not be inherited
18+
}
19+
// Subclass
20+
public class Car extends Vehicle
21+
{
22+
public Car(double c)
23+
{
24+
cost = c;
25+
}
26+
}
27+
}

0 commit comments

Comments
 (0)