Java Programing. My Professor givs me this assighment: For this assignment you w
ID: 3768357 • Letter: J
Question
Java Programing.
My Professor givs me this assighment:
For this assignment you will design two classes that work together to introduce personal information.
The first file ( for example: mark.java)
The file should have the following methods:
setName . The method should set name.
getName. The method should get name.
setCredits. The method should set two semester credits
getTotalCredits. The method should return the total credits of the two semester.
isIdEven. This method should return the boolean value true if the number is an even number.
the second file(for example: mark_data.java):
This file should demonstrate the personal information as following:
1.Create an array which contains your current courses in Fall, 2015 and display each array element.
2.Set your real name to the method defined in the first file
3.Set your 2 real credits of fall, 2015 and Spring 2015 to the method defined in the first class ( for example, you have 13 credits for fall, 2015 and 15 credits for the spring,2015)
4.Check your real banner id whether it is an even number.
and here is the code i wrote:
___________________________________________
public class MB {
public static void main(String args[])
private String name;
private int Credits,Total_Credits,Id=1543439;
public void setName(String naim){
name=naim; }
public String getName(){
return name;}
public void setCredits(int cred1,int cred2){
Credits=cred1+cred2;}
public int getTotalCredits(){
return Credits;}
public void isIdEven(){ if(Id%2==0)
System.out.println("True: Yuor Number is even");
else System.out.println("False:Your Id is not Even");
}
}
public class MB_Data {
public static void main(String args[])
{ int i;
String [] Course = {"Cosc 201","ENGL 222","HIS 101","Java 101","MATH 115"};
MB Displayer= new MB();
Displayer.setName("My Name is MB");
Displayer.setCredits(15,16);
System.out.println(Displayer.getName());
System.out.println("I have a total credit of "+Displayer.getTotalCredits());
Displayer.isIdEven();
for(i=0;i<5;i++)System.out.print(Course[4]+" ");
System.out.println();
}
}
_______________________________________
i tried many times to run this code, but i got errors.
Can anyone help me please
Note: attachment is a pic of the resulte i got when i try to run the code through Command Prompt
Explanation / Answer
Mark.java
/**
*
*/
/**
* @author Srinivas Palli
*
*/
public class Mark {
private String name;
private int Credits, Total_Credits, Id = 1543439;
public void setName(String naim) {
name = naim;
}
public String getName() {
return name;
}
public void setCredits(int cred1, int cred2) {
Credits = cred1 + cred2;
}
public int getTotalCredits() {
return Credits;
}
public void isIdEven() {
if (Id % 2 == 0)
System.out.println("True: Yuor Number is even");
else
System.out.println("False:Your Id is not Even");
}
}
MarkData.java
/**
* @author Srinivas Palli
*
*/
public class MarkData {
/**
* @param args
*/
public static void main(String args[])
{
int i;
String[] Course = { "Cosc 201", "ENGL 222", "HIS 101", "Java 101",
"MATH 115" };
Mark Displayer = new Mark();
Displayer.setName("My Name is MB");
Displayer.setCredits(15, 16);
System.out.println(Displayer.getName());
System.out.println("I have a total credit of "
+ Displayer.getTotalCredits());
Displayer.isIdEven();
for (i = 0; i < 5; i++)
System.out.print(Course[4] + " ");
System.out.println();
}
}
OUTPUT:
My Name is MB
I have a total credit of 31
False:Your Id is not Even
MATH 115 MATH 115 MATH 115 MATH 115 MATH 115
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.