The point of this assignment is to cover a few of the basic principles of classes and objects including the proper use of methods.
The solution for this assignment (at least the one I implemented) can be accomplished by inserting code to determine if a prime number ends in the digit entered by the user.
Using the IDE
Remember that all code must be submitted in text format.
Initial Code & Output
Load the following code into the online compiler:
https://www.jdoodle.com/online-java-compiler/
Please copy the following code into the IDE, compile and run it.
import java.util.Scanner;
class Car {
public void start () {
System.out.println(The Car Has Started
);
}
}
public class MyClass {
public static void main(String args[]) {
System.out.println(A06 Written by Matt Weisfeld
);
String consoleInput = null;
Scanner console = new Scanner(System.in);
Car myCar = new Car();
System.out.print(Please enter a color (or x to end):
);
consoleInput = console.nextLine();
System.out.println(
You entered + consoleInput +
);
myCar.start();
System.out.print(Goodbye!);
}
}
This code is an introduction to creating objects and passing arguments to those objects. We will cover much of this in detail later in the course; however, take this opportunity to study the code and determine what is going on.
When you execute the code it will look something like this:
Problem
Add the constructor for the Car class and add the accessor (getters and setters) methods for the color attribute.
https://www.tutorialspoint.com/java/java_constructors.htm
https://www.w3schools.com/java/java_encapsulation.asp
Here is an article I wrote many years ago on encapsulation which is what accessor methods support.
https://www.developer.com/java/other/article.php/10936_3374921_3/Exploring-Encapsulation.htm
Here are 5 constraints that you must include in your program.
- Include an output statement at the beginning of the program with the assignment number and your name:
A06 Written by Matt Weisfeld
- The constructor must pass a single argument to initialize the color.
- When the constructor is called, set the cars initial color to Green.
- Include a loop to change the color until an x is entered.
- Include a condition to test for the x and when found use a break to exit the loop.
- Print goodbye upon exiting the program.
Final Output
Once completed, your output (in the following test case) should look like this:
Test case: enter Red, Blue, x
Note the input box

![[Solved] IT2650 Assignment6-Classes, Objects and Methods](https://assignmentchef.com/wp-content/uploads/2022/08/downloadzip.jpg)

![[Solved] IT2650 Assignment11](https://assignmentchef.com/wp-content/uploads/2022/08/downloadzip-1200x1200.jpg)
Reviews
There are no reviews yet.