Question

Ok So I have the code I need! and it runs on online codechef IDE! The...

Ok So I have the code I need! and it runs on online codechef IDE! The code is below:

import java.util.Scanner;
import java.io.FileWriter;

public class Main
{
public static void main(String[] args) {
  
Scanner sc = new Scanner(System.in);
  
double sales;
System.out.print("Enter annual sales: ");
sales = sc.nextDouble();
  
double fixed = 30000;
  
double commission = (7.0*sales)/100.0;
  
double total = fixed + commission;
  
System.out.println("Fixed Salary: "+fixed);
System.out.println("Annual Sales: "+sales);
System.out.println("Commission: "+commission);
System.out.println("Total Salary: "+total);
  
  
try
{
FileWriter f = new FileWriter("output.txt");
  
f.write("Fixed Salary: "+fixed+"\n");
f.write("Annual Sales: "+sales+"\n");
f.write("Commission: "+commission+"\n");
f.write("Total Salary: "+total+"\n");
  
f.close();
}
catch(Exception e)
{
System.out.println(e);
}
}
}

The problem I am no having is I need to run this on Apache Netbeans and should have one class in addition to the applications controlling class. A file needs to be created to obtain the output. and I have to create a zip file to turn it in. Can you help me with steps in achieving this?

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

Please find the answer below.
Please do comments in case of any issue. Also, don't forget to rate the question. Thank You.

Providing you two class. One to store Salary information and one driver class.

Main.java

package c6;

import java.util.Scanner;
import java.io.FileWriter;


class SalaryCalculator{
   private double sales;
   private double commission;
   private double fixed;
   private double total;

   public SalaryCalculator(double sales) {
       super();
       this.sales = sales;
       this.commission = (7.0*sales)/100.0;
       this.fixed = 30000;
       this.total = fixed + commission;
   }
   public double getSales() {
       return sales;
   }
   public double getcommission() {
       return commission;
   }
   public double getFixed() {
       return fixed;
   }
   public double getTotal() {
       return total;
   }
   public void writeDataToFile(String string) {
       try
       {
           FileWriter f = new FileWriter(string);

           f.write("Fixed Salary: "+fixed+"\n");
           f.write("Annual Sales: "+sales+"\n");
           f.write("Commission: "+commission+"\n");
           f.write("Total Salary: "+total+"\n");

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

   }
   public void printDetails() {
       System.out.println("Fixed Salary: "+fixed);
       System.out.println("Annual Sales: "+sales);
       System.out.println("Commission: "+commission);
       System.out.println("Total Salary: "+total);
   }

}

public class Main
{
   public static void main(String[] args) {
       Scanner sc = new Scanner(System.in);
       double sales;
       System.out.print("Enter annual sales: ");
       sales = sc.nextDouble();
       SalaryCalculator salary = new SalaryCalculator(sales);
       salary.printDetails();
       salary.writeDataToFile("output.txt");
   }
}

output

ARYA output.txt X 1 Fixed Salary: 30000.0 2 Annual Sales: 1900.0 3 Commission: 133.0 4 Total Salary: 30133.0 5 & Console X <t

Add a comment
Know the answer?
Add Answer to:
Ok So I have the code I need! and it runs on online codechef IDE! The...
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
  • In the code shown above are two parts of two different exercises. HOW WE CAN HAVE...

    In the code shown above are two parts of two different exercises. HOW WE CAN HAVE BOTH OF THEM ON THE SAME CLASS BUT SO WE CAN RECALL them threw different methods. Thank you. 1-First exercise import java.util.Scanner; public class first { public static int average(int[] array){    int total = 0;    for(int x: array)        total += x;    return total / array.length;    } public static double average(double[] array){    double total = 0;    for(double x: array)        total += x;    return total /...

  • I have this program that works but not for the correct input file. I need the...

    I have this program that works but not for the correct input file. I need the program to detect the commas Input looks like: first_name,last_name,grade1,grade2,grade3,grade4,grade5 Dylan,Kelly,97,99,95,88,94 Tom,Brady,100,90,54,91,77 Adam,Sandler,90,87,78,66,55 Michael,Jordan,80,95,100,89,79 Elon,Musk,80,58,76,100,95 output needs to look like: Tom Brady -------------------------- Assignment 1: A Assignment 2: A Assignment 3: E Assignment 4: A Assignment 5: C Final Grade: 82.4 = B The current program: import java.io.File; import java.io.FileNotFoundException; import java.io.FileWriter; import java.io.IOException; import java.util.Scanner; public class main {    public static void main(String[]...

  • I have a program that reads a file and then creates objects from the contents of...

    I have a program that reads a file and then creates objects from the contents of the file. How can I create a linked list of objects and use it with the package class instead of creating and using an array of objects? I am not allowed to use any arrays of objects or any java.util. lists in this program. Runner class: import java.util.Scanner; import java.io.*; class Runner { public static Package[] readFile() { try { File f = new...

  • Write a Java® application, using NetBeans IDE, that calculates the total annual compensation of a salesperson....

    Write a Java® application, using NetBeans IDE, that calculates the total annual compensation of a salesperson. Consider the following: A salesperson will earn a fixed salary of $30,000. A salesperson will also receive a commission as a sales incentive. Commission is a percentage of the salesperson's annual sales. The current commission is 7% of total sales. The total annual compensation is the fixed salary plus the commission earned. he Java® application should meet the following technical requirements: The application should...

  • Having trouble with my code, it keeps giving me an error every time I run it....

    Having trouble with my code, it keeps giving me an error every time I run it. Can someone please help me understand what I'm doing wrong? *********CODE*************** // Java program to read the file contents, sort it and output the sorted content to another file import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.File; import java.io.FileInputStream; import java.io.FileWriter; import java.io.IOException; import java.io.InputStreamReader; import java.util.ArrayList; import java.util.Collections; public class Datasort { public static void main(String[] args) throws IOException { File fin = new File("input.txt");...

  • I need to change the following code so that it results in the sample output below...

    I need to change the following code so that it results in the sample output below but also imports and utilizes the code from the GradeCalculator, MaxMin, and Student classes in the com.csc123 package. If you need to change anything in the any of the classes that's fine but there needs to be all 4 classes. I've included the sample input and what I've done so far: package lab03; import java.util.ArrayList; import java.util.Scanner; import com.csc241.*; public class Lab03 { public...

  • JAVA: Rewrite the following code to where the inputs are from a file. The file name...

    JAVA: Rewrite the following code to where the inputs are from a file. The file name will be from the input from the user scanner. CODE: import java.util.*; public class Q1 { public static int sumOD (int k) { int sumOD = 0; int in = k; while (in != 0) { int digitON = in % 10; sumOD += digitON; in /= 10; } return sumOD; }    public static void main(String[] args) { int n, i, k; System.out.println("Enter...

  • JAVA: amortization table: Hi, I have built this code and in one of my methods: printDetailsToConsole...

    JAVA: amortization table: Hi, I have built this code and in one of my methods: printDetailsToConsole I would like it to print the first 3 payments and the last 3 payments if n is larger than 6 payments. Please help! Thank you!! //start of program import java.util.Scanner; import java.io.FileOutputStream; import java.io.FileNotFoundException; import java.io.PrintWriter; import java.lang.Math; //345678901234567890123456789012345678901234567890123456789012345678901234567890 /** * Write a description of class MortgageCalculator here. * * @author () * @version () */ public class LoanAmortization {    /* *...

  • Please edit my following JAVA code so that there is no main function. I would like...

    Please edit my following JAVA code so that there is no main function. I would like one function in this class that completes what the current program is trying to do so that I can call this class in my main class which will be separate. import java.math.RoundingMode; import java.text.DecimalFormat; import java.util.Scanner; public class enterwklyincme { private static DecimalFormat df = new DecimalFormat("0.00"); public static float readFloat(Scanner reader) { float num; while (true) { try { num = Float.parseFloat(reader.nextLine()); return...

  • Please help me fix my errors. I would like to read and write the text file...

    Please help me fix my errors. I would like to read and write the text file in java. my function part do not have errors. below is my code import java.io.FileInputStream; import java.io.InputStreamReader; import java.io.FileWriter; import java.io.IOException; public class LinkedList {    Node head;    class Node    {        int data;        Node next;       Node(int d)        {            data = d;            next = null;        }    }    void printMiddle()    {        Node slow_ptr...

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