Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I need help with this java assignment program a classCompare3that provides a static method calledlargest. Methodlargestshould take threeComparableparameters and return the largest of the three

I need help with this java assignment

  1. program a classCompare3that provides a static method calledlargest. Methodlargestshould take threeComparableparameters and return the largest of the three (so its return type will also beComparable). Recall that methodcompareTois part of theComparableinterface, solargestcan use thecompareTomethod of its parameters to compare them.
  2. The method header for largest will look like this:public static Comparable largest(Comparable first, Comparable second, Comparable third)

You will get a compiler note as shown below. This is expected and acceptable at this time. The correct way to code this uses generics which are introduced in chapter 12.

Note: Compare3.java uses unchecked or unsafe operations.

Note: Recompile with -Xlint:unchecked for details.

  1. program a classComparisonswhose main method tests yourlargestmethod above.
  • First prompt the user for and read in three strings, use your largest method to find the largest of the three strings, and print it out. (It's easiest to put the call tolargestdirectly in the call toprintln.) Note that sincelargestis a static method, you will call it through its class name, e.g.,Compare3.largest(val1, val2, val3).
  • Add code to also prompt the user for three integers and try to use your largest method to find the largest of the three integers. Does this work? If it does, it's thanks to autoboxing, which is Java 1.5's automatic conversion ofints toIntegers
  1. You will have 2 class files to submit
  2. You will get a compiler note as shown below. This is expected and acceptable at this time. The correct way to code this uses generics which are introduced in chapter 12

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

Introduction to Wireless and Mobile Systems

Authors: Dharma P. Agrawal, Qing An Zeng

4th edition

1305087135, 978-1305087132, 9781305259621, 1305259629, 9781305537910 , 978-130508713

More Books

Students also viewed these Programming questions