MIS 306 GUST Netbeans Program Rewrite & Public Class Java Programming Exercise

User Generated

Zb0baM

Programming

MIS 306

Gulf University for Science and Technology

MIS

Description

The Question is as an Attachment feel free to read it is about Java

btw : we using the netbeans program

Unformatted Attachment Preview

MIS306 Assignment 1 Spring 2021 Question 1 Read the following Java program to answer the following questions. public class Address{ String area; int block; int street; int building; public Address(){ area = ""; block = 1; street = 1; building = 1; } public Address(String a, int b, int s, int bu){ area = a; block = b; street = s; building = bu; } public String toString(){ String fullAddress = area + ", block: " + block + ",street: " +street + ", building: " + building; return fullAddress; } } public class Main { public static void main(String[] args) { Address workAd = new Address("Salwa",10,4,5); Address homeAd = new Address(); homeAd.area = "Mishref"; homeAd.block = 6; homeAd.street = 2; homeAd.building = 109; System.out.println("The area of the work address is: "+ workAd.area); System.out.println("The full home address is: " + homeAd.toString()); } } a) What is the output of the above program? b) Rewrite class Address by declaring its data members as private, and creating setters and getters for all data members. When a new object Address is created, or when the value of any data member is changed, the following data validation rules should be applied. a. The value of the area should contain at least two characters, otherwise it must be set to NA b. The value of the block should be between 1 and 20. c. The value of the street should be between 1 and 150. d. The value of the building should be any positive number. c) Update the second constructor method to validate the data members before setting their values. If a value is incorrect, a default correct value should be stored in the matching data member. d) Rewrite the main class so that it uses the new class Address to generate the same output as before. MIS306 Assignment 1 Spring 2021 Question 2 Read the following code then answer questions a) , b), and c). public class Circle{ private double radius; public String color; public static final double pi = 3.14; public Circle(double r, String c){ radius = r; color = c; } public void setRadius(double r){ if(r > 0 ){ radius = r; } else{ System.out.println("Warning: Radius should be a positive number"); } } public double getRadius(){ return radius; } public double calculateArea(){ double area; area = pi * radius * radius; return area; } public String toString(){ String details = "(Radius: " + radius + ", color: " + color + ")"; return details; } } public class Main { public static void main(String[] args) { Circle c1 = new Circle(2.5, "Red"); System.out.println("The area of the circle " + c1 + " is: "); System.out.println(c1.calculateArea() ); c1.setRadius( c1.getRadius() + 1 ); System.out.println("The area of the circle " + c1 + " is: "); System.out.println(c1.calculateArea() ); c1.setRadius( c1.getRadius() - 5 ); System.out.println("The area of the circle " + c1 + " is: "); System.out.println(c1.calculateArea() ); } } MIS306 Assignment 1 Spring 2021 a) What is the output of the above code? b) Assume that the following statements are added at the end of the main method. Indicate for each statement in the table if it is valid or not. Either correct invalid statements or explain what makes them invalid. Statement Valid (✓)/ Explanation/Correction for Invalid (X) invalid statements ONLY Circle c2 = new Circle("6.5", 15); Circle c3 = new Circle("Red","5"); Circle c4 = new Circle(1.5, "Green"); c4.radius = 2.5; c4.color = "Dark Green"; Circle.color = "Black"; Circle.pi = 3.14159; System.out.println(c4.color); System.out.println(c4.radius); System.out.println(Circle.pi); MIS306 Assignment 1 Spring 2021 Question 3 Answer ALL of the following questions based on this provided code. class Date{ int day; int month; int year; Date(int d, int m, int y){ day = d; month = m; year = y; } boolean isBefore(Date d){ boolean x = false; if( (year
Purchase answer to see full attachment
User generated content is uploaded by users for the purposes of learning and should be used following Studypool's honor code & terms of service.

Explanation & Answer

View attached explanation and answer. Let me know if you have any questions.

Question 1:
a) The area of the work address is: Salwa
The full home address is: Mishref, block: 6,street: 2, building: 109
b,c,d)
public class Address{
private String area;
private int block;
private int street;
private int building;
public Address(){
area = "";
block = 1;
street = 1;
building = 1;
}
public String getArea() {
return area;
}
public int getBlock() {
return block;
}
public int getStreet() {
return street;
}
public int getBuilding() {
return building;
}
public void set...


Anonymous
Just what I needed…Fantastic!

Studypool
4.7
Indeed
4.5
Sitejabber
4.4

Related Tags