Question
In Java Language Task #1 part 1: Student will write two classes: Rectangle.java and RectangeTester.java The Rectangle should have two private instance variables length, and
In Java Language
Task #1
part 1:
Student will write two classes: Rectangle.java and RectangeTester.java
The Rectangle should have two private instance variables length, and width.
We will be using the default constructor so you will not be including a constructor in your code. We will be writing 6 methods in the Rectangle class,
setLength(), setWidth(), getLenth(), getWidth(), getArea(), and getPerimeter(). Some of these methods are mutator methods and some are accessor methods.
You will need to decide whether these methods are void or return a value. You will also need to make a decision on the parameters needed.
In the RectangleTester class first instantiate one object called box1. Populate the length and width variable using the appropriate methods.
Caluculate Area1 in the main method using the getLength() and getWidth() methods and print it out.
Calculate Area2 in the main method using the getArea() method and print it out.
Part 2:
add an overloaded constructor that initializes the length and width to any given values. You will now need to add a default constructor that initializes the length and width variables to 0.
add a printDimensions method that prints the dimensions, length and width of the rectangle.
Task #2
Students will write 2 classes : CashRegister.java and CashRegisterTester.java
a cashRegister should have 3 instance variables:-itemCountthat represents the numbers of items bought,
totalPricethat represents the total price of all your items, and itemNames that represents a concatenated string of the names
of all the products you bought.
The CashRegister should also have 5 methods, addItem, getCount, getTotal, getProducts, clear.
Instantiate a CashRegister object in the CashRegisterTester class called reg1. Add three items
cereal 3.50
milk 2.99
spoons 2.00
and invoke all the other methods to print the final results (tally, total, and name of products)
Task #3
Students will write 3 classes: BankAccount.java, BankAcountTester.java and Financial.java
the BankAccount class should have the following components:
3 instance variables : balance, accName, accNum
1 static variable : lastAccNum = 0
2 constructors
7 methods: setValue, setName, deposit, withdraw, checkBalance, Transfer, output
an 8th method called addInterest that will invoke the static method percentOf from the Financial class
Create 3 objects acc1, acc2, acc3 use the default constructor for acc1 and the second constructor for acc2 (100, "Adam") and acc3(200, "Anna")
you are free to test your code and use the methods on any ojbects
call the output method at the very end on each object.
Task #4 Inheritance
Students will write 4 classes to (Animal, Dog, Puppy, and InheritanceTester ) to apply the inheritance relationship.
- Animal should be the superclass, it should contain at least one behavior. (example eat)
- Dog is a subclass of Animal, it should contain at least one behavior. (example bark)
- Puppy is a sub-class of Dog, it should contain at least one behavior. (example cry)
- inheritanceTester houses the main method. You will need to instantiate two objects,
one of type Dog and one of type Puppy.
Invoke the different methods in the classes with these objects.
(Hint, you may include all the classes in one file, but you must only make one public, and that will
be the class that you name the file after)
Task #5
Students will write a program that takes input from a file, processes the data, and outputs to another file.
Create an input file using notepad and populate it with 5 numbers (each on a separate line).
Store this file in your new project one level above the src folder.
Write a program that reads the 5 numbers from the file and finds their total.
Output the numbers and their total to an output file and to the console.
Task #6
Declare an array of Strings, called cd, with a size of 6.
Fill the array by creating a new song with the title and artist and storing it in the appropriate position in the array. You need to read this information from the text file that is provided. You will need to read the title and the artist and merge them together before storing them into the array. You will need to merge the word by in between the two strings.
- Print the contents of the array to the console.
- output should be as follows:
Contents of Compact Disc
========================
Ode to Joy by Bach
The Sleeping Beauty by Tchaikovsky
Lullaby by Brahms
Canon by Bach
Symphony No. 5 by Beethoven
The Blue Danube Waltz by Strauss
Part two: incorporate a try/catch block in your code to catch your exception.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started