Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Yanbu University College BACHELOR OF SCIENCE IN Applied Computer Science (ACS) ami Introduction to Computer Science (CS102) Second Semester - Academic Year 2012 - 2013

image text in transcribed
image text in transcribed
image text in transcribed
Yanbu University College BACHELOR OF SCIENCE IN Applied Computer Science (ACS) ami Introduction to Computer Science (CS102) Second Semester - Academic Year 2012 - 2013 Lab Exercise - 4 urse Instructors: Mohammed Rafi / Rasheed Ricardo 1. Define a class of student, the student have name, roll number, address and Phone Number. Al attributes are public in access. Create an object of Student Student1" with default values Print the all information of Student1 Output: D:\sem122\cs102 \uprog\ClassPPTPrograms>java studentApp student Name = null student Id = 0 student Address = null Student Phone Number = 0 2. Rewrite your Lab exercises and initialize the fields of class student with the values given below. name Your name, rollNumber your id, address Your address, phoneNumber Your phone number Write a test application named Student Test and create student object. Print all information about student1 then ask from a user that he want to changes the values of object attributes if user gives yes (O means yes) take input for all attributes and print the new values of attributes. Output: pa sen122 CS102 Prog\ClassPPTPrograms>java student2App Student Name = Ahmed Student Id = 100 Student Address = Yanbu Phone Number = 1000 You want to change the values / :: Y Enter student name :: Mohamed Enter student id :: 20101 Enter student address :: YUC Enter student phone number :: 1234444 student Name = Mohammed Student Id - 20101 student Address = YUC Phone Number = 1234444 You want to change the values (Y/N) :: 3. Create a class called Employee that includes three pieces of information as instance variables a first name (type String), a last name (type String) and a monthly salary (double). Initializes the three instance variables with some values. Write a check salary method which checks the monthly salary if the monthly salary is not positive, set it to 0:0 Write a test application named Employee Test that demonstrates class Employee's capabilities Create two Employee objects and display each object's yearty salary and give each Employee a 10% raise and display each Employee's yearly salary again. Output: :\em122\C5102\JProg\classPPTprograms>java Employee Test Employee 1: Mohammed Ali: Yearly salary: 34500.00 Employee 2: Ahmed Mohammed: Yearly salary: 37809.00 Employee 3: Rasheed Mohammed; Yearly salary: 0.00 Increasing employee salaries by 10% Employee 1: Mohammed Ali; Yearly salary: 37950.00 Employee 2: Ahmed Mohammed: Yearly, Salary: 41589.90 Employee 3: Rasheed Mohanned: Yearly salary: 0.00 4. Create a class called Date that includes the pieces of information as instance variables month (type int), a day type ind) and a your type in initializes the three instance variables and assumes that the values provided are correct. Provide a set and a get method for each instance variable Provide a method isplayDute that displays the month day and year separated by Write a test application named Date Test that demonstrates class Date's Output: D:\Sem122\cs102\JProg\classPPT Programs>java Datete Enter day : 23 Enter month :: 11 Enter Year :: 1978 pate = 23/11/1978 2:\sem122\cs102 \JProg\classPPTPrograms>java Datete Enter day : 35 Enter month :: 18 Enter Year :: 1900 Invalid day Invalid month Date = 1/1/1900 5. Create a class named Account that includes one instance variable-balance (Type double) Provide a constructor that Initializes the balance, if the balance is less than 0.0 make the balance The credit method receives one parameter amount (Type double that will add to the balance The getBalance method returns balance of a particular Account's object's balance Write a test application named Account Test that demonstrates class Account's capabilities Create two Account objects and display the balance in each Account Output: D:\sem122\C$102\Prog\ClassPPTPrograms>java Account App Accounti balance = 120.00 Account balance = 0.00 Enter deposit amount for accounti: 567 Adding 567.00 to account balance Accounti Balance : 687.00 Enter deposit amount for account2: 89 Adding 89.00 to account balance Account2 Balance : 89.00 6 Modily class Account to provide a method called debit that withdraw money from an account Ensure that the debit amount does not exceed the Account's balance. If it does the balance should be left unchanged and the method should peint a message indicating "Debit amount exceeded account balance Modity class Account Test to test method debit Output: D:\sem122\C5102\3Prog\ClassPPT Programs>java Account App accountl balance: SR 150.00 account balance: SR0.00 Enter withdrawal amount for accounti: 34 Subtracting SR34.00 from accounti balanc accountl balance: SR116.00 Enter withdrawal amount for account2: 89 subtracting SR89.00 from account? balance Debit amount exceeded account balance. account2 balance: SR0.00 7. Write a program to calculate the area and circumference of a circle by writing Classide and provide set and get methods to the instance variate Create object for the Cide. Output: D:\Sem122\CS102Prog\ClassPPTPrograms>java circleApp 226.08 is the area of circle 17.68 is the circumference of circle

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Intelligent Information And Database Systems Asian Conference Aciids 2012 Kaohsiung Taiwan March 19 21 2012 Proceedings Part 3 Lnai 7198

Authors: Jeng-Shyang Pan ,Shyi-Ming Chen ,Ngoc-Thanh Nguyen

2012th Edition

3642284922, 978-3642284922

More Books

Students also viewed these Databases questions