[SOLVED] IT2650 Assignment6-Classes, Objects and Methods

30.00 $

Category:
Click Category Button to View Your Next Assignment | Homework

You will receive the following solution file(s) instantly after successful payment:

zip file icon Assignment6-f2aqqh.zip (986.2 KB)
Assignment Instructions Updated Recently? Submit Below and we will provide new Solution!
Submit New Instructions
🔒 Securely Powered by:
Secure Checkout
Rate this product

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\n”);

 

}

}

 

public class MyClass {

 

public static void main(String args[]) {

 

System.out.println(“A06 – Written by Matt Weisfeld\n”);

 

String consoleInput = null;

 

Scanner console = new Scanner(System.in);

 

Car myCar = new Car();

 

System.out.print(“Please enter a color (or ‘x’ to end): \n”);

 

consoleInput = console.nextLine();

 

System.out.println(“\nYou entered ” + consoleInput + “\n”);

 

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 car’s 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

  • Assignment6-f2aqqh.zip