Question

Write a program in Java that prompts a user for Name and id number. and then...

Write a program in Java that prompts a user for Name and id number. and then the program outputs students GPA

MAIN

import java.util.StringTokenizer;

import javax.swing.JOptionPane;

public class Main {

   public static void main(String[] args) {

              
       String thedata = JOptionPane.showInputDialog(null, "Please type in Student Name. ", "Student OOP Program", JOptionPane.INFORMATION_MESSAGE);
       String name = thedata;

       Student pupil = new Student(name);

          
       //add code here
      
      
      
      
      
       String outputmsg = "The Pupil: " + pupil.getName();
       outputmsg = outputmsg + "\nID: " + pupil.getIDnumber();
       outputmsg = outputmsg + "\ngrade point average is " + pupil.getGradePoint();
      
       JOptionPane.showMessageDialog(null, outputmsg);

   }

}

Student

public class Student {

   // the private data members
   private int idNumber;
   private int hours;
   private int points;
   private String name = "";

   // Constructor
   Student(String Name) {
       idNumber = 0;
       points = 60;
       hours = 15;
       name = Name;
   }
   // end of constructor added in part c

   // the public get and set methods

   public void setIDnumber(int number) {
       idNumber = number;
   }
   public String getName() {
       return name;
   }

   public int getIDnumber() {
       return idNumber;
   }

   //add here

   public double getGradePoint() {
       return (points * 1.0 / hours);
  
   }
}


0 0
Add a comment Improve this question Transcribed image text
Answer #1

/* Changed source code is */

import java.util.StringTokenizer;

import javax.swing.JOptionPane;

public class Main {

   public static void main(String[] args) {

              

       String thedata = JOptionPane.showInputDialog(null, "Please type in Student Name. ", "Student OOP Program", JOptionPane.INFORMATION_MESSAGE);

       String name = thedata;

       thedata = JOptionPane.showInputDialog(null, "Please type in Student ID. ", "Student OOP Program", JOptionPane.INFORMATION_MESSAGE);

       int idNumber = Integer.parseInt(thedata);

       thedata = JOptionPane.showInputDialog(null, "Please type hours ", "Student OOP Program", JOptionPane.INFORMATION_MESSAGE);

       int hours = Integer.parseInt(thedata);

       thedata = JOptionPane.showInputDialog(null, "Please type Points ", "Student OOP Program", JOptionPane.INFORMATION_MESSAGE);

       int points = Integer.parseInt(thedata);

       

       //Student pupil1 = new Student(name); //Call this for default

       Student pupil = new Student(name, idNumber, points, hours);

       pupil.setIDnumber(idNumber);  

       

       String outputmsg = "The Pupil: " + pupil.getName();

       outputmsg = outputmsg + "\nID: " + pupil.getIDnumber();

       outputmsg = outputmsg + "\ngrade point average is " + pupil.getGradePoint();

      

       JOptionPane.showMessageDialog(null, outputmsg);

   }

}

class Student {

   // the private data members

   private int idNumber;

   private int hours;

   private int points;

   private String name = "";

   // Constructor

   Student(String Name) {

       idNumber = 0;

       points = 60;

       hours = 15;

       name = Name;

   }

   Student(String Name,int idNumber,int points,int hours){

       this.idNumber = idNumber;

       this.points = points;

       this.hours = hours;

       this.name = Name;

   }

   // end of constructor added in part c

   // the public get and set methods

   public void setIDnumber(int number) {

       idNumber = number;

   }

   public String getName() {

       return name;

   }

   public int getIDnumber() {

       return idNumber;

   }

   //add here

   public double getGradePoint() {

       return (points * 1.0 / hours);

  

   }

}

/* Editor screen*/

/* Output Window*/

/* Final output screen*/

/* Thanks*/

Add a comment
Know the answer?
Add Answer to:
Write a program in Java that prompts a user for Name and id number. and then...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Add additional information to the student class below such as name, address, major, and contact information...

    Add additional information to the student class below such as name, address, major, and contact information along with all the getters and setters (methods) needed to access all data. Submit your code along with a sample run of your program. Comment all your code. Cite any sources of information you use. Write a note on the process of completing the assignment in a Microsoft Word document. // ShowStudent.java // client to test the Student class class ShowStudent { public static...

  • Add additional information to the student class below such as name, address, major, and contact information...

    Add additional information to the student class below such as name, address, major, and contact information along with all the getters and setters (methods) needed to access all data. Submit your code along with a sample run of your program. Comment all your code. Cite any sources of information you use. Write a note on the process of completing the assignment in a Microsoft Word document. // ShowStudent.java // client to test the Student class class ShowStudent { public static...

  • write comments // on this program please //Inside package bloodDonation //BloodDonor.java class package bloodDonation; import java.text.ParseException;...

    write comments // on this program please //Inside package bloodDonation //BloodDonor.java class package bloodDonation; import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.Calendar; import java.util.Date; import java.util.Scanner; public class BloodDonor {     long idNumber, cardNumber;     String name, bloodGroup, homePhone, mobilePhone, address, lastDateOfDonation;     SimpleDateFormat myFormat = new SimpleDateFormat("dd MM yyyy");     public BloodDonor(){         this.idNumber = 0;         this.cardNumber = 0;         this.name = "";         this.bloodGroup = "";         this.homePhone = "";         this.mobilePhone = "";         this.address = "";        ...

  • Java Programming --- complete the given classes DeLand Space Car Dealer needs a new program for...

    Java Programming --- complete the given classes DeLand Space Car Dealer needs a new program for their inventory management system. The program needs the following classes: A main class (SpaceCarDealer.java) that includes the main method and GUI. Two instantiable classes: CarDealer.java o Variables to store the dealer name, and the carsOnLot array in Car type. o A constructor to initialize the name variable with the given dealer name. o An accessor method to return the name of the dealer. o...

  • Given attached you will find a file from Programming Challenge 5 of chapter 6 with required...

    Given attached you will find a file from Programming Challenge 5 of chapter 6 with required you to write a Payroll class that calculates an employee’s payroll. Write exception classes for the following error conditions: An empty string is given for the employee’s name. An invalid value is given to the employee’s ID number. If you implemented this field as a string, then an empty string could be invalid. If you implemented this field as a numeric variable, then a...

  • I need code in java The Student class: CODE IN JAVA: Student.java file: public class Student...

    I need code in java The Student class: CODE IN JAVA: Student.java file: public class Student {    private String name;    private double gpa;    private int idNumber;    public Student() {        this.name = "";        this.gpa = 0;        this.idNumber = 0;    }    public Student(String name, double gpa, int idNumber) {        this.name = name;        this.gpa = gpa;        this.idNumber = idNumber;    }    public Student(Student s)...

  • Need help with the program DemoSugarSmash.java import java.util.*; public class DemoSugarSmash { public static void main(String[]...

    Need help with the program DemoSugarSmash.java import java.util.*; public class DemoSugarSmash { public static void main(String[] args) { // Complete the demo program here } } PremiumSugarSmashPlayer.java public class PremiumSugarSmashPlayer { // Define the PremiumSugarSmashPlayer class here } PremiumSugarSmashPlayer.java public class SugarSmashPlayer { private int playerID; private String screenName; private int[] scoresArray ; public SugarSmashPlayer() { this.scoresArray = new int[10]; } public SugarSmashPlayer(int levels) { this.scoresArray = new int[levels]; } public int getIdNumber() { return playerID; } public void setIdNumber(int...

  • Modify the objectstudent JAVA program to add a private variable zipcode, you must also add setters...

    Modify the objectstudent JAVA program to add a private variable zipcode, you must also add setters and getter methods for the new variable and modify the toString method. The objectstudent program is in this weeks module, you can give it a default value of 19090. class Student { private int id; private String name; public Student() { id = 8; name = "John"; } public int getid() { return id; } public String getname() { return name; } public void...

  • How to solve and code the following requirements (below) using the JAVA program? 1. Modify the...

    How to solve and code the following requirements (below) using the JAVA program? 1. Modify the FoodProduct Class to implement Edible, add the @Overrride before any methods that were there (get/set methods) that are also in the Edible interface. 2. Modify the CleaningProduct Class to implement Chemical, add the @Overrride before any methods that were there (get/set methods) that are also in the Chemical interface. 3. Create main class to read products from a file, instantiate them, load them into...

  • In this practice program you are going to practice creating graphical user interface controls and placing...

    In this practice program you are going to practice creating graphical user interface controls and placing them on a form. You are given a working NetBeans project shell to start that works with a given Invoice object that keeps track of a product name, quantity of the product to be ordered and the cost of each item. You will then create the necessary controls to extract the user input and display the results of the invoice. If you have any...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT