Lab01 ITE1219E

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 2

LAB 01: DESIGN CLASS AND WRITE METHODS.

Introduction
Let’s start this semester on the right foot by making sure that we didn’t forget
everything from last semesters. This will be difficult for some of you. This does not
constitute a failure on your part, we’re just trying to get a feel for where everybody
stands on basic java. Good luck!
Your Task
Design and Implement the Class that represents the two number A and B (with A,
B is Integer) with some Operators: Plus, Minus, Multiply, Divide, Modulus two
numbers. Write the main method to test the Class above.
1. Design one class (Concrete) with public properties and write constructor method.

Operators

Main

2. Design one class (Concrete) with private properties and write set, get, and
constructor methods.

Operators

Main

3. Design three classes (Interface, Abstract, and Concrete Class) with private
properties and write set, get, and constructor methods.

Interface

Abstract

Operators

Main 1
Hints
• Design the Classes consisting of Properties and Methods.
• Figure out the algorithm before you start coding.
• See two Examples to know the input number and string from keyboard and print it
out to the screen.
Turn In
Put all files of project in a Folder (One Project in one Directory) and all Projects to
your private folder called Name_ID_Lab01 then Zip it, and submit it to LMS. Failure
to follow this naming convention will result in lost points.
Examples:
1. Input Two Numbers From Keyboard then to Add them.
import java.util.Scanner; // Import the Scanner class
class MyClass {
public static void main(String[] args) {
int x, y, sum;
Scanner myObj = new Scanner(System.in); // Create a Scanner object
System.out.println("Type a number:");
x = myObj.nextInt(); // Read user input
System.out.println("Type another number:");
y = myObj.nextInt(); // Read user input
sum = x + y; // Calculate the sum of x + y
System.out.println("Sum is: " + sum); // Print the sum
}
}

2. Enter Username From Keyboard then print out to the screen.


import java.util.Scanner; // Import the Scanner class
class Main {
public static void main(String[] args) {
Scanner myObj = new Scanner(System.in); // Create a Scanner object
System.out.println("Enter username");
String userName = myObj.nextLine(); // Read user input
System.out.println("Username is: " + userName); // Output user input
}
}

You might also like