Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

- Programs below, are incorrect and used as a template. Make corrcections by usi

ID: 3699925 • Letter: #

Question

- Programs below, are incorrect and used as a template. Make corrcections by using directions.

Problem:

The Swami class (Swami.java)               40 pts

3 instance data: name, month, day;

Methods: getName, getMonth, getDay, getSign, getElement, getHoroscope, setDay, setMonth, changeBirthday;

changeBirthday ()

Use your birthday month and decrement by 5 (if is less than or equal to 5, then it will increment by 5; Take your birth day (13, 25, etc) and decrement it by 6 (if is less than or equal to 6, then increment by 4)

The demoSwami.java Application            30 pts

demoSwami application will do the following:

(1) Read a birthday from the keyboard – using Scanner object

(2) For each birthday it will

(a) Create a Swami object

(b) Display the initial state of the object; (Name, Month, Day)

Use accessor and mutator methods to do the following:

(c) Display the object’s horoscope, sign, symbol, and element;

(d) Call changeBirthday; redisplay Name, Month and Day;

e) display the new horoscope, sign, symbol, and element;

Note: Also if I try to insert an incorrect date you should validate :Sept 31 should not be allowed; etc.

Output:

Name:Gabe            Month:08         Day:23

Gabe, Swami says: You don't mind working hard to make something great happen and today is a good time to figure out your next steps.

Sign:Virgo Symbol:Virgin   Element: Earth

Name:Gabe            Month:             Day:     (New month and new day)

New Horoscope

Sign:New Sign        Symbol:New Symbol     Element: New Element

Explanation / Answer

public class DemoSwami
{

public static void main(String[] args)
{
  
String sName;
int sMonth;
int sDay;
String sSign;
String sSymbol;
String sElement;

Scanner keyboard = new Scanner(System.in);
  
//Swami object
  
SwamiClass obj1 = new SwamiClass();
  
//Prompt the user
System.out.println("Enter the name");
sName = keyboard.nextLine();
obj1.setName(sName);
  
keyboard.nextLine();
  
//prompt for birthday month
System.out.println("What is your birthday month?");
sMonth = keyboard.nextInt();
obj1.setMonth(sMonth);
  
}
}

  

//class
class SwamiClass
{
//Instance fields
private String name;
private String element;
private String horoscope;
private String sign;
private String symbol;
private int month;
private int day;

//Accessor Methods
public int getMonth()
{
return month;
}

public String getName()
{
return name;
}

public int getDay()
{
return day;
}
  
public void changeBirthday()
{

if (month <= 5) {
month += 5;
}
else {
month -= 5;
}

if (day <= 6) {
day += 4;
}
else {
day -= 6;
}

}

//Mutator Methods

public void setDay(int d)
{
if (d < 1)
throw new IllegalArgumentException("Day cannot be less than 1");
  
if (month == 2 && d > 29)
throw new IllegalArgumentException("February dont have more than 29 days");
  
if ((month == 4 || month == 6 || month == 9 || month == 11) && d > 30)
throw new IllegalArgumentException("month " + month + "cannot have more than 30 days");
  
if (d > 31)
throw new IllegalArgumentException("Day cannot be more than 31");
day = d;
}

public void setMonth(int m)
{
if (m < 1)
throw new IllegalArgumentException("Month cannot be less than 1");
  
if (m == 2 && day > 29)
throw new IllegalArgumentException("February dont have more than 29 days");
  
if ((m == 4 || m == 6 || m == 9 || m == 11) && day > 30)
throw new IllegalArgumentException("month " + month + "cannot have more than 30 days");
  
if (m > 12)
throw new IllegalArgumentException("Month cannot be more than 12");
month = m;
}

public void setName(String n)
{
name = n;
}

  
public String getHoroscope()
{
//create code here
  
}

public String getElement()
{
// create code here
}

public String getSign()
{

// create code here
}

public String getSymbol()
{
// Create code here  
}
}

I have updated changeBirthday () acording to the direction provided
And also fixed certain errors in the getters and setters. Also implemented error handling so that user cannot set invalid dates and months