Professor Abdul-Quader
Designing Classes
public class MyClass in file MyClass.javaVariable declarations in Time class:
public Time(...).Java has several different visibility modifiers:
If the instance variables are public:
Time t = new Time(11, 59, Time.AM); // "11:59 AM"
t.hour = 53;
t.minute = -7;
t.amPm = "Hah! I tricked you!";
System.out.println(t);If you are behind, you need to be doing as many exercises as possible. Write code as much as you can.
Problem: given a String name, return the number of times the character c appears in it. What are all the mistakes in the following?
displayNumber without knowing how to write getNumbermain without knowing how to write any of the other methods.getNumber four times, output x, output y, multiply (real and imaginary), output the product.If your grade on exam 1 was below 80, I will accept corrections for any problem you wish to correct. For each question, you must:
You will get up to half the credit lost for each response (up to a max of 80). Please come see me in office hours if you had trouble with any of these! Due: 3/19 (to me, in class, before Spring Break).
If your exam 1 grade is below 50, please see me in office hours, we can discuss further strategies to help catch you up.
Attempt 3: design a program which asks the user to input in the current time and a number of minutes to add (up to a max of 500), and outputs the time after that many minutes.
Already implemented for you:
toString displays the time correctlytimeAfter method, returns a new Time objectgetInput (gets an integer in a certain range from the user)getAmOrPmInput (asks the user for input until they type in “AM” or “PM”)What do you need to do?
Implement the main method to put everything together.
A Gaussian integer is a complex number of the form \(a + bi\), where \(a\) and \(b\) are integers (\(i\) is the imaginary number representing a square root of \(-1\)). How would you design a Gaussian integer? What data is required to represent a Gaussian Integer? What are the actions it should be able to do?