Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

This is my question and this is the code in lab 2 The 1's are replaced with an E public class 1xam { private int

This is my question and this is the code in lab 2 The 1's are replaced with an E

public class 1xam

{

private int day;

private int month;

private int year;

private int hour;

private int minutes;

private double maxMarks;

private final String type;

private final int order;

private static int lab1xamCounter = 0;

private static int midterm1xamCounter = 0;

public static final String LAB_1XAM = "Lab 1xam";

public static final String MIDTERM_1XAM = "Midterm 1xam";

public static final String FINAL_1XAM = "Final 1xam";

public 1xam(String type)

{

this (type, 0, 0, 0, 0, 0, 0);

}

public 1xam(String type, double maxMarks)

{

this (type, maxMarks, 0, 0, 0, 0, 0);

}

public 1xam(String type, double maxMarks, int day, int month, int year)

{

this (type, maxMarks, day, month, year, 0, 0);

}

public 1xam(1xam other)

{

this (other.getType(), other.getMaxMarks(), other.getDay(), other.getMonth(), other.getYear(), other.getHour(), other.getMinutes());

}

public 1xam(String type, double maxMarks, int day, int month, int year, int hour, int minutes)

{

switch( type ) {

case LAB_1XAM:

this.order = ++lab1xamCounter;

this.maxMarks = (maxMarks > 5 && maxMarks <= 10 ? maxMarks : 10 );

break;

case MIDTERM_1XAM:

this.order = ++midterm1xamCounter;

this.maxMarks = (maxMarks > 15 && maxMarks <= 20 ? maxMarks : 20 );

break;

case FINAL_1XAM:

this.order = 0;

this.maxMarks = (maxMarks > 30 && maxMarks <= 40 ? maxMarks : 40 );

break;

default:

this.order = 0;

this.maxMarks = maxMarks;

}

if (day >= 1 && day <= 31)

this.day = day;

if (month >= 1 && month <= 12)

this.month = month;

if (year > 0)

this.year = year;

if (hour >= 0 && hour <= 23)

this.hour = hour;

if (minutes >= 0 && minutes <= 59)

this.minutes = minutes;

this.type = (type != null ? type : "");

}

public String getType()

{

return type;

}

public void setDay(int day)

{

if (day >= 1 && day <= 31)

this.day = day;

}

public int getDay()

{

return day;

}

public void setMonth(int month)

{

if (month >= 1 && month <= 12)

this.month = month;

}

public int getMonth()

{

return month;

}

public void setYear(int year)

{

if (year > 0)

this.year = year;

}

public int getYear()

{

return year;

}

public void setDate(int day, int month, int year)

{

this.setDay(day);

this.setMonth(month);

this.setYear(year);

}

public void setHour(int hour)

{

if (hour >= 0 && hour <= 23)

this.hour = hour;

}

public int getHour()

{

return hour;

}

public void setMinutes(int minutes)

{

if (minutes >= 0 && minutes <= 59)

this.minutes = minutes;

}

public int getMinutes()

{

return minutes;

}

public void setTime(int hour, int minutes)

{

this.setHour(hour);

this.setMinutes(minutes);

}

public void setMaxMarks(double maxMarks)

{

switch( this.type ) {

case LAB_1XAM:

this.maxMarks = (maxMarks > 5 && maxMarks <= 10 ? maxMarks : 10 );

break;

case MIDTERM_1XAM:

this.maxMarks = (maxMarks > 15 && maxMarks <= 20 ? maxMarks : 20 );

break;

case FINAL_1XAM:

this.maxMarks = (maxMarks > 30 && maxMarks <= 40 ? maxMarks : 40 );

break;

}

}

public double getMaxMarks()

{

return this.maxMarks;

}

public String toString()

{

return String.format("1xam: %s %s (%04.2f marks) Date: %d/%d/%d Time: %02d:%02d ",

getType(), (order > 0 ? order : ""), getMaxMarks(), getDay(),

getMonth(), getYear(), getHour(), getMinutes());

}

public static String get1xamStats()

{

return LAB_1XAM + ": " + lab1xamCounter + " 1xam(s) " +

MIDTERM_1XAM + ": " + midterm1xamCounter + " 1xam(s) " ;

}

}

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored 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

Recommended Textbook for

More Books

Students also viewed these Databases questions