Preview

Java Program Structure Problems

Good Essays
Open Document
Open Document
1642 Words
Grammar
Grammar
Plagiarism
Plagiarism
Writing
Writing
Score
Score
Java Program Structure Problems
PROGRAM STRUCTURE-SEQUENCE PROBLEMS

1. Write a Java class that prompts a student for the number of credit hours in which the student is enrolled, and the amount of money spent of books. Display, with full explanation, the student’s total fees. The total is Php 300 per credit hour, plus the amount for books, plus a Php 500 athletic fee.

SOURCE CODE: import javax.swing.JOptionPane; public class JStrucSeqProb1
{
public static void main(String[]args) { String numCreditHours, BookAmt; double credithours , credithoursamt, bookamt, atlfee, total;

numCreditHours = JOptionPane.showInputDialog(null, "Enter the number of your Credit Hours\n(Php300/Credit Hours): ", "Credit Hours", JOptionPane.PLAIN_MESSAGE); BookAmt = JOptionPane.showInputDialog(null, "Enter the amount of Book Spent: ", "Book Amount", JOptionPane.PLAIN_MESSAGE);

//converting String to Integer credithours = Double.parseDouble(numCreditHours); bookamt = Double.parseDouble(BookAmt); atlfee = 500; //computation credithoursamt = credithours * 300; total = credithoursamt + bookamt + atlfee;

JOptionPane.showMessageDialog(null, "Php300/Credit Hours Amount: Php" + credithoursamt + "\nBook Amount: Php" + bookamt + "\nAthletic Fee: Php" + atlfee + "\n\nTotal Amount: Php" + total, "Results", JOptionPane.INFORMATION_MESSAGE); }
}

OUTPUT LAYOUT: Fig.1 Fig.2 Fig.3

2. Write a class that accepts a user’s hourly rate of pay and the number of hours worked. Display the user’s gross pay, the withholding tax (15% of gross pay), and the net pay (gross pay-withholding).

SOURCE CODE: import javax.swing.JOptionPane; public class JStrucSeqProb2
{
public static void main(String[]args) { String numHours; double hours, hrsamt, gross, taxpercent, taxamt, net;

numHours = JOptionPane.showInputDialog(null, "Enter the number of hours worked: ", "Hours Worked", JOptionPane.PLAIN_MESSAGE);

hours = Double.parseDouble(numHours);

You May Also Find These Documents Helpful

  • Satisfactory Essays

    7. The program will calculate and display a final total for the items that are purchased.…

    • 498 Words
    • 2 Pages
    Satisfactory Essays
  • Powerful Essays

    Student will learn how to write Java programs to perform simple calculations, they will use Scanner class to obtain input from the console, they will know how to use identifiers to name variables, constants, methods, and classes. The use of constants , Java primitive…

    • 2338 Words
    • 10 Pages
    Powerful Essays
  • Good Essays

    Kudler Fine Food Week 4

    • 284 Words
    • 2 Pages

    · Calculate the minimum salary for exempt employees and the maximum salary for non-exempt employees.…

    • 284 Words
    • 2 Pages
    Good Essays
  • Satisfactory Essays

    PT1420 Unit 3 Labs

    • 270 Words
    • 2 Pages

    The Network Systems Administration degree is awarded after 90 credits and Nolan Owen has 70 left to take before graduation.…

    • 270 Words
    • 2 Pages
    Satisfactory Essays
  • Better Essays

    Program Lovecs.Java

    • 422 Words
    • 2 Pages

    import java.util. Scanner; public class LoveCS { public static void main(String[] args) { Scanner scan=new Scanner(System.in); System.out.println("Enter how many times you wish the message to be printed."); int limit = 0; limit= scan.nextInt(); int sum=0; int count=1; while (count <=limit) { System.out.println(count+" I love Computer Science!!"); sum+=count; count++; } System.out.println("Printed this message " + limit + " times."); System.out.println("The sum of the numbers from 1 to "+limit+" is "+sum); } } import java.util. Scanner; public class PowersOf2 { public static void main(String[]args) { int valuePowersOf2; int nextPowersOf2 =1; int exponent= 0; int count=0; Scanner scan = new Scanner(System.in); System.out.println("Enter A Number.");…

    • 422 Words
    • 2 Pages
    Better Essays
  • Satisfactory Essays

    CTS 2437 Final Exam

    • 630 Words
    • 4 Pages

    You should provide (1) a screen shot of your solution and (2) code for your solution, copied/pasted into this document. Each problem is worth 20 points.…

    • 630 Words
    • 4 Pages
    Satisfactory Essays
  • Good Essays

    Programing Problems

    • 721 Words
    • 3 Pages

    Display “Please enter regular hours worked” Input RegHours Display “Please enter overtime hours worked” Input OvertimeHours End User Input Module Gross Pay Module GrossPay =…

    • 721 Words
    • 3 Pages
    Good Essays
  • Satisfactory Essays

    unit 3

    • 313 Words
    • 2 Pages

    Design a program that calculates the total amount of meal purchased at a restaurant. The program should ask the user to enter the charge for the food, and then calculate the amount of a 15% tip and 7% sales tax. Display each of these amounts and the total.…

    • 313 Words
    • 2 Pages
    Satisfactory Essays
  • Satisfactory Essays

    Mis 302 Flowchart

    • 262 Words
    • 2 Pages

    Complete Java Program to accept the required input and accordingly produce the output as expected.…

    • 262 Words
    • 2 Pages
    Satisfactory Essays
  • Satisfactory Essays

    13. This attribute configures how content is situated to the left, right, or center of a Web page: align…

    • 335 Words
    • 1 Page
    Satisfactory Essays
  • Satisfactory Essays

    CMIS 102 Homework 3

    • 342 Words
    • 3 Pages

    //Purpose: This program will allow students to input their name and grades to determine a GPA value…

    • 342 Words
    • 3 Pages
    Satisfactory Essays
  • Satisfactory Essays

    The objective of this project is to enable student to record transactions into the accounting cycle.…

    • 685 Words
    • 3 Pages
    Satisfactory Essays
  • Satisfactory Essays

    * This program allows a user to calculate a mortgage payment based on their input.…

    • 469 Words
    • 2 Pages
    Satisfactory Essays
  • Good Essays

    import java.util. *; class LRU { static int nof,nop,i,index,m,frames[]=new int[100],fs[]=new int [100],n,miss=0,hit=0,l=0,flag1,flag2; public static void main(String args[]) { Scanner s=new Scanner(System.in); System.out.println("Enter the number of frames : "); nof=s.nextInt(); for(i=0;i<nof;i++) { frames[i]=-1; fs[i]=0; } System.out.println("Enter the number of pages : "); nop=s.nextInt();; int pages[]=new int[10]; System.out.println("Enter the pages : "); for(i=0;i<nop;i++) { pages[i]=s.nextInt();; } while(l<nop) { flag1=0;flag2=0; for(int k=0;k<nof;k++) { if(pages[l]==frames[k]) { hit++; flag1=1; flag2=1; break; } } if(flag1==0) { for(i=0;i<nof;i++) { if(frames[i]==-1) { frames[i]=pages[l]; miss++; flag2=1; break; } } } if(flag2==0) { for(i=0;i<nof;i++) fs[i]=0; for(m=l-1,n=1;n<nof;n++,m--) { for(i=0;i<nof;i++) { if(frames[i]==pages[m]) fs[i]=1; } } for(i=0;i<nof;i++) { if(fs[i]==0) index= i; } frames[index]=pages[l]; miss++; } l=l+1; display(); } } static void display() { for(i=0;i<nof;i++) { System.out.println("\n"+frames[i]); } System.out.println("\nMiss : "+miss+"\n\n\n"); } } /* OUTPUT D:\SECMPN 60>javac LRU.java D:\SECMPN 60>java LRU Enter the number of frames : 3 Enter the number of pages : 7 Enter the pages : 1 2 4 1 3 5 6 1 -1 -1 Miss : 1 1 2 -1 Miss : 2 1 2 4 Miss : 3 1 2 4 Miss : 3 1 3 4 Miss : 4 1 3 5 Miss : 5 6 3 5 Miss :…

    • 303 Words
    • 2 Pages
    Good Essays
  • Powerful Essays

    import java.io. *; import java.awt. *; import java.awt.event. *; import javax.swing. *; import java.sql.…

    • 3009 Words
    • 13 Pages
    Powerful Essays

Related Topics