Problem 1: Write a program that asks user for their input of number of elements to be sorted and then uses bubbleSort to sort them. BuubleSort is a sorting algorithm (Must have been taught in CPSC...

Income tax


Problem 1: Write a program that asks user for their input of number of elements to be sorted and then uses bubbleSort to sort them. BuubleSort is a sorting algorithm (Must have been taught in CPSC 1150). An ArrayList must be used to solve this question. Must use the template given below. [10 Marks] //Use Appropriate imports here. [1 Mark] public class bubbleSortArrayList { public static void main(String[] args) { ArrayList items = new ArrayList<>(); Scanner inp = new Scanner(System.in); //Ask the user for how many elements to be added. System.out.println("Enter the number of elements to be added"); int HowManyElements = inp.nextInt(); //Complete the for loop for adding the elements to the ArrayList. [3 Marks] for (int i = 1 ; i <=; i++){="" }="" print="" out="" the="" original="" arraylist="" after="" user="" input="" here.="" [1="" mark]="" *="" call="" the="" non-static="" bubblesort="" method="" using="" the="" instantiated="" object="" ‘list’="" of="" the="" class="" it="" is="" defined="" [1="" mark]="" */="" list.bubblesort(items);="" }="" *complete="" the="" bubblesort="" algorithm="" as="" per="" the="" arraylist="" usage="" and="" methods.="" remember,="" the="" way="" to="" access="" the="" index="" elements="" is="" different="" in="" arraylists="" than="" in="" arrays.="" [3="" marks]*/="" public="" void="" bubblesort="" (){="" for="" (){="" for="" (int="" i="0;" i="">< j="" ;="" i++){="" if(){="" int="" temp=";" ;="" ;="" }="" }="" }="" print="" out="" the="" sorted="" arraylist="" here.="" [1="" mark]="" }="" }="" }="" problem="" 2:="" write="" a="" program="" that="" finds="" out="" the="" area="" of="" a="" triangle="" using="" heron’s="" formula.="" the="" code="" template="" below="" uses="" the="" principles="" of="" inheritance="" to="" find="" out="" the="" area="" in="" a="" hierarchical="" manner.="" first="" read="" the="" mathematical="" formula="" for="" heron’s="" computation="" of="" area="" of="" the="" triangle,="" then="" code="" it.="" [15="" marks]="" the="" triangle="" has="" 3="" points="" v1,v2="" and="" v3.="" each="" point="" has="" 2="" coordinates="" x,y.="" the="" point="" class="" defines="" the="" coordinates="" (x,y)="" of="" a="" point.="" linesegment="" defines="" the="" length="" of="" the="" 2="" points.="" triangle="" area="" computation="" uses="" 3="" linesegments="" to="" find="" the="" area="" of="" the="" triangle="" using="" heron’s="" formula.="" formula="" for="" length="" of="" a="" line="" segment="" using="" 2="" points="" v1="" and="" v2.="" √(??1="" −="" 2)="" 2="" +="" (??1="" −="" 2)="" 2="" vertex="" v3="" vertex="" v1="" vertex="" v2="" a="" b="" c="" public="" class="" point="" {="" private="" double="" x;="" private="" double="" y;="" code="" the="" default="" and="" constructor="" using="" fields="" for="" point="" class.="" [2="" marks]="" code="" the="" setters="" and="" getters="" for="" the="" point="" class.="" [2="" marks]="" }="" public="" class="" linesegment="" extends="" point="" {="" point="" v1;="" point="" v2;="" public="" double="" length(point="" v1,="" point="" v2){="" *="" here,="" code="" the="" length="" between="" 2="" points="" v1="" &="" v2="" using="" the="" formula="" given="" above="" [3="" marks]*/="" return="" ;="" }="" }="" public="" class="" triangle="" {="" public="" static="" void="" main(string[]="" args)="" {="" *initialize="" the="" points="" v1,="" v2="" and="" v3="" using="" coordinates="" (0,0),="" (3,0)="" and="" (0,4)="" respectively.="" use="" setters="" and="" getters.="" do="" not="" change="" the="" constructors="" defined="" below="" [2="" marks]="" */="" point="" v1="new" point(0,0);="" point="" v2="new" ;="" point="" v3="new" ;="" code="" the="" values="" of="" side="" lengths="" a,="" b="" and="" c="" of="" the="" triangle="" [3="" marks]="" double="" a=";" double="" b=";" double="" c=";" code="" the="" s="" (half="" perimeter)="" of="" the="" triangle="" [1="" mark]="" double="" s=";" code="" the="" area="" of="" the="" triangle="" using="" heron’s="" formula="" [2="" marks]="" double="" area=";" system.out.println(area);="" area="" of="" the="" triangle="" is="" 6="" with="" the="" defined="" points="" (0,0),="" (3,0)="" and="" (0,4).="" }="" }="" problem="" 3:="" in="" this="" exercise="" you="" are="" going="" to="" create="" an="" interface="" called="" lockable.="" the="" lockable="" interface="" should="" be="" used="" by="" classes="" who="" wish="" to="" have="" objects="" that="" may="" enter="" or="" leave="" a="" locked="" state.="" we="" will="" say="" that="" if="" an="" object="" is="" in="" a="" locked="" state,="" then="" certain="" methods="" of="" the="" object="" cannot="" be="" executed.="" for="" example,="" if="" a="" class="" called="" door="" has="" an="" open="" method,="" then="" if="" a="" door="" object="" enters="" the="" locked="" state,="" calling="" door.open()="" would="" not="" succeed.="" we="" would="" have="" to="" unlock="" the="" door="" before="" we="" could="" successfully="" call="" the="" open="" method.="" create="" the="" lockable="" interface="" that="" includes="" the="" following="" methods:="" setkey,="" lock,="" unlock,="" and="" islocked.="" the="" setkey,="" lock,="" and="" unlock="" methods="" take="" an="" integer="" parameter="" that="" represents="" the="" key.="" the="" setkey="" method="" establishes="" the="" key.="" the="" lock="" and="" unlock="" methods="" lock="" and="" unlock="" the="" object,="" but="" only="" if="" the="" key="" passed="" in="" is="" correct.="" the="" islocked="" method="" returns="" a="" boolean="" that="" indicates="" whether="" or="" not="" the="" object="" is="" locked.="" a="" lockable="" object="" represents="" an="" object="" whose="" regular="" methods="" can="" be="" frozen:="" if="" the="" object="" is="" locked,="" the="" methods="" cannot="" be="" invoked;="" if="" it="" is="" unlocked,="" they="" can="" be="" invoked.="" [5="" marks]="" below="" is="" a="" class="" called="" door.="" a="" door="" can="" be="" open="" or="" closed="" and="" has="" methods="" to="" open="" the="" door="" and="" close="" the="" door.="" make="" door="" implement="" the="" lockable="" interface="" and="" provide="" implementations="" for="" the="" abstract="" methods="" of="" lockable.="" initialize="" the="" door="" to="" be="" unlocked="" and="" have="" a="" key="" value="" of="" 0.="" use="" the="" locked="" state="" to="" prevent="" the="" door="" from="" being="" opened.="" [5="" marks]="" public="" class="" door{="" private="" boolean="" isopen;="" public="" door()="" {="" isopen="false;" }="" public="" void="" open()="" {="" isopen="true;" }="" public="" void="" close()="" {="" isopen="false;" }="" public="" boolean="" getstate()="" {="" return="" isopen;="" }="" public="" string="" tostring()="" {="" if(isopen)="" return="" "the="" door="" is="" open";="" else="" return="" "the="" door="" is="" closed";="" }="" here="" is="" the="" account="" class,="" make="" account="" implement="" the="" lockable="" interface.="" when="" an="" account="" becomes="" locked,="" you="" cannot="" make="" deposits="" or="" withdrawals.="" [5="" marks]="" public="" class="" account{="" private="" static="" int="" basenum="100000000;" private="" int="" number;="" private="" double="" balance;="" public="" account()="" {="" this.number="baseNum++;" this.balance="0;" }="" public="" account(double="" balance)="" {="" this.number="baseNum++;" this.balance="balance;" }="" public="" void="" deposit(double="" amount)="" {="" if="" (amount=""> 0) balance += amount; } public void withdraw(double amount) { if (amount > 0 && amount <= balance) balance -= amount; } public int getnumber() { return number; } public double getbalance() { return balance; } problem 4: create an abstract class called geometricfigure. each figure includes a height, a width, a figure type, and an area. include an abstract method to determine the area of the figure. [2 marks] add an interface called sidedobject that contains a method called displaysides(); this method displays the number of sides the object possesses. [2 marks] create two concrete subclasses called square and triangle that extends geometricfigure abstract class and implements the sidedobject interface. [3 marks] create an figuretest class that demonstrates creating objects of both subclasses, and store the objects in an array and display their output for different field variables. [3 marks] balance)="" balance="" -="amount;" }="" public="" int="" getnumber()="" {="" return="" number;="" }="" public="" double="" getbalance()="" {="" return="" balance;="" }="" problem="" 4:="" create="" an="" abstract="" class="" called="" geometricfigure.="" each="" figure="" includes="" a="" height,="" a="" width,="" a="" figure="" type,="" and="" an="" area.="" include="" an="" abstract="" method="" to="" determine="" the="" area="" of="" the="" figure.="" [2="" marks]="" add="" an="" interface="" called="" sidedobject="" that="" contains="" a="" method="" called="" displaysides();="" this="" method="" displays="" the="" number="" of="" sides="" the="" object="" possesses.="" [2="" marks]="" create="" two="" concrete="" subclasses="" called="" square="" and="" triangle="" that="" extends="" geometricfigure="" abstract="" class="" and="" implements="" the="" sidedobject="" interface.="" [3="" marks]="" create="" an="" figuretest="" class="" that="" demonstrates="" creating="" objects="" of="" both="" subclasses,="" and="" store="" the="" objects="" in="" an="" array="" and="" display="" their="" output="" for="" different="" field="" variables.="" [3="">
Jun 13, 2021
SOLUTION.PDF

Get Answer To This Question

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here