Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Can someone please help me with part 2 for this assignment? Part 2. Enhance your JavaAccount.java class to implement a Measurable2.java interface. public interface Measurable2

Can someone please help me with part 2 for this assignment?

Part 2. Enhance your JavaAccount.java class to implement a Measurable2.java interface.

 public interface Measurable2 { double getMinMeasure1(); int getMaxMeasure2(); } 

First add the implementation of the interface to your JavaAccount.java and submit that java file. Then in the main() method of the JavaAccount.java add the followings:

Create an account object aliAccount and assigned it to the JavaAccount type

Create an account object bobAccount and assigned it to the Measuable2 type

Check if you can invoke aliAccount.getBalance() and aliAccount.getMeasure1() as well as .getMeasure2()

Check if you can invoke bobAccount.getBalance() and bobAccount.getMeasure1() as well as .getMeasure2(), find a way to access the getBalance() method from the bobAccount

Here is part 1 and what had been done

import java.util.Calendar; import java.util.Date; import java.util.Scanner;

/** * * @author pc */ public class TestCalendar { public static void findDayOfWeek(Calendar c) { int y1,y,m,d; d=c.get(Calendar.DATE);//find the date m=c.get(Calendar.MONTH);//find the month from calendar y1=c.get(Calendar.YEAR);//find the year y=y1;//y=y1 int t[] = { 0, 3, 2, 5, 0, 3, 5, 1, 4, 6, 2, 4 };//shifting days //The below statement creates a "virtual year" that starts on March 1 and ends on February 28 or 29, //putting the extra day (if any) at the end of the previous year. y -= m < 3? m:0; //we have 365 days in a normal year that means 52 weeks + 1 day , it shifts day of the week by one every year //But we know that every four year we have leap year which contributes to adding extra day //so we add the y/4 but every y/100 is not a leap year so decrease it but y/400 is leap year again so add it int day= ( y + y/4 - y/100 + y/400 + t[m] + d) % 7;//it returns the value 0-6 so 0 stands for sunday and 6 for saturday System.out.print("The day of the week for date "+d+"/"+(m+1)+"/"+y1+" - "); switch(day) { case 0: System.out.println("Sunday"); break; case 1: System.out.println("Monday"); break; case 2: System.out.println("Tuesday"); break; case 3: System.out.println("Wednesday"); break; case 4: System.out.println("Thursday"); break; case 5: System.out.println("Friday"); break; case 6: System.out.println("Saturday"); break; } } public static void findNextLeapYear(int year) { int d=year+1;//start checking for next leap year from year next to this one(current) while(true)//check until you find one date which is leap year { if(d%4==0)//if the year is divisible by 4 and not divisible by 100 then it is leap year { if(d%100!=0) { break;//if the control comes here that means d is leap year so break out of the loop } else{ if(d%400==0)//if it is divisible by 100 and also divisible by 400 then its a leap year break;//break out of the loop } } d++;//if we are still in the loop that means we havent found any leap year so increase d by 1 } System.out.println("Next Leap year after this year is : "+d);//print next leap year } public static void findDaysLeftUntilGraduation(Calendar c) { //find the todays date Calendar cNow=Calendar.getInstance(); Date d1=cNow.getTime();//call getTime() of calendar object ,it returns date object Date d2=c.getTime(); // getTime() method of the date object returns the number of milliseconds since jan 1 1970 //so find the difference between two of the miliseconds and then convert milliseconds into days //milliseconds(divide by 1000) -> second //second/60 -> minute //minute/60 ->hour //hour/24 ->day //so 24*60*60*1000 = 86400000 so divide the number by this to get the days long difference = (d2.getTime()-d1.getTime())/86400000; System.out.println("Days left - "+difference);//print days } public static void main(String[] args) { //get the calendar instance (calendar class is abstract so you cant instantiate it by using new //rather use its static method getInstance() to get its instance Calendar c=Calendar.getInstance(); c.set(1970,0,1);//set the date month starts from 0 so pass january as 0 findDayOfWeek(c);//find day of th eweek //find the next leap year c=Calendar.getInstance();//get the instance initialy it will contain the current date(todays date) findNextLeapYear(c.get(Calendar.YEAR));//find the next leap year after the current date //find the days left until the graduation date System.out.println("Please enter the graduation date -- "); //take the input for graduation date Scanner sc=new Scanner(System.in); System.out.println("Enter date");//take graduation date int grDate=sc.nextInt(); System.out.println("Enter month");//take graduation month int grMonth=sc.nextInt(); System.out.println("Enter Year");//take graduation year int grYear=sc.nextInt(); c.set(grYear,grMonth-1, grDate);//take month in a format such that 0 represents jan and so on (11 dec) findDaysLeftUntilGraduation(c);//find date left } }

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access with AI-Powered 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

Students also viewed these Databases questions