Assignment 1 - Semester Fall 2020: COMSATS University Islamabad, Lahore Campus Department of Electrical Engineering

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 1

COMSATS University Islamabad, Lahore Campus

Department of Electrical Engineering

Assignment 1 – Semester Fall 2020


Course Title: Object Oriented Programing Course Code: CSC241 Credit 4(3,1)
Hours:
Course Instructor/s: Tahir Muhammad Programme BEE, BCE, BTE
Name:
Semester: Batch: Section: Date
Student’s Name: Reg. No. FA19-BEE-
Important Instructions / Guidelines:
 Use front page and submit it in on Turnitin.com form.
 Do not copy code from internet else you will be awarded with a zero.

Q1: Rewrite the given code into object-oriented java code. Estimate mathematical operations and write a
separate class method for each operation. Extend your code by adding a separate function for user input.
Make sure that program satisfies input and output validations. [CLO 1, PLO1 C2]

public static void main(String[] args) {


System.out.println(" Welcome to Java Calculator v0.1 \n");
Scanner scanner = new Scanner(System.in);

System.out.println("\n Please enter two numbers");


System.out.print("\n First number: ");
int firstNumber = scanner.nextInt();
System.out.print("\n Second number: ");
int secondNumber = scanner.nextInt();
System.out.println("\n Select between (*,/,+,-)\n Type out the character in a single letter: ");
String operation = scanner.next();
String eo = "You have selected ";

switch (operation) {
case "*":
System.out.println(eo + "* \n Your Result: "+ ( firstNumber * secondNumber ));
break;
case "/":
System.out.println(eo +"/ \n Your Result: "+ ( firstNumber / secondNumber ));
break;
case "+":
System.out.println(eo + "+ \n Your Result: "+ ( firstNumber + secondNumber ));
break;
case "-":
System.out.println(eo + "- \n Your Result: "+ ( firstNumber - secondNumber ));
break;
default: System.out.println("\n Please select a valid character");
}
scanner.close();
System.out.println(" Closing Application ");
}

Page 1 of 1

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy