CoreJava_Day1Assignments

Share Embed Donate


Short Description

java...

Description

Core Java Assignments Day #1: Java Basics t he assignments, participants will be able to create classes and Objective : At the end of the write programs using objects, arrays, command-line arguments, Strings.

Java - Class, Object and Methods using Conditional statements and Loops

Estimated Estimate d time: .! "our

1. Write Write a program program to to list all even even numbers numbers less than or equal to to the number number n. Tae Tae the value o! n as input !rom user. ". De!ine De!ine a class class ectangle ectangle $ith $ith its length an% brea%th. brea%th. &rovi%e appropriate constructor's() $hich gives !acilty o! constructing rectangle ob*ect $ith %e!ault values o! length p! brea%th as + or passing value o! length an%  brea%th e,ternally to constructor. &rovi%e appropriate accessor - mutator metho%s to ectangle class. &rovi%e metho%s to calculate area - to %isplay all in!ormation o! ectangle. Design %i!!erent class Testectangle Testectangle class in separate source !ile) $hich $ill contain main !unction. rom this main !unction) create / ectangle ob*ects by taing all necessary in!ormation !rom the user. 0. Create Create a class Boo Boo $hich %escri %escribes bes its Booti Bootitle tle an% Boopri Booprice. ce. 2se getter getter an% setter metho%s to get - set the Boos %escription. 3mplement createBoos an% sho$Boos metho%s to create n ob*ects o! Boo in an array. Display the boos along $ith its %escription as !ollo$s:4 !ollo$s:4 Boo Title Java &rogramming 5et 2s C

&rice s.0/+./+ s."++.++

 6ote: createBoos - sho$Boos shoul% not be member !unctions o! Boo class. 7. 8o%i!y 8o%i!y the program program $hich $hich is create% create% in assignme assignment nt " as !ollo$ !ollo$ss The class has attributes length  an% width) each o! $hich %e!aults to 1. 3t shoul% have member !unctions that calculate the perimeter an% area o! the rectangle. 3t shoul% have set an% get !unctions !or both length an% $i%th. The set !unctions

shoul% veri!y that length an% $i%th are each !loating4point numbers larger than +.+ an% less than "+.+ /. Create a class Date !or manipulating %ates. &rovi%e a constructor that enables an ob*ect o! this class to be initiali9e% $hen it is %eclare% 'ou can select any %e!ault values !or the %ay) month - year) e.g. your birth %ate(. &rovi%e the necessary !unctionality to per!orm error checing on the initiali9er values !or %ata members %ay) month) an% year. Also) provi%e a member !unction to a%% an integer in a %ate to obtain a ne$ %ate. Design separate class ;mployee $hich $ill have !ollo$ing in!ormation. ;mployee 6umber

6umber 

;mployee 6ame

Te,t

Joining Date

Date

&rovi%e appropriate constructor's( - metho%s to this class. &rovi%e main !unction $hich $ill create / ob*ects o! ;mployee class.

Estimated time: 1./ tring through Comman% 5ine argument an% %isplay the length o! the string. Also %isplay the string into uppercase an% chec $hether it is a palin%rome or not. 'e!er Java A&3 Documentation( ?. Write a program that accepts t$o numbers !rom the Comman% 5ine an% prints them out. Then use a for loop to print the ne,t 10 numbers in the sequence $here each number is the sum o! the previous t$o. or e,ample: input> java prob2 1 3 output> 1 3 4 7 11 18 29 47 76 123 322 521 843 1364

@. Write a program that accepts t$o numbers in the range !rom 1 to 7+ !rom the Comman% 5ine. 3t then compares these numbers against a single %imension array o! !ive integer elements ranging in value !rom 1 to 7+. The program %isplays the message BINGO i! the t$o inputte% values are !oun% in the array element. or e,ample: input>java prob3 3 29 output>Your first number was 3 Your second number was 29

Its in!o" ## t$is messa!e if 3 and 29 is found in t$e arra% &ot 'ound" ## t$is messa!e if 3 and 29 is not found in t$e ##arra% ($e arra% was 7 25 5 19 3)

. Write a program that allo$s you to create an integer array o! 1@ elements $ith the !ollo$ing values: int A[]={3,2,4,5,6,4,5,7,3,2,3,4,7,1,2,0,0,0}. The program computes the sum o! element + to 17 an% stores it at element 1/) computes the average an% stores it at element 1= an% i%enti!ies the smallest value !rom the array an% stores it at element 1?. 1+. Create a class #erm. This class represents a term o! a polynomial such as " ,7 $here " is coe!!icient an% 7 is e,ponent o! the term. $ata members:int coefficient int e%ponent

Create another class &olynomial . The internal representation o! a polynomial is an array o! Terms. The si9e o! this array shoul% be !i,e%. &rovi%e a constructor !or this class that $ill set all terms o! a polynomial ob*ect as 9ero '$here coe!!icient is + an% e,ponent is +(. &rovi%e !ollo$ing !unctions: setTerm'int) int(  >etting a term o! a polynomial ob*ec t. ;ach successive call o! this !unction shoul% set ne,t term o! the polynomial ob*ec t. 3t shoul% %o the !ollo$ing vali%ations:4 Whether the e,ponent o! the term being set is alrea%y use%. Whether the array si9e limit is e,cee%e%. Whether the e,ponent is negative. In all the cases it should not set the term and display an appropriate message.  

sort() – to arrange the terms in ascending order of exponents.  Provide a function to print a polynomial object

Passing objects to methods Estimated time: 1
View more...

Comments

Copyright ©2017 KUPDF Inc.
SUPPORT KUPDF