Machine Problem

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 6

Jericho Jover V. Magpantay Jeane Kelmer O.

DelaCruz

Machine Problem #1: Structure/concepts: Array; no method is required


Write an application that contains an array of 5 multiple-choice
quiz questions related to Advanced Programming course. Each question
contains three answer choices. Also create an array that holds the
correct answer to each question – A, B, or C. Display each question
and verify that the user enters only A, B, or C as the answer – if
not, keep prompting the user until valid response is entered. If the
user responds to a question correctly, display "Correct"; otherwise,
display "The correct answer is " and the letter of the correct answer.
After the user answers all the questions, display the number of
correct and incorrect answers. Save the file as
Surname1Surname2_Quiz.java. Please make your own questions and choices
and make sure that it will all be related to advance programming.

File: MagpantayDelaCruz_Quiz.java
package magpantaydelacruz_quiz;
import javax.swing.JOptionPane;

public class MagpantayDelaCruz_Quiz {

public static void main(String[] args) {


int score = 0 ;
String q1 = JOptionPane.showInputDialog("The statement which is
not the characteristic of COBOL is?\n" + " A. It is readable"
+ " \n B. It is very efficient in coding and execution \n
C. It is standardized language\n");
if ("b".equals(q1) || "B".equals(q1)){
JOptionPane.showMessageDialog(null,"Correct");
score++;
}else{
JOptionPane.showMessageDialog(null,"The Correct
Answer is b\nIt is very efficient in coding and execution", "Error",
JOptionPane.ERROR_MESSAGE);
}
String q2 = JOptionPane.showInputDialog("The high level language
program before ready to be executed must go through various process
except?\n"
+ " A. Linking \n B. Translation \n C. Loading\n");
if ("b".equals(q2)||"B".equals(q2)){
JOptionPane.showMessageDialog(null,"Correct");
score++;
}else{
JOptionPane.showMessageDialog(null,"The Correct
Answer is b\nTranslation", "Error", JOptionPane.ERROR_MESSAGE);
}
String q3 = JOptionPane.showInputDialog("Which one of the
following language reflects the way people think mathematically?\n"
+ " A. Functional \n B. Event driven programming
language\n C. Cross platform programming language\n");
if ("a".equals(q3)||"A".equals(q3)){
JOptionPane.showMessageDialog(null,"Correct");
score++;

DCIT 111 : ADVANCED PROGRAMMING Page 1


Jericho Jover V. Magpantay Jeane Kelmer O. DelaCruz

}else{
JOptionPane.showMessageDialog(null,"The Correct
Answer is a\nFunctional", "Error", JOptionPane.ERROR_MESSAGE);
}
String q4 = JOptionPane.showInputDialog("Which language can be
directly understood by the CPU?\n"
+ " A. Java \n B. C++\n C. Assembly language\n");
if ("c".equals(q4)||"C".equals(q4)){
JOptionPane.showMessageDialog(null,"Correct");
score++;
}else{
JOptionPane.showMessageDialog(null,"The Correct
Answer is c\nAssembly language", "Error", JOptionPane.ERROR_MESSAGE);
}
String q5 = JOptionPane.showInputDialog("Problem oriented
language is?\n"
+ " A. BASIC \n B. PL/1\n C. All of the above\n");
if ("c".equals(q5)||"C".equals(q5)){
JOptionPane.showMessageDialog(null,"Correct");
score++;
}else{
JOptionPane.showMessageDialog(null,"The Correct
Answer is c\nAll of the above", "Error", JOptionPane.ERROR_MESSAGE);
}
int total = 0;
int Stotal = total+score;
JOptionPane.showMessageDialog(null, "Total Score : " + Stotal
+ "/" + "5");

}
}

Machine Problem #2 Structure/concepts: Encapsulation; methods


Write an application named as Surname1Surname2_Scholarship.java
that will give the total payment fee of a student with corresponding
scholarship applied. Two methods will be called – setGrade() and
getScholarship() which is under CVSUScholarship.java. In the main
class, ask the user to input his/her GPA, amounts of tuition fee, SRF,
SFDF, and Miscellaneous. The method named setGrade() will process the
application and set new amount to be paid by the student while
getScholarship() will only return that amount after being called.

If GPA is from 1.00 to 1.45, a student will get a full


scholarship while those students with 1.46 to 1.75 will have a partial
scholarship. Students with grades from 1.76 to 5.00 will get no
scholarship and must have the full payment. Grades that are out of
range are invalid.

REGULAR (with no scholarship) = tuition + srf + sfdf +


miscellaneous

DCIT 111 : ADVANCED PROGRAMMING Page 2


Jericho Jover V. Magpantay Jeane Kelmer O. DelaCruz

PARTIAL = 50% free tuition + 50% free srf + 50% free sfdf +
miscellaneous
FULL = 100% free tuition + 100% free srf + 100% free sfdf +
miscellaneous

File: MagpantayDelaCruz_Scholarship.java

package magpantaydelacruz_scholarship;

import java.util.*;

public class MagpantayDelaCruz_Scholarship {

public static void main(String[] args) {


Scanner jhe = new Scanner(System.in);
try{
System.out.print("Please Enter your GPA : ");
float GPA = jhe.nextFloat();
if (GPA >= 1.00 && GPA <= 5.00){
System.out.print("Please Enter your Amount of tuition
fee : ");
float tuition = jhe.nextFloat();
System.out.print("Please Enter your Amount of SRF : ");
float SRF = jhe.nextFloat();
System.out.print("Please Enter your Amount of SFDF : ");
float SFDF = jhe.nextFloat();
System.out.print("Please Enter your Amount of Miscellanous :
");
float misc = jhe.nextFloat();
CVSUScholarship schor = new CVSUScholarship();
schor.setGrade(GPA,tuition,SRF,SFDF,misc);
System.out.println("Total Amount : ₱ "+
schor.getScholarship());

}else{
System.out.println("INVALID GRADE!");
}
}catch(Exception e){
System.out.println(e);
}

}
File : CVSUScholarship.java

package magpantaydelacruz_scholarship;
public class CVSUScholarship {
float GPA,tuition,SRF,SFDF,misc;

DCIT 111 : ADVANCED PROGRAMMING Page 3


Jericho Jover V. Magpantay Jeane Kelmer O. DelaCruz

public void setGrade(float GPA,float tuition,float SRF,float


SFDF,float misc){
this.GPA = GPA;
this.tuition = tuition;
this.SRF = SRF;
this.SFDF = SFDF;
this.misc = misc;
if(this.GPA >= 1.00 && this.GPA <= 1.45){
this.tuition = (float) ((tuition=0)+ (SRF=0)+(SFDF=0)+misc);
float total = this.tuition;
getScholarship();

}else if(this.GPA >= 1.46 && this.GPA <= 1.75){


this.tuition = (float) ((0.5*tuition)+
(0.5*SRF)+(SFDF*0.5)+misc);
getScholarship();
}
else if(this.GPA >= 1.76 && this.GPA <= 5.00){
this.tuition = tuition+SRF+SFDF+misc;
getScholarship();
}
else{
System.out.println("INVALID GPA");
}

}
public float getScholarship(){
return this.tuition ;

}
}

Machine Problem #3 : Structure/concepts: Abstraction; methods


Write an application named Surname1Surname2_UseChildren that
creates and displays at least two Child objects – one Male and one
Female. Child is an abstract class and Male and Female are subclasses.
The Child class contains fields that hold the name, gender, and age of
a child. The Child class constructor requires a name and gender. The
Child class also contains two abstract methods named setAge() and
display(). The Male and Female subclass constructors require only a
name; they pass the name and appropriate gender to the Child. The
subclass constructors also prompt the user for an age using the
setAge() method, and then display the Child’s data using the display()
method. Save the files as Child.java, Male.java, Female.java, and
Surname1Surname2_UseChildren.java

File : MagpantayDelaCruz_UseChildren.java
package magpantaydelacruz_usechildren;

import java.util.*;

DCIT 111 : ADVANCED PROGRAMMING Page 4


Jericho Jover V. Magpantay Jeane Kelmer O. DelaCruz

public class MagpantayDelaCruz_UseChildren {


public static void main(String[] args) {
Scanner jhe = new Scanner(System.in);
try{

System.out.print("Enter Name : ");


String name = jhe.nextLine();
System.out.print("Enter Gender : ");
char Gender = jhe.next().charAt(0);
if(Gender == 'm' || Gender == 'M' || Gender == 'f' || Gender
== 'F' ){
System.out.print("Enter Age : ");
int age = jhe.nextInt();
Child c = new Child() {};
c.setAge(name,Gender, age);
c.display();

}else{
System.out.println("INVALID GENDER");
}

}
catch(Exception e){
System.out.println(e);
}

File : Child.java

package magpantaydelacruz_usechildren;

abstract class Child {


private String name;
private char gender;
private int age;
public void setAge(String name,char gender,int age){
this.name = name;
this.gender = gender;
this.age = age;
if(gender == 'm' || gender == 'M'){
Male c = new Male();
}else if(gender == 'f' || gender == 'F'){
Female c = new Female();
}else{
System.out.println("INVALID");
}

DCIT 111 : ADVANCED PROGRAMMING Page 5


Jericho Jover V. Magpantay Jeane Kelmer O. DelaCruz

}
public void display(){
Male c = new Male();
c.Male(name);
Child f = new Child() {};
System.out.println("Age : "+age);

File : Male.java

package magpantaydelacruz_usechildren;
public class Male extends Female{
private String name;

public void Male(String name){


this.name = name;
System.out.println("Name : "+name+ "\nGender : Male");
}
}

File : Female.java

package magpantaydelacruz_usechildren;
public class Female extends Child {
private String name;
public void Male(String name){
this.name = name;
System.out.println("Name : "+name+ "\nGender : Female");

}
}

DCIT 111 : ADVANCED PROGRAMMING Page 6

You might also like