Explain the following code. import java.text.DecimalFormat; public class Time1 extends Object { private int hour; private int minute; private int second; public Time1()
Q: Computer Science In Java, create a class Die representing a die to roll randomly. -Give Die a…
A: ans is given below
Q: Java Questions - (Has 2 Parts). Based on each code, which answer out of the choices "A,B,C,D,E" is…
A: Both of these questions from the inheritance part of the java. The second question is giving the…
Q: Java --- Please help me understand further the code below. Thank you!| --- Circle.java public class…
A: ALGORITHM: Step 1: Create an interface Shape Step 2: In that create 4 classes circle, rectangle,…
Q: 1. Write the java code for the following class diagram. Mention the method overridden. Vehicle Car…
A: Create two classes Vehicle and Car As per class diagram Car class will extend Vehicle class In Car…
Q: public class BClass { private int x; public void set(int a) { x = a; } public void print( {…
A: print() method displays the respective data member of the class. In method overriding, we need to…
Q: TestCakeProgram.java:30: error: cannot find symbe ob[i] = new orderCake(w,name,rateO); symbol:…
A: 1- I have checked the entire code, there is only one mistake. 2- ob[i] = new…
Q: (this is question1) public abstract class Shape { public Shape() { } public abstract…
A: Here we have an abstract class shape that has an abstract method and one method that returns the…
Q: Write a Java application for the Banking system that consists of at least three classes for Bank,…
A: Given: Write a Java application for the Banking system that consists of at least three classes for…
Q: public class array { public static void main(String args[] {…
A: ArrayIndexOutOfBoundsException
Q: (Java) 7.2 Code: Look at the following Person.java class code: class Person{ public String name;…
A: The toString() method is a method in java that is used to print or output the values of an object or…
Q: The BankAccount class described below is used to represent a personal savings account with a yearly…
A: ALGORITHM:- 1. Create a class CreditAccount inheriting the BankAccount class. 2. Override the…
Q: Implement the following classes in Java. Date class which has day(int), month(int) and year(int)…
A: Total 5 classes needs to be maid one each for date, time, datetime, pizzaorder and test class. Date…
Q: 4. Consider the following program segment: public class Ch7_PrExercise4 public static void main…
A: we can only solve one question in one post. solving first. please post second question saperatly.…
Q: Given the following code, the output is class Base { private int x = 5; } class Derived extends Base…
A: This is an example of inheritence.
Q: How do I fix the errors? Java Error 1 overloading constructor with invalid weight ERROR:…
A: There is a trick to validate the instance variable's value. You should call the setters to set the…
Q: Evaluate the JAVA code snippet below, then motivate why this is representative of good programming…
A: Good programming practices: The given code snippet is not an example of good programming practice…
Q: public class Ice extends Fire { public void method1() { System.out.print("Ice 1 "); public class…
A: Output of the given program is given below:-
Q: Intellij - Java Program 1: Write a program which does the following: Create a class with the…
A: According to our guidelines we can answer only one question at a time if you want answer of an other…
Q: public class Appliance { public int getVoltage() { return 10; } Appliance.java public interface…
A:
Q: Computer Science Is there a way to rewrite this Java code differently? package application;…
A: The other way to write the above code is by not declaring the variables as private , so in that case…
Q: Type a Java method constructor for the "book" Class, which takes values as parameters for all of…
A: A program is used to interact with the computer system. A program is converted into the 0's and 1's…
Q: Write a program using classes ,methods and objects concept to do the following tasks. a) Read input…
A: import java.util.Scanner; public class Main{ public static void main(String[] args) { double…
Q: java programming Complete the code for the class StudentAccount in the following. Add constructors…
A: The abstract class is the class in which abstract classes can't be created object and if the class…
Q: Q#1: Write the Class for Circle. Read the following code and create the attributes, method,…
A: Define the class Circle as follows: It contains a private data member for storing the radius. It…
Q: Consider the following three Java classes: public abstract class Toy { public void makeNoise() {…
A: doll.makeNoise(); doll is an instance of Doll class and it invokes makeNoise() method in Doll…
Q: You are given the below Java code: 1 public class Student( public String name; public double gpa; 3.…
A: Find the answer with reason given as below :
Q: Consider the following code in Java 8: public interface Runnable { void run() ; } public final class…
A: Here we have an interface named Runnable with one abstract method named run, hence we can say that…
Q: Given the following Date class public class Date { private int year; private int month; private int…
A: Answer: date d=new Date(2020,20,9);
Q: The following code is in Java: public class Vehicle // Superclass { private…
A: Given code snippet public class Vehicle // Superclass { private double cost;…
Q: o Page 200, Question 5.25(25%) • Modify the application you wrote in Exercise 5.24 to read an odd…
A: According to information given:- We have to modify the code to read an odd number in range of 1-19…
Q: Given the below class: public class Dog { private String name; private double weight;…
A: 1.) Class : Dog public class Dog { private String name; private double weight; private…
Q: Problem 1) The following Java Code class is given public class Point { private int xCor; private int…
A: public class Point { private int xCor; private int yCor; public Point(int x,int y) { this.xCor=x;…
Q: A digital clock shows hours (between 0 and 23) and minutes (between 0 and 59). Ônce a minute, it…
A: File name: “Clock.java” public class Clock { private int hours; private int minutes;…
Q: (Java) Question 3 Explain the answer step-by-step and include verbal explanation. Thank you!…
A: EXPLANATION: The first object is created of Person class and the constructor is called by passing…
Q: Consider the following declaration of class Quad and answer the question below. class Quad int x0,…
A: A class template provides a specification for generating classes based on parameters. Class…
Q: Analyse the following Java code segment and answer the questions that follow: 1| interface Steerable…
A: Every program is written using some building blocks which are called programming constructs. The…
Q: Java programming. A method signature for a method consists of all elements of the method except the…
A: a) A method in class String that returns the reversed version of the current String. public String…
Q: Given the definition of the Person and Student classes below, public class Person{ public String m…
A: According to the information given:- We have to find the appropriate choose .
Q: Java-OOP write the dry run of the following program public abstract class Payment { protected double…
A: According to the information given:- we have to compile and dry run the given code in Java.
Q: Java: Derive the class ExtClock from the class Clock by adding a data member to store the time zone.…
A: Inheritance is a feature of java object-oriented programming. The property of acquiring the parent…
Q: What is the output of the following code? public interface yourInterface { int x = 10; %3D int y =…
A: Operators are the fundamental building blocks of all programming languages. Java, too, has a variety…
Q: How do I code: public static int sum(int[] arr) public static int sum(int[] arr, int…
A: Algorithm: for (initialExpression; testExpression; updateExpression){ // body of the…
Q: The following code is in Java: public class Vehicle // Superclass { private…
A: Given code snippet in java public class Vehicle // Superclass { private double cost;…
Q: Problem 4) Suppose the following Course class is given: public class Course { private String…
A: If the evaluation of a logical expression exits even before the complete evaluation is done, it is…
Q: You are given Car.java class public class Car { } protected double year; Car cl public Car (double…
A: given java program and the output is given below
Q: public class A extends C { public void method1() { System.out.print("a1 "); } public String…
A: The above program is a program of inheritance in java. Inheritance is an object-oriented programming…
Q: Explain the following Java Polymorphism code in details. class Shape { public double getArea() {…
A: Lets see the solution.
Q: The following is in Java: public class MyClass { private int x; private double y;…
A: Defined the given Java code
Q: Q1. Write two Java classes for calculating the power m" using the recursive method as follow: Class…
A: Algorithm to calculate power mn using recursion: Method: int calculatePower(n, m) 1. IF n == 1:…
Q: irst, you need to design, code in Java, test and document a base class, Student. The Student class…
A: Actually, program is a executable software that runs on a computer.
Explain the following code.
import java.text.DecimalFormat;
public class Time1 extends Object {
private int hour;
private int minute;
private int second;
public Time1()
{
setTime( 0,0,0 );
}
public void setTime( int h, int m, int s )
{
hour = ( ( h >= 0 && h < 24 ) ? h : hour );
minute = ( ( m >= 0 && m < 60 ) ? m : minute );
second = ( ( s >= 0 && s < 60 ) ? s : second );
}
public String toUniversalString()
{
DecimalFormat twoDigits = new DecimalFormat( "00" );
return twoDigits.format( hour ) + ":" +
twoDigits.format( minute ) + ":" + twoDigits.format( second );
}
public String toStandardString()
{
DecimalFormat twoDigits = new DecimalFormat( "00" );
return ( (hour == 12 || hour == 0) ? 12 : hour % 12 ) + ":" +
twoDigits.format( minute ) + ":" + twoDigits.format( second ) +
( hour < 12 ? " AM" : " PM" );
}
}
public class TimeTest1 {
public static void main( String args[] )
{
Time1 time = new Time1();
String output = "The initial universal time is: " +
time.toUniversalString() + "\nThe initial standard time is: " +
time.toStandardString();
time.setTime( 13, 27, 6 );
output += "\n\nUniversal time after setTime is: " +
time.toUniversalString() +
"\nStandard time after setTime is: " + time.toStandardString();
time.setTime( 99, 99, 99 );
output += "\n\nAfter attempting invalid settings: " +
"\nUniversal time: " + time.toUniversalString() +
"\nStandard time: " + time.toStandardString();
System.out.println(output);
}
}
Step by step
Solved in 4 steps with 4 images
- use Java. Given the following class. public class FamilyMember { public String drink( ) {return “cup”;} public String eat( ) {return “fork”;} } Write a Baby class that is derived from the FamilyMember class. The Baby class has an instance variable for the age, a default constructor, and a constructor that accepts an integer. Include any other necessary methods. If a baby is older than 3 years, print that “it eats with its fork”; otherwise, “it eats with its hands”.Solve below java problem please. You are given a list of Employee objects and you need to implement a method that returns the top n highest-paid employees. class Employee { private String name; private double salary; public Employee(String name, double salary) { this.name = name; this.salary = salary; } public String getName() { return name; } public double getSalary() { return salary; } }Given the following class. (JAVA) public class FamilyMember { public String drink( ) {return “cup”;} public String eat( ) {return “fork”;} } Write a Baby class that is derived from the FamilyMember class. The Baby class has an instance variable for the age, a default constructor, and a constructor that accepts an integer. Include any other necessary methods. If a baby is older than 3 years, print that “it eats with its fork”; otherwise, “it eats with its hands”.
- In Java code: Write the class encapsulating the concept of money, assuming that money has the following attributes: dollars, cents In addition to the constructors, the accessors and mutators, write the following methods: public Money() public Money(int dollars, int cents) public Money add(Money m) public Money substract(Money m) public Money multiply(int m) public static Money[] multiply(Money[] moneys, int amt) public boolean equals(Money money) public String toString() private void normalize() // normalize dollars and cents field Add additional helper methods if necessary. Use the following test driver program to test your Money class: public class MoneyTester{public static void main(String[] args){Money m1 = new Money(8, 75); // set dollars to 8 and cents to 75Money m2 = new Money(5, 80); // set dollars to 5 and cents to 80 MoneyMoney m3 = new Money(); // initialize dollars to 0 and cents to 0System.out.println("\tJane Doe " + "CIS35A Spring 2021 Lab 4"); // useyour…COMPLETE THE JAVA CODE BELOWSEE ATTACHED PHOTO FOR THE PROBLEM AND THE OUTPUT class Employee extends Person { private String companyName; public Employee(String name,String address,int age,String companyName) { super(name,address,age); this.companyName = companyName; } public Employee() { } public void setCompanyName(String cname){ companyName = cname; } public String getCompanyName(){ return companyName; } // Override the display method in the Person class // define earnings as an abstract method with a return type of double // override the toString() and equals() methods } class HourlyEmployee extends Employee{ private int hoursWorked; //total number of hours worked private double rate; // rate per hour public HourlyEmployee(String name,String address,int age,String cName,int hoursWorked,double rate) { } public HourlyEmployee(String name,String address,int age,String cName)…(Java) 7.2 Code: Look at the following Person.java class code: class Person{public String name;public int age;public String gender;public void greeting() {System.out.println( "Hi, my name is " + name + "!");}public void greeting(String otherName){System.out.println("Hi, " + otherName + "!");}public void printPerson () {System.out.println("Name: "+name);System.out.println("Age: "+age);System.out.println("Gender: "+gender);System.out.println();}} Remove the printPerson method from this class. Instead, write a toString() method that can be used to display the Student Object in the following manner: Name: <The Name> Age: <The Age> Gender: <The Gender> Note the use of the <> above. Do not add these <> to your String. Instead, these <> are commonly used to mean a value will be filled in later. Don't forget the @Override tag in front of the toString() method image source Using the below starter code and the toString method, we will…
- 1- void 2- private 3- static 4- public Which is correct in JavaThe following code is in Java: public class Vehicle // Superclass { private double cost; public Vehicle(double c) { cost = c; } (Other methods . . .) // assume these are given and they’re OK. } public class Car extends Vehicle // Subclass { private int passengers; public Car(int p) { passengers = c; } (Other methods . . .) // assume these are given and they’re OK. } 1) What problems are in the code above?2) What is needed to fix the issue of the code?(this is question1) public abstract class Shape { public Shape() { } public abstract double area() ; public String who() { return "Shape" ; } } public class Circle extends Shape { private int radius ; public Circle( int r ) { radius = r ; } @Override public double area() { return Math.PI * radius * radius ; } } public class Square extends Shape { private int _sideLength ; public Square( int sideLength ) { /* TODO question 45 */ } @Override public double area() { return _sideLength * _sideLength ; } } What is the output of the following code (approximate answer ok if needed)? Assume your constructor from question 1 above has been implemented and the following code is contained within a driver class. public static void main(String[] args) { report(new Circle(4)); report(new Square(5)); } public static void…
- Please solve this using java and attach output screenshot and implementation screenshot. Using this clock class please: public class Clock { private int hr; private int min; private int sec; public Clock() { setTime(0, 0, 0); } public Clock(int hours, int minutes, int seconds) { setTime(hours, minutes, seconds); } public void setTime(int hours, int minutes, int seconds) { if (0 <= hours && hours < 24) hr = hours; else hr = 0; if (0 <= minutes && minutes < 60) min = minutes; else min = 0; if(0 <= seconds && seconds < 60) sec = seconds; else sec = 0; } public int getHours() { return hr; } public int getMinutes() { return min; } public int getSeconds() { return sec; } public void printTime() { if (hr < 10) System.out.print("0"); System.out.print(hr + ":"); if (min < 10) System.out.print("0"); System.out.print(min + ":"); if (sec < 10) System.out.print("0"); System.out.print(sec); } public void incrementSeconds() { sec++; if (sec >…Consider the following three Java classes: public abstract class Toy {public void makeNoise() { System.out.println("DEFAULT SOUND"); }} public class Doll extends Toy {public void makeNoise() { System.out.println("Mama!"); }}public class ToyRobot extends Toy {private int volume; public ToyRobot() { this.volume = 5; } public void makeNoise() { System.out.println("BEEP"); } public int getVolume() { return volume; } public void setVolume(int volume) { this.volume = volume; }} Given these classes, determine what will be printed when each of the code snippets below are copied into the following main method at the indicated location. public static void main(String[] args) { Toy toy; Doll doll; ToyRobot robot1; ToyRobot robot2; doll = new Doll(); robot1 = new ToyRobot(); robot2 = robot1; toy = robot1; // INSERT CODE HERE. } A) doll.makeNoise(); ["", "", "", ""] B) toy.makeNoise(); ["", "", "", ""] C)…The following code is in Java: public class Vehicle // Superclass { private double cost; (Other methods . . .) // assume these are given and they’re OK. } // Subclass public class Car extends Vehicle { public Car(double c) { cost = c; } }1) What is the problem with the code?2)How can it be fixed?