04 Mar Click here to submit your solution to Lab A
Click here to submit your solution to Lab Assignment 7.Submit copies of any Java source code files you create or modify, specifically:
- Time.java
- TimeDemo.java
- Task 2 Java program
Use two sets of data to demonstrate successful execution of Task 1:
- Use the six valid military time values given as part of Task #1 as one set and then
- use the six invalid military time values given as part of Task #1 as the second set.
These values can be found in step 5 of Task 1.Don't forget to also complete and submit your successful solution to Task 2.
You will need these files to successfully complete Lab Assignment 7:
- Time.java, Class definition for the Time class.
- TimeDemo.java, "Driver" program for time processing.
- secret.txt, Secret message file.
import java.util.Scanner; /** This program demonstrates the Time class. */ public class TimeDemo { public static void main(String[] args) { Scanner keyboard = new Scanner(System.in); char answer = 'Y'; String enteredTime; String response; while (//CHECK ANSWER AFTER CONVERTING TO CAPITAL) { System.out.print("Enter a military time " + "using the ##:## format: "); enteredTime = keyboard.nextLine(); Time now = new Time (enteredTime); System.out.println("Do you want to enter " + "another (Y/N)? "); response = keyboard.nextLine(); answer = response.charAt(0); } } }
,
January is the first month and december is the last. Violet is a purple color as are lilac and plum.
,
/** Represents time in hours and minutes using the customary conventions. */ public class Time { private int hours; // Conventional hours private int minutes; // Conventional minutes private boolean afternoon; // Flag for afternoon /** Constructs a cutomary time (12 hours, am or pm) from a military time ##:## @param militaryTime Time in the military format ##:## */ public Time(String militaryTime) { // Check to make sure something was entered if (militaryTime == null) { System.out.println(militaryTime + " is not a " + "valid miliary time." ); } // Check to make sure there are 5 characters else if (// CONDITION TO CHECK LENGTH OF STRING) { System.out.println(militaryTime + " is not a " + "valid miliary time." ); } else { // Check to make sure the colon is in // the correct spot if (//CONDITION TO CHECK COLON POSITION) { System.out.println(militaryTime + " is not a " + "valid miliary time." ); } // Check to make sure all other characters // are digits else if (// CONDITION TO CHECK FOR DIGIT) { System.out.println(militaryTime + " is not a " + "valid miliary time." ); } else if (// CONDITION TO CHECK FOR DIGIT) { System.out.println(militaryTime + " is not a " + "valid miliary time." ); } else if (//CONDITION TO CHECK FOR DIGIT) { System.out.println(militaryTime + " is not a " + "valid miliary time." ); } else if (//CONDITION TO CHECK FOR DIGIT) { System.out.println(militaryTime + " is not a " + "valid miliary time." ); } else { // SEPARATE THE STRING INTO THE HOURS // AND THE MINUTES, CONVERTING THEM TO // INTEGERS AND STORING INTO THE // INSTANCE VARIABLES // Validate hours and minutes are valid values if(hours > 23) { System.out.println(militaryTime + " is not a " + "valid miliary time." ); } else if(minutes > 59) { System.out.println(militaryTime + " is not a " + "valid miliary time." ); } // Convert military time to conventional time // for afternoon times else if (hours > 12) { hours = hours – 12; afternoon = true; System.out.println(this.toString()); } // Account for midnight else if (hours == 0) { hours = 12; System.out.println(this.toString()); } // Account for noon else if (hours == 12) { afternoon = true; System.out.println(this.toString()); } // Morning times do not need converting else { System.out.println(this.toString()); } } } } /** The toString method returns a conventional time. @return A conventional time with am or pm. */ public String toString() { String am_pm; String zero = ""; if (afternoon) am_pm = "PM"; else am_pm = "AM"; if (minutes < 10) zero = "0"; return hours + ":" + zero + minutes + " " + am_pm; } }
Our website has a team of professional writers who can help you write any of your homework. They will write your papers from scratch. We also have a team of editors just to make sure all papers are of HIGH QUALITY & PLAGIARISM FREE. To make an Order you only need to click Ask A Question and we will direct you to our Order Page at WriteEdu. Then fill Our Order Form with all your assignment instructions. Select your deadline and pay for your paper. You will get it few hours before your set deadline.
Fill in all the assignment paper details that are required in the order form with the standard information being the page count, deadline, academic level and type of paper. It is advisable to have this information at hand so that you can quickly fill in the necessary information needed in the form for the essay writer to be immediately assigned to your writing project. Make payment for the custom essay order to enable us to assign a suitable writer to your order. Payments are made through Paypal on a secured billing page. Finally, sit back and relax.
Do you need help with this question?
Get assignment help from WriteEdu.com Paper Writing Website and forget about your problems.
WriteEdu provides custom & cheap essay writing 100% original, plagiarism free essays, assignments & dissertations.
With an exceptional team of professional academic experts in a wide range of subjects, we can guarantee you an unrivaled quality of custom-written papers.
Chat with us today! We are always waiting to answer all your questions.