#368 Create a new project and call this project
Create a new project and call this project - Computer Science
ChemistryExplain daily providing Q&A content “#368 Create a new project and call this project" in Computer science, Ba computer science, Berkeley computer science, Computer science associate degree jobs
Get the Free Online Chemistry Q&A Questions And Answers with explain. To crack any examinations and Interview tests these Chemistry Questions And Answers are very useful. Here we have uploaded the Free Online Chemistry Questions. Here we are also given the all chemistry topic.
ChemistryExplain team has covered all Topics related to inorganic, organic, physical chemistry, and others So, Prepare these Chemistry Questions and Answers with Explanation Pdf.
For More Chegg Questions
Free Chegg Question
Create a new project and call this project Lab5. Create a package called Time. You will complete two classes for this lab: Time and TimeTest.
Before you start, download the Time.zip folder. (The Time.zip folder contains under the following)
------------------------------
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package Time;
/**
*
* @author
*/
public class Time {
private int hours;
private int minutes;
private String meridian;
/**
* The constructor initializes the three private instance variables.
* It checks if the hours the user passed in is not between 1 and 12, then it
* assigns the hour to be 12. Otherwise, it will assign to be the value that
* was passed in as argument. The constructor also checks if the minutes
* are between 0 and 60. If it is not between 0 and 60, then it assigns the
* minutes to be 0. Otherwise, it assigned the minutes to be the value passed in
* as argument. The constructor also checks if the meridian is AM or PM.
* If the meridian is neither AM or PM, then the default value is AM. Otherwise,
* it will assign the meridian to be the value passed in as the argument.
* @param hours
* @param minutes
* @param meridian
*/
public Time(int hours, int minutes, String meridian) {
}
/**
* This method set the hour of the Time. It also checks that the
* hours are between 1 and 12.
* @param hours
*/
public void setHours(int hours) {
}
/**
* This method set the minutes of the Time. It also checks that the
* minutes are between 0 and 60.
* @param minutes
*/
public void setMinutes(int minutes) {
}
/**
* This method set the meridian of the Time. It also checks that the
* argument is either AM or PM. If it is not AM or PM, it will assign
* the meridian to be AM.
* @param meridian
*/
public void setMeridian(String meridian) {
}
/**
* This method returns the current value of the meridian (AM/PM).
* @return
*/
public String getMeridian() {
}
/**
* This method returns the current hour .
* @return
*/
public int getHours() {
}
/**
* This method returns the current minutes.
* @return
*/
public int getMinutes() {
}
/**
* This method takes minutes as its argument. This parameter determines how
* many minutes has passed since the current time. This method changes the current
* time (hours, minutes, and/or meridian) based on the total minutes that has passed.
* @param min elapsed minutes
*/
public void addMinutes(int min) {
}
/**
* This method prints out the current time using the 12-hour clock.
*/
public void print12Hour() {
}
/**
* This method prints out the current time using the 24 hour clock.
*/
public void print24Hour() {
}
}
------------------------------
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package Time;
import java.util.Scanner;
/**
* The purpose of this program is to test the Java class, Time.
* @author
*/
public class TimeTest {
public static void main (String [] args) {
Scanner in = new Scanner(System.in);
System.out.print("Enter an hour: "); // Prompt the user for an hour
int hours = in.nextInt();
System.out.print("Enter a minute: "); // Prompt the user for a minute
int mins = in.nextInt();
in.nextLine(); // Resolve bug from reading \n after reading a number
System.out.print("Enter a meridian (AM or PM): "); // Prompt user for meridian
String mer = in.nextLine();
System.out.print("How many minutes have passed? "); // Prompt user for time elapse
int e_mins = in.nextInt();
System.out.println("-------- Before Time Elapse --------");
/*
* Step 1) Create an instance of the class Time. It will call the constructor that has three arguments
* Step 2) Print the 12 Hour Clock
* Step 3) Print the 24 Hour Clock
* Step 4) Add minutes that have been passed by calling the appopriate method
* Step 5) Print the 12 Hour Clock (Must be After Print Statement - After Time Elapse)
* Step 6) Print the 24 Hour Clock (Must be After Print Statement - After Time Elapse)
*/
System.out.println("-------- After Time Elapse --------");
}
}
------------------------------
Complete the methods for the class named Time.
Use the UML to help construct the class Time.
Time |
- hour: int - minutes: int - meridian: String |
+ Time (hour: int, minutes: int, meridian: String) + getHour(): int + getMinutes(): int + getMeridian(): String + setHour(hour: int) + setMinutes(minutes: int) + setMeridian(meridian: String) + addMinutes() + printUniversalTime() + printMilitaryTime() |
Constructor
Time class has a constructor that initializes all the instance variables. The constructor checks if all the inputs are valid. The hour passed to the constructor must be between 1 and 12. If the hour is not between those two values, it sets the hour to be 12. It also checks if the minutes are between 0 and 60. If the minutes are not between those two values, then it sets the minutes to be 0. The constructor also checks if the string passed to the constructor is either AM or PM. Make sure that you capitalize each letter.
- To check if two Strings are equivalent, do not use the equality operator (==) or (!=). Java treats the String as an object.
- Instead of using if ( meridian == "AM" ), use if ( meridian.equals("AM"))
- To check if two Strings are not equivalents: use the following code if( !meridian.equals("AM"))
Get Methods
The get method retrieves the current values stored in the instance variable.
Set Methods
Each set method should check if the value passed in is valid before reassignment.
- If the hour is not between 1 and 12, reassign the hour to be 12
- If the minutes are not between 0 and 60, reassign the hours to be 0
- If the meridian is not AM or PM, set the meridian to be AM.
- To check if two Strings are equivalent, do not use the equality operator (==) or (!=). Java treats the String as an object.
- Instead of using if ( meridian == "AM" ), use if ( meridian.equals("AM"))
- To check if two Strings are not equivalents: use the following code if( !meridian.equals("AM"))
addMinutes
This method adds additional minutes to the current time. It will change the hour, minutes, and meridian accordingly. (i.e. if the current time 10:35 AM, and 342 minutes have passed, the current time should be 04:17 PM).
print12Hour
This method prints out the time using the 12-hour clock (i.e. 04:17 PM)
print24Hour
This method prints out the time using the 24-hour clock (i.e. 16:17)
==============================
TimeTest
Complete TimeTest.
The class TimeTest holds the main method we used to test our Time class. The main method already includes all the prompts you need from the user input. Students are responsible for:
- Creating an instance of the software object Time. It will call the constructor that requires three arguments.
- Print the 12 Hour Clock
- Print the 24 Hour Clock
- Add minutes that have been passed by calling the appropriate method
- Print the 12 Hour Clock
- Print the 24 Hour Clock
Assume that the largest value the user will enter for the minutes passed is 1440.
Sample Input Enter an hour: 10 Enter a minute: 35 Enter a meridian (AM or PM): AM How many minutes have passed? 342 Sample Output -------- Before Time Elapse -------- 10:35 AM 10:35 -------- After Time Elapse -------- 04:17 PM 16:17
Sample Input Enter an hour: -1 Enter a minute: 32 Enter a meridian (AM or PM): PM How many minutes have passed? 598 Sample Output -------- Before Time Elapse -------- 12:32 AM 00:32 -------- After Time Elapse -------- 10:30 PM 22:30
Sample Input Enter an hour: 6 Enter a minute: 75 Enter a meridian (AM or PM): PM How many minutes have passed? 563 Sample Output -------- Before Time Elapse -------- 06:00 PM 18:00 -------- After Time Elapse -------- 03:23 AM 03:23
Sample Input Enter an hour: 11 Enter a minute: 35 Enter a meridian (AM or PM): PE How many minutes have passed? 75 Sample Output -------- Before Time Elapse -------- 11:35 AM 11:35 -------- After Time Elapse -------- 12:50 PM 12:50
Sample Input Enter an hour: 11 Enter a minute: 23 Enter a meridian (AM or PM): AM Sample Output How many minutes have passed? 1440 -------- Before Time Elapse -------- 11:23 AM 11:23 -------- After Time Elapse -------- 11:23 AM 11:23
Sample Input Enter an hour: 5 Enter a minute: 23 Enter a meridian (AM or PM): PM How many minutes have passed? 720 Sample Output -------- Before Time Elapse -------- 05:23 PM 17:23 -------- After Time Elapse -------- 05:23 AM 05:23
Sample Input Enter an hour: 11 Enter a minute: 59 Enter a meridian (AM or PM): PM How many minutes have passed? 1 Sample Output -------- Before Time Elapse -------- 11:59 PM 23:59 -------- After Time Elapse -------- 12:00 AM 00:00
Free Chegg AnswerFor More Chemistry Notes and Helpful Content Subscribe Our YouTube Chanel - Chemistry Explain
Free Chegg Answer
/* * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. */ package Time; /** * * @author sysadmin */ public class Time { private int hours; private int minutes; private String meridian; public Time(int hours, int minutes, String meridian) { if (checkHours(hours)) { this.hours = hours; } else { this.hours = 12; } if (checkMinutes(minutes)) { this.minutes = minutes; } else { this.minutes = 0; } if (checkMeridian(meridian)) { this.meridian = meridian; } else { this.meridian = "AM"; } } public void setHours(int hours) { if (checkHours(hours)) { this.hours = hours; } else { this.hours = 12; } } public void setMinutes(int minutes) { if (checkMinutes(minutes)) { this.minutes = minutes; } else { this.minutes = 0; } } public void setMeridian(String meridian) { if (checkMeridian(meridian)) { this.meridian = meridian; } else { this.meridian = "AM"; } } public void addMinutes(int min) { String m = meridian; minutes = minutes + (min % 60); if (minutes >=60) { minutes = minutes - 60; hours = hours + 1; } hours = hours + (min / 60); if (hours >= 12 && hours <= 23) { if (hours != 12) { hours = hours - 12; } if (m.equals("PM")) { meridian = "AM"; } if (m.equals("AM")) { meridian = "PM"; } } if (hours > 23) { if (hours == 24) { hours = 12; } else { hours = hours - 24; } } }
public void print12Hour() { System.out.println("Current Time using 12 hour clock is :" + hours + ":" + minutes + " " + meridian); } public void print24Hour() { int h; if (meridian.equals("AM")) { if (hours == 12) { h = 0; } else { h = hours; } } else { if (hours == 12) { h = 12; } else { h = 12 + hours; } } System.out.println("Current Time using 24 hour clock is :" + h + ":" + minutes); } public int getHours() { return hours; } public String getMeridian() { return meridian; } public int getMinutes() { return minutes; } public boolean checkHours(int hours) { boolean flag = false; if (hours >= 1 && hours < 12) { flag = true; } return flag; } public boolean checkMinutes(int minutes) { boolean flag = false; if (minutes > 0 && minutes < 60) { flag = true; } return flag; } public boolean checkMeridian(String meridian) { boolean flag = false; if (meridian.equals("AM") || (meridian.equals("PM"))) { flag = true; } return flag; } } /* * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. */ package Time; import java.util.Scanner; /** * * @author sysadmin */ public class TimeTest { public static void main(String args[]) { Scanner in=new Scanner(System.in); System.out.println("Enter an hour"); int hours=in.nextInt(); System.out.println("Enter a minutes"); int mins=in.nextInt(); in.nextLine(); System.out.println("Enter a meridian(AM or PM):"); String mer=in.nextLine(); System.out.println("How many minutes have passed?"); int e_mins=in.nextInt(); System.out.println("---Before Time Elapse"); Time timeTesting=new Time(hours, mins, mer); timeTesting.print12Hour(); timeTesting.print24Hour(); timeTesting.addMinutes(e_mins); System.out.println("After Time Elapse"); timeTesting.print12Hour(); timeTesting.print24Hour(); } }
Labels: Chegg, Free Chegg Answer, Q&A Computer Science
0 Comments:
Post a Comment
Subscribe to Post Comments [Atom]
<< Home