0% found this document useful (0 votes)
51 views

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

This document contains an assignment for an Object Oriented Programming course. It instructs students to rewrite a Java calculator program using object-oriented principles. The original program uses a switch statement to perform basic math operations. Students are asked to create separate classes for input validation, each mathematical operation, and output. They must refactor the code to satisfy input and output validation requirements. The assignment is for Semester Fall 2020 and is worth 4 credit hours.
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
51 views

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

This document contains an assignment for an Object Oriented Programming course. It instructs students to rewrite a Java calculator program using object-oriented principles. The original program uses a switch statement to perform basic math operations. Students are asked to create separate classes for input validation, each mathematical operation, and output. They must refactor the code to satisfy input and output validation requirements. The assignment is for Semester Fall 2020 and is worth 4 credit hours.
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 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