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?
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
Ok So I have the code I need! and it runs on online codechef IDE! The...
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 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 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...
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: 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 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 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...
JAVA HELP FOR COMP: Can someone please modify the code to create LowestGPA.java that prints out the name of the student with the lowestgpa. In the attached zip file, you will find two files HighestGPA.java and students.dat. Students.dat file contains names of students and their gpa. Check if the code runs correctly in BlueJ or any other IDE by running the code. Modify the data to include few more students and their gpa. import java.util.*; // for the Scanner class...
This is my code but my overtime calculation is wrong and I cant figure out how to round to two decimal places import java.util.Scanner; public class HourlyWage { public static void main(String[] args) { //Variables double totalWage; double totalOvertimePay; double totalPay; String name; double overtimeHours = 0.0; double hoursWorked = 0.0; double hourlyWage = 0.0; Scanner keyboard = new Scanner(System.in); System.out.println("Please enter your name "); name = keyboard.next(); System.out.println("Please enter your hourly wage "); hourlyWage = keyboard.nextDouble(); System.out.println("How many hours...
need help editing or rewriting java code, I have this program
running that creates random numbers and finds min, max, median ect.
from a group of numbers,array. I need to use a data class and a
constructor to run the code instead of how I have it written right
now. this is an example of what i'm being asked
for.
This is my code:
import java.util.Random;
import java.util.Scanner;
public class RandomArray {
// method to find the minimum number in...