CSci 169 Programming HW 4 solution

$24.99

Original Work ?

Download Details:

  • Name: HW4-1.zip
  • Type: zip
  • Size: 303.00 KB

Category: You will Instantly receive a download link upon Payment||Click Original Work Button for Custom work

Description

5/5 - (1 vote)

1. (5 points) Translate this C++ program to Java (Quicksort):
https://math.scu.edu/~linnell/cs169s19/hw/hw2/main.cpp
To make a Java program in Eclipse, make sure Java is selected in the upper right, then make a new
Java project. Right-click on the src folder in the left panel, and create a new class. You should be
ready to start programming
2. (10 points) In this problem, you will explore inheritance. Implement the classes Food, Fruit,
Orange, Apple, Seafood, Shrimp, and Prawn as represented in the class diagram here:
https://math.scu.edu/~linnell/169resources/classDiag.pdf
That is, Fruit inherits from Food, Orange inherits from Fruit, etc.
The first area in a class’s box is its name, the second is its member data fields and their types, and
the third is its member methods. So you can tell what the methods should do, I’ve included the
following main function and its output. Note that the name of any object of type Apple should be
“apple”, etc.
import java.util.Date;
class MainClass
{
public static void main(String args[])
{
Date d = new Date(2000000000);
Food gum = new Food(“gum”);
Food las = new Food(“lasagna”);
Fruit pom = new Fruit(d, “pomegranate”);
Fruit app = new Apple(d);
Orange o = new Orange(d);
Shrimp sh = new Shrimp();
Seafood p = new Prawn();
Seafood l = new Seafood(“lobster”);

sh.prepare();
app.prepare();
pom.prepare();
o.prepare();
gum.prepare();
p.prepare();
l.prepare();
las.prepare();
las = app;
las.prepare();

o.ripeTime();
pom.ripeTime();
}
}
Peel the shrimp
Core the apple
Prepare the pomegranate
Peel the orange
Prepare the gum
Peel the prawn
Peel the lobster
Prepare the lasagna
Core the apple
You can eat it on Fri Jan 23 19:33:20 PST 1970
You can eat it on Fri Jan 23 19:33:20 PST 1970
3. (5 points) We started on a BinarySearch Class in class on Monday (Code is linked from Monday’s
link on the webpage). In this problem you will make it “more” object-oriented in the following ways:
-You will change its name to SortedList
-You will make a constructor that takes no arguments to be more traditional and initialize the
member fields to dummy values.
-You will add a constructor that takes in an initialized array and a size
-You will add an insert function that adds a value to the list and maintains its sorted-ness
-You will add a quicksort function (feel free to use what you wrote #1).
-You will make updates as necessary to the main function so that it still runs and tests your code.
Submission instructions: You will print out your code for each problem, stapling together
multiple sheets (there will be deductions for unstapled homework!). Turn in the hardcopy at the
beginning of class. You will ALSO submit all of your .java files as attachments, to
cs169@math.scu.edu (NOT Dr. Linnell’s email!!)
The subject line of the email should be “CS169 HW4 YourLastName YourIDNumber “