======== MyInteger.java ========
public class MyInteger {
// Declaring instance variables
private int value;
// Parameterized constructor
public MyInteger(int value) {
this.value = value;
}
// Getter method
public int getValue() {
return value;
}
/*
* This method will check whether the number is even or
not if even returns
* true else return false
*/
public boolean isEven() {
if (value % 2 == 0)
return
true;
else
return
false;
}
/*
* This method will check whether the number is odd or
not if odd returns
* true else return false
*/
public boolean isOdd() {
if (value % 2 != 0)
return
true;
else
return
false;
}
/*
* This method will check whether the number is prime
or not if prime
* returns true else return false
*/
public boolean isPrime() {
// If the user entered number is
'2' return true
if (value == 2)
return
true;
for (int i = 2; i * i <= value;
i++) {
if (value % i ==
0)
return false;
}
return true;
}
/*
* This method will check whether the number is even or
not if even returns
* true else return false
*/
public static boolean isEven(int val) {
if (val % 2 == 0)
return
true;
else
return
false;
}
/*
* This method will check whether the number is odd or
not if odd returns
* true else return false
*/
public static boolean isOdd(int val) {
if (val % 2 != 0)
return
true;
else
return
false;
}
/*
* This method will check whether the number is prime
or not if prime
* returns true else return false
*/
public static boolean isPrime(int val) {
// If the user entered number is
'2' return true
if (val == 2)
return
true;
for (int i = 2; i * i <= val;
i++) {
if (val % i ==
0)
return false;
}
return true;
}
/*
* This method will check whether the number is even or
not if even returns
* true else return false
*/
public static boolean isEven(MyInteger mi) {
if (mi.getValue() % 2 == 0)
return
true;
else
return
false;
}
/*
* This method will check whether the number is odd or
not if odd returns
* true else return false
*/
public static boolean isOdd(MyInteger mi) {
if (mi.getValue() % 2 != 0)
return
true;
else
return
false;
}
/*
* This method will check whether the number is prime
or not if prime
* returns true else return false
*/
public static boolean isPrime(MyInteger mi) {
// If the user entered number is
'2' return true
if (mi.getValue() == 2)
return
true;
for (int i = 2; i * i <=
mi.getValue(); i++) {
if
(mi.getValue() % i == 0)
return false;
}
return true;
}
// This method will whether the two numbers are
equal are not
public boolean equals(int val) {
if (this.value == val)
return
true;
else
return
false;
}
// This method will whether the two numbers are
equal are not
public boolean equals(MyInteger mi) {
if (this.value ==
mi.getValue())
return
true;
else
return
false;
}
public static int parseInt(char[] ch) {
return
Integer.parseInt(String.valueOf(ch));
}
public static int parseInt(String str) {
return Integer.parseInt(str);
}
}
==========================================
======== Exercise.java ========
public class Exercise
{
public static void main(String[] args)
{
MyInteger n1 = new MyInteger(5);
System.out.println("n1 is even? " + n1.isEven());
System.out.println("n1 is prime? " + n1.isPrime());
System.out.println("15 is prime? " + MyInteger.isPrime(15));
char[] chars = { '3', '5', '3', '9' };
System.out.println(MyInteger.parseInt(chars));
String s =
"3539";
System.out.println(MyInteger.parseInt(s));
MyInteger n2 = new MyInteger(24);
System.out.println("n2 is odd? " + n2.isOdd());
System.out.println("45 is odd? " + MyInteger.isOdd(45));
System.out.println("n1 is equal to n2? " + n1.equals(n2));
System.out.println("n1 is equal to 5? " + n1.equals(5));
}
}
==========================================
==========================================
Output:
=====================Could you plz rate me well.Thank
You
. Design a class named MyInteger. The class contains: An int data field named value that...
Once your UML diagram is complete implement the class naming the Java file MyInteger.java. Create another Java file, a program named MyIntegerTester.java that tests all methods in the class. One technique is to write both classes at the same time. As much as possible you implement and test one method at a time. This minimized the amount of new code you have to look at when debugging a method. Only the Version 4.0 “tester” file will have main() method in...
(The Account class) Design a class named Account that contains: A private int data field named id for the account (default 0). A private double data field named balance for the account (default 0). A private double data field named annualInterestRate that stores the current interest rate (default 0). Assume all accounts have the same interest rate. A private Date data field named dateCreated that stores the date when the account was created. A no-arg constructor that creates a default...
PYTHON PROGRAMMING LANGUAGE Design a class named Savings Account that contains: A private int data field named id for the savings account. A private float data field named balance for the savings account. A private float data field named annuallnterestRate that stores the current interest rate. A_init_ that creates an account with the specified id (default 0), initial balance (default 100), and annual interest rate (default 0). . The accessor and mutator methods for id, balance, and annuallnterestRate. A method...
9.7 (The Account class) Design a class named Account that contains: • A private int data field named id for the account (default o). • A private double data field named balance for the account (default o). • A private double data field named annualInterestRate that stores the current interest rate (default o). Assume that all accounts have the same interest rate. • A private Date data field named dateCreated that stores the date when the account was created. •...
Design a class named Account that contains: A private int datafield named id(default 0) A private double datafield named balance(default 0) A no-arg constructor that creates default account A constructor that creates an account with specified id & balance The getter and setter methods for id and balance. Create an object of account class using default constructor and update the balance to 2000$ .
Design a class named BankAccount that contains: 1. A private int data field named accountId for the account. 2. A private double data field named accountBalance for the account (default 0). 3. A private double data field named annualInterestRate that stores the current interest rate (default 0). Assume all accounts have the same interest rate. 4. A private Date data field named dateCreated that stores the date when the account was created. 5. A private int data field named numberOfDeposits...
Write a class named Month. The class should have an int field named monthNumber that holds the number of the month. For example. January would be 1. February would be 2. and so forth. In addition, provide the following methods A no-arg constructor that sets the monthNumber field to 1 A constructor that accepts the number of the month as an argument. It should set the monthNumber field to the value passed as the argument. If a value less than...
In Python - Design a class named Time. The class contains: -Data fields hour, minute, and second that represent a time. -A no-arg constructor that creates a Time object for the current time.(the values of the data fields will respresent the current time.) -A constructor that constructs a Time object with a specified hour, minute, and second, respectively. -A constructor that constructs a Time object with a specified elapsed time since midnight, Jan 1, 1970, in milliseconds. (The values of...
Part I: (The Myate class) Design a class named MyDate. The class contains: • The data fields year, month, and day that represent a date. Month is 0-based, i.e., 0 is for January. • A no-arg constructor that creates a MyDate object for the current date. • A constructor that constructs a MyDate object with a specified elapsed time since midnight, January 1, 1970, in milliseconds. • A constructor hat constructs a MyDate object with the specified year, month, and...
QUESTION 5 (15 Marks) Inheritance and Polymorphism Design a Ship class that has the following members: • A private String data field named name for the name of the ship. • A private String data field named yearBuilt for the year that the ship was built. • A constructor that creates a ship with the specified name and the specified year that the ship was built. • Appropriate getter and setter methods. A toString method that overrides the toString method...