Answer to Question #309235 in Java | JSP | JSF for Lairus

Question #309235

Create a project to model student with firstname, lastname, age, gender and student number. Create two construtors, one to be used as default and another to include all attributes. Add a class attribute to keep count of all registered students. Use the class attribute to generate student numbers with the following format 22201XYZ, where XYZ is the current count provided by the class attribute. Implement the respective getters and setters for each attribute.  2. In plane geometry, the x- and y axis of a 2D Cartesian system divide it into four infinite regions called quadrants. Your task is to model each point with an x-value and y-value. Apart from the constructors, getters and setters, implement a getQuadrant method to determine the region in which a given point falls. 


1
Expert's answer
2022-03-10T10:25:45-0500




import java.util.*;


class Student {
	private String firstname;
	private String lastname;
	private int age;
	private String gender;
	private int number;
	private static int count = 0;


	public Student() {
		count++;
	}


	public Student(String firstname, String lastname, int age, String gender) {
		this.firstname = firstname;
		this.lastname = lastname;
		this.age = age;
		this.gender = gender;
		count++;
		this.number = count;
	}


	public String toString() {
		return "Full names : " + this.firstname + " " + this.lastname + "\nAge : " + this.age + "\nGender : "
				+ this.gender + "\nStudent Number : " + String.format("22201%03d", this.number);
	}


	/**
	 * @return the firstname
	 */
	public String getFirstname() {
		return firstname;
	}


	/**
	 * @param firstname the firstname to set
	 */
	public void setFirstname(String firstname) {
		this.firstname = firstname;
	}


	/**
	 * @return the lastname
	 */
	public String getLastname() {
		return lastname;
	}


	/**
	 * @param lastname the lastname to set
	 */
	public void setLastname(String lastname) {
		this.lastname = lastname;
	}


	/**
	 * @return the age
	 */
	public int getAge() {
		return age;
	}


	/**
	 * @param age the age to set
	 */
	public void setAge(int age) {
		this.age = age;
	}


	/**
	 * @return the gender
	 */
	public String getGender() {
		return gender;
	}


	/**
	 * @param gender the gender to set
	 */
	public void setGender(String gender) {
		this.gender = gender;
	}


	/**
	 * @return the number
	 */
	public int getNumber() {
		return number;
	}


	/**
	 * @param number the number to set
	 */
	public void setNumber(int number) {
		this.number = number;
	}


}


class App {


	public static void main(String[] args) {
		Scanner keyboard = new Scanner(System.in);
		int numberStudents = keyboard.nextInt();
		Student students[] = new Student[numberStudents];
		keyboard.nextLine();
		for (int i = 0; i < numberStudents; i++) {
			String values[] = keyboard.nextLine().split(" ");
			students[i] = new Student(values[0], values[1], Integer.parseInt(values[2]), values[3]);
		}
		for (int i = 0; i < numberStudents; i++) {
			System.out.println(students[i].toString());
		}


		keyboard.close();
	}
}













import java.util.*;


class Point {
	private int x;
	private int y;


	public Point() {


	}


	public Point(int x, int y) {
		this.x = x;
		this.y = y;
	}


	public String getQuadrant() {
		if (x == 0 && y == 0) {
			return "Point: (" + x + ", " + y + ") is the origin";
		} else if (y == 0) {
			return "Point: (" + x + ", " + y + ") is on the x-axis";
		} else if (x == 0) {
			return "Point: (" + x + ", " + y + ") is on the y-axis";
		} else if (y > 0) {
			if (x > 0) {
				return "Point: (" + x + ", " + y + ") is in Quadrant I";
			} else {
				return "Point: (" + x + ", " + y + ") is in Quadrant II";
			}
		} else {
			if (x < 0) {
				return "Point: (" + x + ", " + y + ") is in Quadrant III";
			}
		}
		return "Point: (" + x + ", " + y + ") is in Quadrant IV";
	}


	/**
	 * @return the x
	 */
	public int getX() {
		return x;
	}


	/**
	 * @param x the x to set
	 */
	public void setX(int x) {
		this.x = x;
	}


	/**
	 * @return the y
	 */
	public int getY() {
		return y;
	}


	/**
	 * @param y the y to set
	 */
	public void setY(int y) {
		this.y = y;
	}


}


class App {


	public static void main(String[] args) {
		Scanner keyboard = new Scanner(System.in);
		System.out.print("Enter the x and y value: ");
		int x = keyboard.nextInt();
		int y = keyboard.nextInt();
		Point p = new Point(x, y);
		System.out.print(p.getQuadrant());
		keyboard.close();
	}
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS